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