Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/obinary/cms/util/Resource.java


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-2003 obinary Ltd. (http://www.obinary.com) All rights reserved.
11   *
12   * */
13  
14  
15  
16  package com.obinary.cms.util;
17  
18  
19  import com.obinary.cms.core.Content;
20  import com.obinary.cms.core.HierarchyManager;
21  import com.obinary.cms.core.Container;
22  import com.obinary.cms.core.Atom;
23  import com.obinary.cms.Aggregator;
24  import com.obinary.cms.beans.MultipartForm;
25  import com.obinary.cms.beans.File;
26  
27  import javax.servlet.http.HttpServletRequest;
28  import javax.servlet.jsp.PageContext;
29  import java.util.Collection;
30  import java.util.Iterator;
31  
32  
33  /**
34   * Date: Apr 28, 2003
35   * Time: 11:20:59 AM
36   * @author Sameer Charles
37   * @version 1.0
38   */
39  
40  
41  
42  public class Resource {
43  
44  
45  
46      public static final int SCOPE_GLOBAL = 1;
47      public static final int SCOPE_LOCAL = 2;
48  
49  
50  
51      private static final String GLOBAL_CONTAINER = "contentObjGlobal";
52      private static final String LOCAL_CONTAINER = "contentObj";
53      private static final String LOCAL_CONTAINERLIST_NAME = "localContainerListName";
54  
55  
56  
57      /**
58       * <p>get Content object as requested from the URI</p>
59       *
60       * @param req HttpServletRequest as received in JSP or servlet
61       * @return currently active page, as requested from the URI
62       */
63      public static Content getActivePage(HttpServletRequest req) {
64          return (Content) req.getAttribute(Aggregator.ACTPAGE);
65      }
66  
67  
68  
69      /**
70       * <p>get file object associated with the requested atom</p>
71       *
72       * @param req HttpServletRequest as received in JSP or servlet
73       * @return currently atom
74       */
75      public static File getFile(HttpServletRequest req) {
76          return (File) req.getAttribute(Aggregator.FILE);
77      }
78  
79  
80  
81       /**
82       * <p>get Content object as requested from the URI</p>
83       *
84       * @param req HttpServletRequest as received in JSP or servlet
85       * @return currently active page, as requested from the URI
86       */
87      public static Content getCurrentActivePage(HttpServletRequest req) {
88           Content currentActpage;
89           currentActpage = (Content) req.getAttribute(Aggregator.CURRENT_ACTPAGE);
90           if (currentActpage == null) currentActpage = (Content) req.getAttribute(Aggregator.ACTPAGE);
91           return currentActpage;
92      }
93  
94  
95  
96  
97  
98      /**
99       * <p>get HierarchyManager object from the request OR from the user session
100      * this hierarchy manager points to website repository, in order to swith between user
101      * and website repositories, use method (changeContext) on this object</p>
102      *
103      * @param req HttpServletRequest as received in JSP or servlet
104      * @return hierarchy manager, for the website repository
105      */
106     public static HierarchyManager getHierarchyManager(HttpServletRequest req) {
107         return (HierarchyManager)req.getAttribute(Aggregator.HIERARCHY_MANAGER);
108     }
109 
110 
111 
112     /**
113      * <p>this only works for forms which uses enctype=multipart/form-data</p>
114      *
115      * @param req HttpServletRequest as received in JSP or servlet
116      * @return initialised multipart form object with the posted data
117      */
118     public static MultipartForm getPostedForm(HttpServletRequest req) {
119         return (MultipartForm)req.getAttribute("multipartform");
120     }
121 
122 
123 
124     /**
125      * <p>get Container object as passed to the include tag</p>
126      *
127      * @param req HttpServletRequest as received in JSP or servlet
128      * @return Container , local container specific to the current JSP/Servlet paragraph
129      */
130     public static Container getLocalContainer(HttpServletRequest req) {
131         try {
132             return (Container)req.getAttribute(Resource.LOCAL_CONTAINER);
133         } catch (Exception e) {return null;}
134     }
135 
136 
137 
138     /**
139      * <p>set Container object in resources , scope:TAG</p>
140      *
141      * @param req HttpServletRequest as received in JSP or servlet
142      * @param container to be set
143      */
144     public static void setLocalContainer(HttpServletRequest req, Container container) {
145         req.setAttribute(Resource.LOCAL_CONTAINER,container);
146     }
147 
148 
149 
150     /**
151      * <p>removes Container object in resources , scope:TAG</p>
152      *
153      * @param req HttpServletRequest as received in JSP or servlet
154      */
155     public static void removeLocalContainer(HttpServletRequest req) {
156         req.removeAttribute(Resource.LOCAL_CONTAINER);
157     }
158 
159 
160 
161     /**
162      * <p>get Container object as set by the "set" tag</p>
163      *
164      * @param req HttpServletRequest as received in JSP or servlet
165      * @return Container , global container specific to the current JSP/Servlet page
166      */
167     public static Container getGlobalContainer(HttpServletRequest req) {
168         try {
169             return (Container)req.getAttribute(Resource.GLOBAL_CONTAINER);
170         } catch (Exception e) {return null;}
171     }
172 
173 
174 
175     /**
176      * <p>set Container object in resources, scope:page</p>
177      *
178      * @param req HttpServletRequest as received in JSP or servlet
179      * @param container to be set
180      */
181     public static void setGlobalContainer(HttpServletRequest req, Container container) {
182         req.setAttribute(Resource.GLOBAL_CONTAINER,container);
183     }
184 
185 
186 
187     /**
188      * <p>removes Container object in resources , scope:page</p>
189      *
190      * @param req HttpServletRequest as received in JSP or servlet
191      */
192     public static void removeGlobalContainer(HttpServletRequest req) {
193         req.removeAttribute(Resource.GLOBAL_CONTAINER);
194     }
195 
196 
197 
198     /**
199      *
200      */
201     public static void setLocalContainerListName(HttpServletRequest req, String name) {
202         req.setAttribute(Resource.LOCAL_CONTAINERLIST_NAME,name);
203     }
204 
205 
206 
207     /**
208      *
209      */
210     public static String getLocalContainerListName(HttpServletRequest req) {
211         try {
212             return (String)req.getAttribute(Resource.LOCAL_CONTAINERLIST_NAME);
213         } catch (Exception e) {return "";}
214     }
215 
216 
217 
218     /**
219      *
220      */
221     public static void removeLocalContainerListName(HttpServletRequest req) {
222         req.removeAttribute(Resource.LOCAL_CONTAINERLIST_NAME);
223     }
224 
225 
226 
227     /**
228      * <p>check for preview mode</p>
229      *
230      * @param req HttpServletRequest as received in JSP or servlet
231      * @return boolean , true if preview is enabled
232      */
233     public static boolean showPreview(HttpServletRequest req) {
234         return (req.getParameter("preview") != null);
235     }
236 
237 
238 
239 
240 
241 }