001: //** Copyright Statement ***************************************************
002: //The Salmon Open Framework for Internet Applications (SOFIA)
003: // Copyright (C) 1999 - 2002, Salmon LLC
004: //
005: // This program is free software; you can redistribute it and/or
006: // modify it under the terms of the GNU General Public License version 2
007: // as published by the Free Software Foundation;
008: //
009: // This program is distributed in the hope that it will be useful,
010: // but WITHOUT ANY WARRANTY; without even the implied warranty of
011: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: // GNU General Public License for more details.
013: //
014: // You should have received a copy of the GNU General Public License
015: // along with this program; if not, write to the Free Software
016: // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
017: //
018: // For more information please visit http://www.salmonllc.com
019: //** End Copyright Statement ***************************************************
020:
021: package com.salmonllc.html;
022:
023: import java.util.Enumeration;
024:
025: import javax.portlet.PortletContext;
026: import javax.portlet.PortletSession;
027: import javax.servlet.ServletContext;
028: import javax.servlet.http.HttpSession;
029: import javax.servlet.http.HttpSessionContext;
030:
031: /**
032: * Wrapper for the http session object, used by the framework to adapt portlet sessions to http sessions
033: */
034: public class HttpSessionWrapper implements HttpSession {
035: HttpSession _sess;
036: PortletSession _psess;
037:
038: public HttpSessionWrapper(PortletSession sess) {
039: _psess = sess;
040: }
041:
042: public HttpSessionWrapper(HttpSession sess) {
043: _sess = sess;
044: }
045:
046: /* (non-Javadoc)
047: * @see javax.servlet.http.HttpSession#getAttribute(java.lang.String)
048: */
049: public Object getAttribute(String arg0) {
050: if (_sess != null)
051: return _sess.getAttribute(arg0);
052: else
053: return _psess.getAttribute(arg0,
054: PortletSession.APPLICATION_SCOPE);
055: }
056:
057: /* (non-Javadoc)
058: * @see javax.servlet.http.HttpSession#getAttributeNames()
059: */
060: public Enumeration getAttributeNames() {
061: if (_sess != null)
062: return _sess.getAttributeNames();
063: else
064: return _psess
065: .getAttributeNames(PortletSession.APPLICATION_SCOPE);
066: }
067:
068: /* (non-Javadoc)
069: * @see javax.servlet.http.HttpSession#getCreationTime()
070: */
071: public long getCreationTime() {
072: if (_sess != null)
073: return _sess.getCreationTime();
074: else
075: return _psess.getCreationTime();
076: }
077:
078: /* (non-Javadoc)
079: * @see javax.servlet.http.HttpSession#getId()
080: */
081: public String getId() {
082: if (_sess != null)
083: return _sess.getId();
084: else
085: return _psess.getId();
086: }
087:
088: /* (non-Javadoc)
089: * @see javax.servlet.http.HttpSession#getLastAccessedTime()
090: */
091: public long getLastAccessedTime() {
092: if (_sess != null)
093: return _sess.getLastAccessedTime();
094: else
095: return _psess.getLastAccessedTime();
096: }
097:
098: /* (non-Javadoc)
099: * @see javax.servlet.http.HttpSession#getMaxInactiveInterval()
100: */
101: public int getMaxInactiveInterval() {
102: if (_sess != null)
103: return _sess.getMaxInactiveInterval();
104: else
105: return _psess.getMaxInactiveInterval();
106: }
107:
108: /* (non-Javadoc)
109: * @see javax.servlet.http.HttpSession#getServletContext()
110: */
111: public ServletContext getServletContext() {
112: //if (_sess != null)
113: // return _sess.getServletContext();
114: //else
115: return null;
116: }
117:
118: /* (non-Javadoc)
119: * @see javax.servlet.http.HttpSession#getServletContext()
120: */
121: public PortletContext getPortletContext() {
122: if (_sess != null)
123: return null;
124: else
125: return _psess.getPortletContext();
126: }
127:
128: /* (non-Javadoc)
129: * @see javax.servlet.http.HttpSession#getSessionContext()
130: */
131: public HttpSessionContext getSessionContext() {
132: if (_sess != null)
133: return _sess.getSessionContext();
134: else
135: return null;
136: }
137:
138: /* (non-Javadoc)
139: * @see javax.servlet.http.HttpSession#getValue(java.lang.String)
140: */
141: public Object getValue(String arg0) {
142: if (_sess != null)
143: return _sess.getAttribute(arg0);
144: else
145: return _psess.getAttribute(arg0);
146: }
147:
148: /* (non-Javadoc)
149: * @see javax.servlet.http.HttpSession#getValueNames()
150: */
151: public String[] getValueNames() {
152: if (_sess != null)
153: return _sess.getValueNames();
154: else
155: return null;
156: }
157:
158: /* (non-Javadoc)
159: * @see javax.servlet.http.HttpSession#invalidate()
160: */
161: public void invalidate() {
162: if (_sess != null)
163: _sess.invalidate();
164: else
165: _psess.invalidate();
166:
167: }
168:
169: /* (non-Javadoc)
170: * @see javax.servlet.http.HttpSession#isNew()
171: */
172: public boolean isNew() {
173: if (_sess != null)
174: return _sess.isNew();
175: else
176: return _psess.isNew();
177: }
178:
179: /* (non-Javadoc)
180: * @see javax.servlet.http.HttpSession#putValue(java.lang.String, java.lang.Object)
181: */
182: public void putValue(String arg0, Object arg1) {
183: if (_sess != null)
184: _sess.setAttribute(arg0, arg1);
185: else
186: _psess.setAttribute(arg0, arg1,
187: PortletSession.APPLICATION_SCOPE);
188: }
189:
190: /* (non-Javadoc)
191: * @see javax.servlet.http.HttpSession#removeAttribute(java.lang.String)
192: */
193: public void removeAttribute(String arg0) {
194: if (_sess != null)
195: _sess.removeAttribute(arg0);
196: else
197: _psess.removeAttribute(arg0,
198: PortletSession.APPLICATION_SCOPE);
199: }
200:
201: /* (non-Javadoc)
202: * @see javax.servlet.http.HttpSession#removeValue(java.lang.String)
203: */
204: public void removeValue(String arg0) {
205: if (_sess != null)
206: _sess.removeAttribute(arg0);
207: else
208: _psess.removeAttribute(arg0,
209: PortletSession.APPLICATION_SCOPE);
210:
211: }
212:
213: /* (non-Javadoc)
214: * @see javax.servlet.http.HttpSession#setAttribute(java.lang.String, java.lang.Object)
215: */
216: public void setAttribute(String arg0, Object arg1) {
217: if (_sess != null)
218: _sess.setAttribute(arg0, arg1);
219: else
220: _psess.setAttribute(arg0, arg1,
221: PortletSession.APPLICATION_SCOPE);
222:
223: }
224:
225: /* (non-Javadoc)
226: * @see javax.servlet.http.HttpSession#setMaxInactiveInterval(int)
227: */
228: public void setMaxInactiveInterval(int arg0) {
229: if (_sess != null)
230: _sess.setMaxInactiveInterval(arg0);
231: else
232: _psess.setMaxInactiveInterval(arg0);
233:
234: }
235:
236: }
|