1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package info.magnolia.context;
35
36 import java.util.Locale;
37
38 import org.slf4j.Logger;
39 import org.slf4j.LoggerFactory;
40
41 import info.magnolia.cms.i18n.MessagesManager;
42
43
44
45
46
47
48
49 public abstract class AbstractSystemContext extends AbstractContext implements SystemContext {
50
51 private static final Logger log = LoggerFactory.getLogger(AbstractSystemContext.class);
52
53
54
55
56 private static final long serialVersionUID = 222L;
57
58 protected static ThreadLocal<JCRSessionStrategy> repositoryStrategyThreadLocal = new ThreadLocal<JCRSessionStrategy>();
59
60
61
62
63 public AbstractSystemContext() {
64 setAttributeStrategy(new MapAttributeStrategy());
65 }
66
67 @Override
68 public void setAttribute(String name, Object value, int scope) {
69 if (scope == Context.LOCAL_SCOPE || scope == Context.SESSION_SCOPE) {
70 log.warn("you should not set an attribute in the system context in request or session scope. You are setting {}={}", name, value);
71 }
72 super.setAttribute(name, value, scope);
73 }
74
75 public void removeAttribute(String name, Object value, int scope) {
76 if (scope == Context.LOCAL_SCOPE || scope == Context.SESSION_SCOPE) {
77 log.warn("you should not manipulate an attribute in the system context in request or session scope. You are setting {}={}", name, value);
78 }
79 super.removeAttribute(name, scope);
80 }
81
82
83
84
85
86 @Deprecated
87 @Override
88 public void setLocale(Locale locale) {
89 throw new UnsupportedOperationException("setLocale() should not be called on SystemContext - system default locale is handled by MessagesManager");
90 }
91
92
93 @Override
94 public Locale getLocale() {
95 return MessagesManager.getInstance().getDefaultLocale();
96 }
97 }