1 /*
2 * Copyright (C) 2003-2012 eXo Platform SAS.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Affero General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Affero General Public License for more details.
13 *
14 * You should have received a copy of the GNU Affero General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17 package org.exoplatform.services.context;
18
19 import java.util.HashMap;
20
21
22 /**
23 * This class acts as a context stores some auxiliary attributes of a document.
24 * It's useful with document listeners which are able to make decision based on these attributes, for example: skipping raising social activity,...
25 *
26 * Created by The eXo Platform SAS
27 * Author : Lai Trung Hieu
28 * hieult@exoplatform.com
29 * Apr 23, 2012
30 */
31 public class DocumentContext {
32
33 /**
34 * The attribute name is used to indicate is it need to skip raising social activity
35 */
36 public static final String IS_SKIP_RAISE_ACT = "isSkipRaiseActivity";
37
38 /**
39 * ThreadLocal keeper for DocumentContext.
40 */
41 private static ThreadLocal<DocumentContext> current = new ThreadLocal<DocumentContext>();
42
43 /**
44 * Additions attributes of DocumentContext.
45 */
46 private HashMap<String, Object> attributes = new HashMap<String, Object>();
47
48 /**
49 * @return current DocumentContext or null if it was not preset
50 */
51 public static DocumentContext getCurrent() {
52 if (current.get() == null) {
53 setCurrent(new DocumentContext());
54 }
55 return current.get();
56 }
57
58 /**
59 * Preset current DocumentContext.
60 * @param state DocumentContext
61 */
62 public static void setCurrent(DocumentContext state) {
63 current.set(state);
64 }
65
66 /**
67 * @return the attributes
68 */
69 public HashMap<String, Object> getAttributes() {
70 return attributes;
71 }
72
73 /**
74 * @param attributes the attributes to set
75 */
76 public void setAttributes(HashMap<String, Object> attributes) {
77 this.attributes = attributes;
78 }
79 }