01: /*
02: ItsNat Java Web Application Framework
03: Copyright (C) 2007 Innowhere Software Services S.L., Spanish Company
04: Author: Jose Maria Arranz Santamaria
05:
06: This program is free software: you can redistribute it and/or modify
07: it under the terms of the GNU Affero General Public License as published by
08: the Free Software Foundation, either version 3 of the License, or
09: (at your option) any later version. See the GNU Affero General Public
10: License for more details. See the copy of the GNU Affero General Public License
11: included in this program. If not, see <http://www.gnu.org/licenses/>.
12: */
13:
14: package org.itsnat.impl.core.http;
15:
16: import java.util.Enumeration;
17: import org.itsnat.core.http.ItsNatHttpSession;
18: import org.itsnat.impl.core.ItsNatServletContextImpl;
19: import org.itsnat.impl.core.ItsNatSessionImpl;
20: import javax.servlet.http.HttpSession;
21:
22: /**
23: *
24: * @author jmarranz
25: */
26: public class ItsNatHttpSessionImpl extends ItsNatSessionImpl implements
27: ItsNatHttpSession {
28: protected HttpSession session;
29: protected boolean msie; // No tiene por qué hacerse pública
30: protected String userAgent;
31:
32: /**
33: * Creates a new instance of ItsNatHttpSessionImpl
34: */
35: public ItsNatHttpSessionImpl(HttpSession session,
36: ItsNatServletContextImpl context, String userAgent) {
37: super (context);
38:
39: this .session = session;
40: this .userAgent = userAgent;
41: this .msie = isMSIE(userAgent);
42: }
43:
44: public HttpSession getHttpSession() {
45: return session;
46: }
47:
48: public Object getOriginalSessionObject() {
49: return session;
50: }
51:
52: public boolean isMSIE() {
53: return msie;
54: }
55:
56: public static boolean isMSIE(String userAgent) {
57: // Opera siempre ha tratado de ser un clon del Internet Explorer
58: // por tanto consideramos como "MSIE" a Opera
59: return ((userAgent.indexOf("MSIE") != -1) || (userAgent
60: .indexOf("Opera") != -1));
61: }
62:
63: public String getUserAgent() {
64: return userAgent;
65: }
66:
67: public boolean isUserAgentCompatible(String userAgent) {
68: // Útil en el caso de control remoto
69: // Las actualizaciones via JavaScript de un navegador (ej. MSIE)
70: // pueden no valer para otro (ej. Firefox), es el caso sobre todo
71: // de los paths de los nodos
72: return (isMSIE() == isMSIE(userAgent));
73: }
74:
75: public Object getAttribute(String name) {
76: return session.getAttribute(name);
77: }
78:
79: public Enumeration getAttributeNames() {
80: return session.getAttributeNames();
81: }
82:
83: public void removeAttribute(String name) {
84: session.removeAttribute(name);
85: }
86:
87: public void setAttribute(String name, Object value) {
88: session.setAttribute(name, value);
89: }
90: }
|