001: /*
002: * (C) Copyright 2000 - 2003 Nabh Information Systems, Inc.
003: *
004: * This program is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU General Public License
006: * as published by the Free Software Foundation; either version 2
007: * of the License, or (at your option) any later version.
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: */
019:
020: package com.nabhinc.portal.container;
021:
022: import java.util.Enumeration;
023: import java.util.Vector;
024:
025: import javax.portlet.PortletContext;
026: import javax.portlet.PortletSession;
027: import javax.servlet.http.HttpSession;
028:
029: /**
030: *
031: *
032: * @author Padmanabh dabke
033: * (c) 2003 Nabh Information Systems, Inc. All Rights Reserved.
034: */
035: public class PortletSessionImpl implements PortletSession {
036:
037: private static final String PORTLET_SCOPE_NAMESPACE = "javax.portlet.p.";
038:
039: private transient HttpSession psiSession = null;
040:
041: private PortletContext psiPortletContext = null;
042:
043: private String psiPortletWindowID = null;
044:
045: private String psiAttribPrefix = null;
046:
047: public PortletSessionImpl(String portletID, HttpSession sess,
048: PortletContext context) {
049: psiPortletWindowID = portletID;
050: psiAttribPrefix = PORTLET_SCOPE_NAMESPACE + portletID + "?";
051: psiSession = sess;
052: psiPortletContext = context;
053: }
054:
055: /**
056: * @see javax.portlet.PortletSession#getAttribute(java.lang.String)
057: */
058: public Object getAttribute(String name) {
059: return psiSession.getAttribute(psiAttribPrefix + name);
060: }
061:
062: /**
063: * @see javax.portlet.PortletSession#getAttribute(java.lang.String, int)
064: */
065: public Object getAttribute(String name, int scope) {
066: if (scope == PortletSession.APPLICATION_SCOPE)
067: return psiSession.getAttribute(name);
068: else
069: return psiSession.getAttribute(psiAttribPrefix + name);
070: }
071:
072: /**
073: * @see javax.portlet.PortletSession#getAttributeNames()
074: */
075: @SuppressWarnings("unchecked")
076: public Enumeration getAttributeNames() {
077: Enumeration appAttribs = psiSession.getAttributeNames();
078: Vector v = new Vector();
079: while (appAttribs.hasMoreElements()) {
080: String attrib = (String) appAttribs.nextElement();
081: if (attrib.startsWith(psiAttribPrefix)) {
082: int index = attrib.indexOf('?');
083: if (index > -1) {
084: attrib = attrib.substring(index + 1);
085: v.addElement(attrib);
086: }
087: }
088: }
089: return v.elements();
090: }
091:
092: /**
093: * @see javax.portlet.PortletSession#getAttributeNames(int)
094: */
095: public Enumeration getAttributeNames(int scope) {
096: if (scope == PortletSession.APPLICATION_SCOPE)
097: return psiSession.getAttributeNames();
098: else
099: return getAttributeNames();
100: }
101:
102: /**
103: * @see javax.portlet.PortletSession#getCreationTime()
104: */
105: public long getCreationTime() {
106: return psiSession.getCreationTime();
107: }
108:
109: /**
110: * @see javax.portlet.PortletSession#getId()
111: */
112: public String getId() {
113: return psiSession.getId();
114: }
115:
116: /**
117: * @see javax.portlet.PortletSession#getLastAccessedTime()
118: */
119: public long getLastAccessedTime() {
120: return psiSession.getLastAccessedTime();
121: }
122:
123: /**
124: * @see javax.portlet.PortletSession#getMaxInactiveInterval()
125: */
126: public int getMaxInactiveInterval() {
127: return psiSession.getMaxInactiveInterval();
128: }
129:
130: /**
131: * @see javax.portlet.PortletSession#invalidate()
132: */
133: public void invalidate() {
134: psiSession.invalidate();
135:
136: }
137:
138: /**
139: * @see javax.portlet.PortletSession#isNew()
140: */
141: public boolean isNew() {
142: return psiSession.isNew();
143: }
144:
145: /**
146: * @see javax.portlet.PortletSession#removeAttribute(java.lang.String)
147: */
148: public void removeAttribute(String name) {
149: psiSession.removeAttribute(psiAttribPrefix + name);
150:
151: }
152:
153: /**
154: * @see javax.portlet.PortletSession#removeAttribute(java.lang.String, int)
155: */
156: public void removeAttribute(String name, int scope) {
157: if (scope == PortletSession.APPLICATION_SCOPE) {
158: psiSession.removeAttribute(name);
159: } else {
160: removeAttribute(name);
161: }
162:
163: }
164:
165: /**
166: * @see javax.portlet.PortletSession#setAttribute(java.lang.String, java.lang.Object)
167: */
168: public void setAttribute(String name, Object value) {
169: psiSession.setAttribute(psiAttribPrefix + name, value);
170:
171: }
172:
173: /**
174: * @see javax.portlet.PortletSession#setAttribute(java.lang.String, java.lang.Object, int)
175: */
176: public void setAttribute(String name, Object value, int scope) {
177: if (scope == PortletSession.APPLICATION_SCOPE) {
178: psiSession.setAttribute(name, value);
179: } else {
180: setAttribute(name, value);
181: }
182:
183: }
184:
185: /**
186: * @see javax.portlet.PortletSession#setMaxInactiveInterval(int)
187: */
188: public void setMaxInactiveInterval(int interval) {
189: psiSession.setMaxInactiveInterval(interval);
190:
191: }
192:
193: /**
194: * @see javax.portlet.PortletSession#getPortletContext()
195: */
196: public PortletContext getPortletContext() {
197: return psiPortletContext;
198: }
199:
200: /**
201: *
202: * @param portletID
203: */
204: public void setPortletWindowID(String portletID) {
205: psiAttribPrefix = PORTLET_SCOPE_NAMESPACE + portletID + "?";
206: psiPortletWindowID = portletID;
207: }
208:
209: public String getPortletWindowID() {
210: return psiPortletWindowID;
211: }
212:
213: public HttpSession getServletSession() {
214: return psiSession;
215: }
216:
217: public void setServletSession(HttpSession session) {
218: psiSession = session;
219: }
220:
221: }
|