KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > clipbuilder > html > SessionManager


1 package org.jahia.clipbuilder.html;
2
3 import javax.servlet.http.*;
4
5 import org.jahia.clipbuilder.html.bean.*;
6 import org.jahia.clipbuilder.html.struts.Util.*;
7 import org.jahia.clipbuilder.html.struts.webBrowser.*;
8 import org.jahia.clipbuilder.html.web.*;
9 import java.util.*;
10
11 /**
12  * Access to session object
13  *
14  *@author Tlili Khaled
15  */

16 public class SessionManager {
17     private static org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(SessionManager.class);
18
19
20     /**
21      * Constructor for the SessionManager object
22      */

23     public SessionManager() {
24     }
25
26
27     /**
28      * Sets the ClipperBean attribute of the SessionManager object
29      *
30      *@param httpServletRequest The new ClipperBean value
31      *@param cBean The new ClipperBean value
32      */

33     public static void setClipperBean(HttpServletRequest httpServletRequest, ClipperBean cBean) {
34         HttpSession session = httpServletRequest.getSession();
35         String JavaDoc nameSpace = getNameSpace(httpServletRequest);
36         if (nameSpace == null) {
37             session.setAttribute(Constants.CLIPPER_BEAN, cBean);
38         }
39         else {
40             session.setAttribute(nameSpace + Constants.CLIPPER_BEAN, cBean);
41         }
42     }
43
44
45     /**
46      * Sets the WebBrowserForm attribute of the AbstractWizardAction object
47      *
48      *@param request The new WebBrowserForm value
49      *@param w The new WebBrowserForm value
50      */

51     public static void setWebBrowserForm(HttpServletRequest request, WebBrowserForm w) {
52         HttpSession session = request.getSession();
53         session.setAttribute(Constants.WEB_BROWSER_FORM, w);
54     }
55
56
57     /**
58      * Sets the HttpState attribute of the SessionManager object
59      */

60     /*
61      * public static void setHttpState(HttpServletRequest httpServletRequest, HttpState state) {
62      * HttpSession session = httpServletRequest.getSession();
63      * session.setAttribute(org.jahia.clipbuilder.html.web.Constant.WebConstants.HTTPSTATE, state);
64      * }
65      */

66     /**
67      * Sets the LastBuildedUrlBean attribute of the SessionManager class
68      */

69     /*
70      * public static void setLastBuildedUrlBean(HttpServletRequest httpServletRequest, UrlBean u) {
71      * HttpSession session = httpServletRequest.getSession();
72      * session.setAttribute(org.jahia.clipbuilder.html.web.Constant.WebConstants.LAST_PROCESSED_URL, u);
73      * }
74      */

75     /**
76      * Sets the WebClient attribute of the SessionManager class
77      */

78     /*
79      * public static void setWebClient(HttpServletRequest request, HTMLUnitProcessor client) {
80      * HttpSession session = request.getSession();
81      * session.setAttribute(org.jahia.clipbuilder.html.web.Constant.WebConstants.ADVANCED_WEBCLIENT, client);
82      * }
83      */

84     /**
85      * Sets the UrlEncoder attribute of the SessionManager class
86      */

87     /*
88      * public static void setUrlEncoder(HttpServletRequest request, UrlEncoderIF encoder) {
89      * HttpSession session = request.getSession();
90      * session.setAttribute(org.jahia.clipbuilder.html.web.Constant.WebConstants.URL_ENCODER, encoder);
91      * }
92      */

93     /**
94      * Sets the URLMap attribute of the AbstractWizardAction object
95      */

96     /*
97      * public static void setURLMap(HttpServletRequest httpServletRequest, URLMap map) {
98      * HttpSession session = httpServletRequest.getSession();
99      * session.setAttribute(Constants.URL_MAP, map);
100      * }
101      */

102     /**
103      * Sets the RecorderBean attribute of the SessionManager class
104      *
105      *@param httpServletRequest The new RecorderBean value
106      *@param rb The new RecorderBean value
107      */

108     public static void setRecorderBean(HttpServletRequest httpServletRequest, RecordingBean rb) {
109         HttpSession session = httpServletRequest.getSession();
110         session.setAttribute(org.jahia.clipbuilder.html.web.Constant.WebConstants.RECORDING, rb);
111     }
112
113
114
115     /**
116      * Gets the HTMLDocumentBuilder attribute of the SessionManager class
117      *
118      *@param r Description of Parameter
119      *@param htd Description of Parameter
120      */

121     public static void setHTMLDocumentBuilder(HttpServletRequest r, HTMLDocumentBuilder htd) {
122         HttpSession session = r.getSession();
123         String JavaDoc nameSpace = getNameSpace(r);
124
125         if (nameSpace == null) {
126             session.setAttribute(Constants.HTMLDOCUMENT_BUILDER, htd);
127         }
128         else {
129             session.setAttribute(nameSpace + Constants.HTMLDOCUMENT_BUILDER, htd);
130         }
131     }
132
133
134     /**
135      * Sets the WebBrowserSimulator attribute of the WebBrowserAction object
136      *
137      *@param request The new WebBrowserSimulator value
138      *@param w The new WebBrowserSimulator value
139      */

140     public static void setWebBrowserSimulator(HttpServletRequest request, WebBrowserSimulator w) {
141         request.getSession().setAttribute(Constants.WEB_BROWSER_SIMULATOR, w);
142     }
143
144
145     /**
146      * Gets the WebBrowserSimulator attribute of the WebBrowserAction object
147      *
148      *@param request Description of Parameter
149      *@return The WebBrowserSimulator value
150      */

151     public static WebBrowserSimulator getWebBrowserSimulator(HttpServletRequest request) {
152         return (WebBrowserSimulator) request.getSession().getAttribute(Constants.WEB_BROWSER_SIMULATOR);
153     }
154
155
156     /**
157      * Gets the UrlEncoder attribute of the SessionManager class
158      */

159     /*
160      * public static UrlEncoderIF getUrlEncoder(HttpServletRequest request) {
161      * HttpSession session = request.getSession();
162      * return (UrlEncoderIF) session.getAttribute(org.jahia.clipbuilder.html.web.Constant.WebConstants.URL_ENCODER);
163      * }
164      */

165     /**
166      * Gets the WebBrowserForm attribute of the SessionManager object
167      *
168      *@param httpServletRequest Description of Parameter
169      *@return The WebBrowserForm value
170      */

171     public static WebBrowserForm getWebBrowserForm(HttpServletRequest httpServletRequest) {
172         HttpSession session = httpServletRequest.getSession();
173         WebBrowserForm w = (WebBrowserForm) session.getAttribute(Constants.WEB_BROWSER_FORM);
174         return w;
175     }
176
177
178
179     /**
180      * Gets the ClipperBean attribute of the SessionManager object
181      *
182      *@param httpServletRequest Description of Parameter
183      *@return The ClipperBean value
184      */

185     public static ClipperBean getClipperBean(HttpServletRequest httpServletRequest) {
186         ClipperBean bean = new ClipperBean();
187         HttpSession session = httpServletRequest.getSession();
188         String JavaDoc nameSpace = getNameSpace(httpServletRequest);
189         if (nameSpace != null) {
190             logger.debug("NameSpace: " + nameSpace);
191             bean = (ClipperBean) session.getAttribute(nameSpace + Constants.CLIPPER_BEAN);
192         }
193         else {
194             logger.debug("NameSpac is null: ");
195             bean = (ClipperBean) session.getAttribute(Constants.CLIPPER_BEAN);
196         }
197         //Handing error
198
if (bean == null) {
199             logger.error("[ClipperBean error: Not found]");
200         }
201
202         //debugSession(session);
203

204         return bean;
205     }
206
207
208
209     /**
210      * Gets the URLMap attribute of the SessionManager object
211      *
212      *@param r Description of Parameter
213      *@return The URLMap value
214      */

215     /*
216      * public static URLMap getURLMap(HttpServletRequest httpServletRequest) {
217      * HttpSession session = httpServletRequest.getSession();
218      * return (URLMap) session.getAttribute(Constants.URL_MAP);
219      * }
220      */

221     public static HTMLDocumentBuilder getHTMLDocumentBuilder(HttpServletRequest r) {
222         HttpSession session = r.getSession();
223         String JavaDoc nameSpace = getNameSpace(r);
224         if (nameSpace == null) {
225             return (HTMLDocumentBuilder) session.getAttribute(Constants.HTMLDOCUMENT_BUILDER);
226         }
227         else {
228             return (HTMLDocumentBuilder) session.getAttribute(nameSpace + Constants.HTMLDOCUMENT_BUILDER);
229         }
230     }
231
232
233
234     /**
235      * Gets the HttpState attribute of the SessionManager object
236      */

237     /*
238      * public static HttpState getHttpState(HttpServletRequest httpServletRequest) {
239      * HttpSession session = httpServletRequest.getSession();
240      * HttpState hs = (HttpState) session.getAttribute(org.jahia.clipbuilder.html.web.Constant.WebConstants.HTTPSTATE);
241      * return hs;
242      * }
243      */

244     /**
245      * Gets the WebClient attribute of the SessionManager class
246      */

247     /*
248      * public static HTMLUnitProcessor getWebClient(HttpServletRequest request) {
249      * HttpSession session = request.getSession();
250      * HTMLUnitProcessor client = (HTMLUnitProcessor) session.getAttribute(org.jahia.clipbuilder.html.web.Constant.WebConstants.ADVANCED_WEBCLIENT);
251      * return client;
252      * }
253      */

254     /**
255      * Gets the RecorderBean attribute of the SessionManager object
256      *
257      *@param httpServletRequest Description of Parameter
258      *@return The RecorderBean value
259      */

260     public static RecordingBean getRecorderBean(HttpServletRequest httpServletRequest) {
261         HttpSession session = httpServletRequest.getSession();
262         RecordingBean rb = (RecordingBean) session.getAttribute(org.jahia.clipbuilder.html.web.Constant.WebConstants.RECORDING);
263         return rb;
264     }
265
266
267
268     /**
269      * Gets the LastBuildedUrlBean attribute of the SessionManager class
270      */

271     /*
272      * public static UrlBean getLastBuildedUrlBean(HttpServletRequest httpServletRequest) {
273      * HttpSession session = httpServletRequest.getSession();
274      * UrlBean u = (UrlBean) session.getAttribute(org.jahia.clipbuilder.html.web.Constant.WebConstants.LAST_PROCESSED_URL);
275      * return u;
276      * }
277      */

278     /**
279      * Gets the ClippersManagerBean attribute of the SessionManager object
280      *
281      *@param request Description of Parameter
282      *@return The ClippersManagerBean value
283      */

284     public static ClippersManagerBean getClippersManagerBean(HttpServletRequest request) {
285         HttpSession session = request.getSession();
286         ClippersManagerBean bean = (ClippersManagerBean) session.getAttribute(ClippersManagerBean.class.toString());
287         //Handing error
288
if (bean == null) {
289             logger.error("[ClipperBean error: Not found]");
290         }
291         return bean;
292     }
293
294
295     /**
296      * Gets the NameSpace attribute of the SessionManager object
297      *
298      *@param request Description of Parameter
299      *@return The NameSpace value
300      */

301     public static String JavaDoc getNameSpace(HttpServletRequest request) {
302         String JavaDoc nameSpace = RequestParameterManager.getNameSpace(request);
303         logger.debug("get NameSpace: " + nameSpace);
304         return nameSpace;
305     }
306
307
308     /**
309      * Description of the Method
310      *
311      *@param request Description of Parameter
312      *@return Description of the Returned Value
313      */

314     public static boolean sessionExist(HttpServletRequest request) {
315         return !(request.getSession() == null);
316     }
317
318
319     /**
320      * Description of the Method
321      *
322      *@param request Description of Parameter
323      */

324     public static void removeWebBrowserSimulator(HttpServletRequest request) {
325         request.getSession().removeAttribute(Constants.WEB_BROWSER_SIMULATOR);
326     }
327
328
329
330     /**
331      * Description of the Method
332      *
333      *@param r Description of Parameter
334      */

335     public static void removeHTMLDocumentBuilder(HttpServletRequest r) {
336         HttpSession session = r.getSession();
337         String JavaDoc nameSpace = getNameSpace(r);
338         if (nameSpace == null) {
339             session.removeAttribute(Constants.HTMLDOCUMENT_BUILDER);
340         }
341         else {
342             session.removeAttribute(nameSpace + Constants.HTMLDOCUMENT_BUILDER);
343         }
344     }
345
346
347     /**
348      * Description of the Method
349      *
350      *@param request Description of Parameter
351      */

352     public static void initSessionAttributes(HttpServletRequest request) {
353         //session.invalidate();
354

355         // remove all attribute from session
356
/*
357          * Enumeration enume = session.getAttributeNames();
358          * while(enume.hasMoreElements()){
359          * String attName = (String)enume.nextElement();
360          * session.removeAttribute(attName);
361          * }
362          */

363         // init clipperManager
364
initClippersManagerBean(request);
365     }
366
367
368     /**
369      * Description of the Method
370      */

371     /*
372      * public static void removeWebClient(HttpServletRequest httpServletRequest) {
373      * HttpSession session = httpServletRequest.getSession();
374      * session.removeAttribute(org.jahia.clipbuilder.html.web.Constant.WebConstants.SIMPLE_WEBCLIENT);
375      * }
376      */

377     /**
378      *@param httpServletRequest Description of Parameter
379      */

380     public static void removeClipperBean(HttpServletRequest httpServletRequest) {
381         HttpSession session = httpServletRequest.getSession();
382         String JavaDoc nameSpace = getNameSpace(httpServletRequest);
383         if (nameSpace == null) {
384             session.removeAttribute(Constants.CLIPPER_BEAN);
385         }
386         else {
387             session.removeAttribute(nameSpace + Constants.CLIPPER_BEAN);
388         }
389     }
390
391
392     /*
393      * public static void removeHttpState(HttpServletRequest httpServletRequest) {
394      * HttpSession session = httpServletRequest.getSession();
395      * session.removeAttribute(org.jahia.clipbuilder.html.web.Constant.WebConstants.HTTPSTATE);
396      * }
397      */

398     /**
399      * Description of the Method
400      *
401      *@param httpServletRequest Description of Parameter
402      */

403     public static void initClippersManagerBean(HttpServletRequest httpServletRequest) {
404         ClippersManagerBean bean = new ClippersManagerBean();
405         HttpSession session = httpServletRequest.getSession();
406         session.setAttribute(ClippersManagerBean.class.toString(), bean);
407     }
408
409
410     /**
411      * Description of the Method
412      *
413      *@param session Description of Parameter
414      */

415     private static void debugSession(HttpSession session) {
416         Enumeration enu = session.getAttributeNames();
417
418         while (enu.hasMoreElements()) {
419             logger.debug("Session attribut name: " + enu.nextElement().toString());
420         }
421     }
422
423 }
424
Popular Tags