View Javadoc

1   /**
2    * This file Copyright (c) 2003-2011 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.cms.taglibs;
35  
36  import info.magnolia.cms.beans.runtime.MultipartForm;
37  import info.magnolia.cms.core.Content;
38  import info.magnolia.cms.filters.InterceptFilter;
39  import info.magnolia.cms.util.SelectorUtil;
40  import info.magnolia.context.MgnlContext;
41  import org.apache.commons.lang.StringUtils;
42  
43  
44  /**
45   * A utility class.
46   * @author Sameer Charles
47   * @version 1.1
48  
49   * @deprecated since 4.0 - should not be used. AggregationState should be usable as a replacement in most cases.
50   */
51  public class Resource {
52  
53      /**
54       * @deprecated since 4.0 - use {@link InterceptFilter#MGNL_PREVIEW_ATTRIBUTE} or rather, use the methods on AggregationState.
55       */
56      public static final String MGNL_PREVIEW_ATTRIBUTE = InterceptFilter.MGNL_PREVIEW_ATTRIBUTE;
57  
58      private static final String GLOBAL_CONTENT_NODE = "contentObjGlobal"; //$NON-NLS-1$
59  
60      private static final String LOCAL_CONTENT_NODE = "contentObj"; //$NON-NLS-1$
61  
62      private static final String LOCAL_CONTENT_NODE_COLLECTION_NAME = "localContentNodeCollectionName"; //$NON-NLS-1$
63  
64      /**
65       * Utility class, don't instantiate.
66       */
67      protected Resource() {
68          // unused
69      }
70  
71      /**
72       * <p>
73       * get Content object as requested from the URI.
74       * </p>
75       * @return currently active page, as requested from the URI
76       *
77       * @deprecated use AggregationState
78       */
79      public static Content getActivePage() {
80          return MgnlContext.getAggregationState().getMainContent();
81      }
82  
83      /**
84       * <p>
85       * get Content object as requested from the URI.
86       * </p>
87       * @return currently active page, as requested from the URI
88       */
89      public static Content getCurrentActivePage() {
90          Content currentActpage = MgnlContext.getAggregationState().getCurrentContent();
91          if (currentActpage == null) {
92              currentActpage = MgnlContext.getAggregationState().getMainContent();
93          }
94          return currentActpage;
95      }
96  
97      /**
98       * <p>
99       * get ContentNode object as set by the "set" tag.
100      * </p>
101      * @return ContentNode , global container specific to the current JSP/Servlet page
102      */
103     public static Content getGlobalContentNode() {
104         try {
105             return (Content) MgnlContext.getAttribute(Resource.GLOBAL_CONTENT_NODE);
106         }
107         catch (Exception e) {
108             return null;
109         }
110     }
111 
112     /**
113      * <p>
114      * get ContentNode object as passed to the include tag.
115      * </p>
116      * @return ContentNode , local container specific to the current JSP/Servlet paragraph
117      */
118     public static Content getLocalContentNode() {
119         return MgnlContext.getAggregationState().getCurrentContent();
120     }
121 
122     /**
123      *
124      */
125     public static String getLocalContentNodeCollectionName() {
126         try {
127             return (String) MgnlContext.getAttribute(Resource.LOCAL_CONTENT_NODE_COLLECTION_NAME);
128         }
129         catch (Exception e) {
130             return StringUtils.EMPTY;
131         }
132     }
133 
134     /**
135      * <p>
136      * this only works for forms which uses enctype=multipart/form-data.
137      * </p>
138      * @return initialised multipart form object with the posted data
139      * @deprecated since 4.0 - use WebContext.getPostedForm()
140      */
141     public static MultipartForm getPostedForm() {
142         return MgnlContext.getPostedForm();
143     }
144 
145     /**
146      * <p>
147      * get selector as requested from the URI. The selector is the part between the handle and the extension.
148      * selector("http://server/a.x.1.f.4.html") = "x.1.f.4"
149      * </p>
150      * <strong>Warning - this might change in the future - see MAGNOLIA-2343 for details.</strong>
151      * @return selector String as requested from the URI
152      * @deprecated since 4.0 - use {@link info.magnolia.cms.util.SelectorUtil#getSelector}
153      */
154     public static String getSelector() {
155         return SelectorUtil.getSelector();
156     }
157 
158     /**
159      * Get the selector by index
160      * <strong>Warning - this might change in the future - see MAGNOLIA-2343 for details.</strong>
161      * @param index
162      * @return the selector value
163      * @deprecated since 4.0 - use {@link info.magnolia.cms.util.SelectorUtil#getSelector}
164      */
165     public static String getSelector(int index) {
166         return SelectorUtil.getSelector(index);
167     }
168 
169     /**
170      * <p>
171      * removes ContentNode object in resources , scope:page.
172      * </p>
173      *
174      * @deprecated not used
175      */
176     public static void removeGlobalContentNode() {
177         MgnlContext.removeAttribute(Resource.GLOBAL_CONTENT_NODE);
178     }
179 
180     /**
181      * removes ContentNode object in resources , scope:TAG.
182      */
183     public static void removeLocalContentNode() {
184         MgnlContext.getAggregationState().setCurrentContent(null);
185     }
186 
187     /**
188      *
189      */
190     public static void removeLocalContentNodeCollectionName() {
191         MgnlContext.removeAttribute(Resource.LOCAL_CONTENT_NODE_COLLECTION_NAME);
192     }
193 
194     /**
195      * Restores the request's original <code>actpage</code> attribute (i.e. the one specified by the request URI).
196      */
197     public static void restoreCurrentActivePage() {
198         setCurrentActivePage(MgnlContext.getAggregationState().getMainContent());
199     }
200 
201     /**
202      * Set the request's <code>actpage</code> attribute to <code>page</code>.
203      * @deprecated since 4.0 - use AggregationState.
204      */
205     public static void setCurrentActivePage(Content page) {
206         MgnlContext.getAggregationState().setCurrentContent(page);
207     }
208 
209     /**
210      * <p>
211      * set ContentNode object in resources, scope:page.
212      * </p>
213      * @param node to be set
214      */
215     public static void setGlobalContentNode(Content node) {
216         MgnlContext.setAttribute(Resource.GLOBAL_CONTENT_NODE, node);
217     }
218 
219     /**
220      * <p>
221      * set ContentNode object in resources , scope:TAG.
222      * </p>
223      * @param node to be set
224      */
225     public static void setLocalContentNode(Content node) {
226         MgnlContext.getAggregationState().setCurrentContent(node);
227     }
228 
229     /**
230      *
231      */
232     public static void setLocalContentNodeCollectionName(String name) {
233         MgnlContext.setAttribute(Resource.LOCAL_CONTENT_NODE_COLLECTION_NAME, name);
234     }
235 
236     /**
237      * Check for preview mode.
238      * @return boolean , true if preview is enabled
239      * @deprecated use {@link info.magnolia.cms.core.AggregationState#isPreviewMode}
240      */
241     public static boolean showPreview() {
242         return MgnlContext.getAggregationState().isPreviewMode();
243     }
244 
245     /**
246      * @deprecated use AggregationState
247      */
248     public static void setShowPreview(boolean showPreview){
249         MgnlContext.getAggregationState().setPreviewMode(showPreview);
250     }
251 
252 }