View Javadoc
1   /**
2    * This file Copyright (c) 2003-2018 Magnolia International
3    * Ltd.  (http://www.magnolia-cms.com). All rights reserved.
4    *
5    *
6    * This file is dual-licensed under both the Magnolia
7    * Network Agreement and the GNU General Public License.
8    * You may elect to use one or the other of these licenses.
9    *
10   * This file is distributed in the hope that it will be
11   * useful, but AS-IS and WITHOUT ANY WARRANTY; without even the
12   * implied warranty of MERCHANTABILITY or FITNESS FOR A
13   * PARTICULAR PURPOSE, TITLE, or NONINFRINGEMENT.
14   * Redistribution, except as permitted by whichever of the GPL
15   * or MNA you select, is prohibited.
16   *
17   * 1. For the GPL license (GPL), you can redistribute and/or
18   * modify this file under the terms of the GNU General
19   * Public License, Version 3, as published by the Free Software
20   * Foundation.  You should have received a copy of the GNU
21   * General Public License, Version 3 along with this program;
22   * if not, write to the Free Software Foundation, Inc., 51
23   * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24   *
25   * 2. For the Magnolia Network Agreement (MNA), this file
26   * and the accompanying materials are made available under the
27   * terms of the MNA which accompanies this distribution, and
28   * is available at http://www.magnolia-cms.com/mna.html
29   *
30   * Any modifications to this file must keep this entire header
31   * intact.
32   *
33   */
34  package info.magnolia.context;
35  
36  import info.magnolia.cms.core.HierarchyManager;
37  import info.magnolia.cms.core.search.QueryManager;
38  import info.magnolia.cms.i18n.Messages;
39  import info.magnolia.cms.security.AccessManager;
40  import info.magnolia.cms.security.User;
41  
42  import java.util.Locale;
43  import java.util.Map;
44  
45  import javax.jcr.LoginException;
46  import javax.jcr.RepositoryException;
47  import javax.jcr.Session;
48  import javax.security.auth.Subject;
49  
50  
51  /**
52   * This interface defines all the methods which should be implemented by any configured magnolia context. Implementing
53   * class should never be accessible directly but only via MgnlContext static methods which work on a local (Thread) copy
54   * of the implementation.
55   */
56  public interface Context extends info.magnolia.commands.chain.Context {
57  
58      /**
59       * Attribute visibility scope.
60       */
61      public static final int LOCAL_SCOPE = 1;
62  
63      /**
64       * Attribute visibility scope Shared by all requests from this session.
65       */
66      public static final int SESSION_SCOPE = 2;
67  
68      /**
69       * Attribute visibility scope, its visible to all sessions of this application.
70       */
71      public static final int APPLICATION_SCOPE = 3;
72  
73      final static public String ATTRIBUTE_REPOSITORY = "repository";
74  
75      final static public String ATTRIBUTE_PATH = "path";
76  
77      final static public String ATTRIBUTE_VERSION = "version";
78  
79      final static public String ATTRIBUTE_VERSION_MAP = "versionMap";
80  
81      final static public String ATTRIBUTE_UUID = "uuid";
82  
83      final static public String ATTRIBUTE_RECURSIVE = "recursive";
84  
85      public static final String ATTRIBUTE_COMMENT = "comment";
86  
87      public static final String ATTRIBUTE_MESSAGE = "msg";
88  
89      public static final String ATTRIBUTE_EXCEPTION = "exception";
90  
91      /**
92       * Name of the attribute keeping the user that has launched the command.
93       * @deprecated since 5.4.4, use {@link #ATTRIBUTE_USERNAME}.
94       */
95      @Deprecated
96      public static final String ATTRIBUTE_REQUESTOR = "requestor";
97  
98      /**
99       * User name attribute. Refers to the user which has launched a {@link info.magnolia.commands.chain.Command}.
100      */
101     public static final String ATTRIBUTE_USERNAME = "userName";
102 
103     /**
104      * If this is not a UserContext this method will very likely return the system user.
105      */
106     public User getUser();
107 
108     public Subject getSubject();
109 
110     public void setLocale(Locale locale);
111 
112     /**
113      * Get the current locale.
114      */
115     public Locale getLocale();
116 
117     public Session getJCRSession(String workspaceName) throws LoginException, RepositoryException;
118 
119     /**
120      * Get hierarchy manager initialized for this user.
121      *
122      * @return hierarchy manager
123      * @deprecated since 4.5 - use {@link #getJCRSession(String)}
124      */
125     @Deprecated
126     public HierarchyManager getHierarchyManager(String workspaceName);
127 
128     /**
129      * Get a an {@link info.magnolia.cms.security.AccessManager} for logical entities. The accesses to the repository are handled by the repository itself.
130      */
131     public AccessManager getAccessManager(String name);
132 
133     /**
134      * Get QueryManager created for this user on the specified repository.
135      *
136      * @deprecated since 4.5 - use {@link #getJCRSession(String)} and acquire the JCR query manager directly from the session.
137      */
138     @Deprecated
139     public QueryManager getQueryManager(String workspaceName);
140 
141     /**
142      * Set attribute value, scope of the attribute is defined.
143      *
144      * @param name is used as a key
145      * @param scope , highest level of scope from which this attribute is visible
146      */
147     public void setAttribute(String name, Object value, int scope);
148 
149     /**
150      * Get attribute value.
151      *
152      * @param name to which value is associated to
153      * @param scope the scope (request, session, application)
154      * @return attribute value
155      */
156     public <T> T getAttribute(String name, int scope);
157 
158     /**
159      * Get attribute value without passing a scope. the scopes are searched from bottom up (request, session,
160      * application)
161      *
162      * @param name to which value is associated to
163      * @return attribute value
164      */
165     public <T> T getAttribute(String name);
166 
167     /**
168      * Get a map of a attributes set in the scope.
169      *
170      * @return the map
171      */
172     public Map<String, Object> getAttributes(int scope);
173 
174     /**
175      * Remove an attribute.
176      */
177     public void removeAttribute(String name, int scope);
178 
179     /**
180      * Get an over all map.
181      *
182      * @return the map
183      */
184     public Map<String, Object> getAttributes();
185 
186     /**
187      * Get the default messages. It uses the locale set on this context
188      * TODO: This duplicates methods from MessagesManager : remove either
189      */
190     public Messages getMessages();
191 
192     /**
193      * Get the messages of the named bundle. It uses the locale set on this context
194      *
195      * @param basename name of the bundle
196      * TODO: This duplicates methods from MessagesManager : remove either
197      */
198     public Messages getMessages(String basename);
199 
200     /**
201      * Release any resource used by this Context (e.g. jcr sessions).
202      */
203     public void release();
204 
205 }