01: /*
02: * Wilos Is a cLever process Orchestration Software - http://www.wilos-project.org
03: * Copyright (C) 2006-2007 Paul Sabatier University, IUP ISI (Toulouse, France) <massie@irit.fr>
04: *
05: * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
06: * General Public License as published by the Free Software Foundation; either version 2 of the License,
07: * or (at your option) any later version.
08: *
09: * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
10: * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11: * GNU General Public License for more details.
12: *
13: * You should have received a copy of the GNU General Public License along with this program; if not,
14: * write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15: */
16:
17: package wilos.presentation.web.utils;
18:
19: import javax.faces.context.FacesContext;
20: import javax.servlet.http.HttpServletRequest;
21: import javax.servlet.http.HttpSession;
22:
23: /**
24: * Allow to manage the web session and its attributes.
25: *
26: */
27: public class WebSessionService {
28:
29: /**
30: * The session attribute WilosUser Id.
31: */
32: public static final String WILOS_USER_ID = "wilosUserId";
33:
34: /**
35: * The session attribute Project Id.
36: */
37: public static final String PROJECT_ID = "projectId";
38:
39: /**
40: * The session attribute Role Type.
41: */
42: public static final String ROLE_TYPE = "roleType";
43:
44: /**
45: * The session attribute Tree Mode.
46: */
47: public static final String TREE_MODE = "treeMode";
48:
49: /**
50: * The session attribute Concrete Break Down Element.
51: */
52: public static final String CONCRETE_BREAK_DOWN_ELEMENT = "concreteBreakDownElement";
53:
54: /**
55: * Gets the value of the attribute
56: * @param _attributeName the name of the attribute to get
57: * @return the value of the attribute
58: */
59: public static Object getAttribute(String _attributeName) {
60: return getHttpSession().getAttribute(_attributeName);
61: }
62:
63: /**
64: * Sets an attribute and its value in the session
65: * @param _attributeName the name of the attribute
66: * @param _value the value of the attribute
67: */
68: public static void setAttribute(String _attributeName, Object _value) {
69: getHttpSession().setAttribute(_attributeName, _value);
70: }
71:
72: /**
73: * Removes all the attributes in the current session
74: *
75: */
76: public static void cleanSesssion() {
77: getHttpSession().removeAttribute(WILOS_USER_ID);
78: getHttpSession().removeAttribute(PROJECT_ID);
79: getHttpSession().removeAttribute(ROLE_TYPE);
80: getHttpSession().removeAttribute(TREE_MODE);
81: getHttpSession().removeAttribute(CONCRETE_BREAK_DOWN_ELEMENT);
82: }
83:
84: /**
85: * Returns the current session
86: * @return the http session
87: */
88: private static HttpSession getHttpSession() {
89: HttpServletRequest httpServletRequest = (HttpServletRequest) FacesContext
90: .getCurrentInstance().getExternalContext().getRequest();
91: return httpServletRequest.getSession();
92: }
93: }
|