KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > info > magnolia > context > SystemContextImpl


1 /**
2  *
3  * Magnolia and its source-code is licensed under the LGPL.
4  * You may copy, adapt, and redistribute this file for commercial or non-commercial use.
5  * When copying, adapting, or redistributing this document in keeping with the guidelines above,
6  * you are required to provide proper attribution to obinary.
7  * If you reproduce or distribute the document without making any substantive modifications to its content,
8  * please use the following attribution line:
9  *
10  * Copyright 1993-2005 obinary Ltd. (http://www.obinary.com) All rights reserved.
11  *
12  */

13 package info.magnolia.context;
14
15 import info.magnolia.cms.beans.config.ContentRepository;
16 import info.magnolia.cms.core.HierarchyManager;
17 import info.magnolia.cms.core.search.QueryManager;
18 import info.magnolia.cms.security.AccessManager;
19 import info.magnolia.cms.security.Security;
20 import info.magnolia.cms.security.User;
21
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
24
25
26 /**
27  * This is the system context using the not secured HierarchyManagers. The context uses only one scope.
28  * @author Philipp Bracher
29  * @version $Revision: 6341 $ ($Author: philipp $)
30  */

31 public class SystemContextImpl extends AbstractMapBasedContext implements SystemContext {
32
33     /**
34      * Logger
35      */

36     private static Logger log = LoggerFactory.getLogger(SystemContextImpl.class);
37
38     /**
39      * Stable serialVersionUID.
40      */

41     private static final long serialVersionUID = 222L;
42
43     /**
44      * DON'T CREATE AN OBJECT. The SystemContext is set by magnolia system itself. Init the scopes
45      */

46     public SystemContextImpl() {
47     }
48
49     public HierarchyManager getHierarchyManager(String JavaDoc repositoryId, String JavaDoc workspaceId) {
50         return ContentRepository.getHierarchyManager(repositoryId, workspaceId);
51     }
52
53     public AccessManager getAccessManager(String JavaDoc repositoryId, String JavaDoc workspaceId) {
54         return ContentRepository.getAccessManager();
55     }
56
57     public QueryManager getQueryManager(String JavaDoc repositoryId, String JavaDoc workspaceId) {
58         return this.getHierarchyManager(repositoryId, workspaceId).getQueryManager();
59     }
60
61     public void setAttribute(String JavaDoc name, Object JavaDoc value, int scope) {
62         if (scope == Context.LOCAL_SCOPE || scope == Context.SESSION_SCOPE) {
63             log
64                 .warn(
65                     "you should not set an attribute in the system context in request or session scope. You are setting {}={}",
66                     name,
67                     value);
68         }
69         super.setAttribute(name, value, scope);
70     }
71
72     public void removeAttribute(String JavaDoc name, Object JavaDoc value, int scope) {
73         if (scope == Context.LOCAL_SCOPE || scope == Context.SESSION_SCOPE) {
74             log
75                 .warn(
76                     "you should not manipulate an attribute in the system context in request or session scope. You are setting {}={}",
77                     name,
78                     value);
79         }
80         super.removeAttribute(name, scope);
81     }
82
83     /**
84      * Get System user
85      * @return User
86      * @see info.magnolia.cms.security.User
87      */

88     public User getUser() {
89         if (this.user == null) {
90             log.debug("JAAS Subject is null, returning Anonymous user");
91             this.user = Security.getUserManager().getSystemUser();
92         }
93         return this.user;
94     }
95 }
96
Popular Tags