1 16 package org.apache.cocoon.environment.portlet; 17 18 import org.apache.cocoon.environment.Session; 19 20 import java.util.Enumeration ; 21 import java.util.NoSuchElementException ; 22 23 34 public final class PortletSession implements Session { 35 36 private static final String APP_SCOPE = PortletEnvironment.SESSION_APPLICATION_SCOPE; 37 private static final String PORTLET_SCOPE = PortletEnvironment.SESSION_PORTLET_SCOPE; 38 39 javax.portlet.PortletSession session; 40 41 46 private int scope; 47 48 51 public PortletSession(javax.portlet.PortletSession session, int scope) { 52 this.scope = scope; 53 this.session = session; 54 } 55 56 68 public long getCreationTime() { 69 return this.session.getCreationTime(); 70 } 71 72 83 public String getId() { 84 return this.session.getId(); 85 } 86 87 105 public long getLastAccessedTime() { 106 return this.session.getLastAccessedTime(); 107 } 108 109 117 public void setMaxInactiveInterval(int interval) { 118 this.session.setMaxInactiveInterval(interval); 119 } 120 121 136 public int getMaxInactiveInterval() { 137 return this.session.getMaxInactiveInterval(); 138 } 139 140 151 public Object getAttribute(String name) { 152 if (name.startsWith(APP_SCOPE)) { 153 return this.session.getAttribute(name.substring(APP_SCOPE.length()), 154 javax.portlet.PortletSession.APPLICATION_SCOPE); 155 } else if (name.startsWith(PORTLET_SCOPE)) { 156 return this.session.getAttribute(name.substring(PORTLET_SCOPE.length()), 157 javax.portlet.PortletSession.PORTLET_SCOPE); 158 } else { 159 return this.session.getAttribute(name, this.scope); 160 } 161 } 162 163 180 public Enumeration getAttributeNames() { 181 final Enumeration names1 = this.session.getAttributeNames(javax.portlet.PortletSession.PORTLET_SCOPE); 182 final Enumeration names2 = this.session.getAttributeNames(javax.portlet.PortletSession.APPLICATION_SCOPE); 183 184 return new Enumeration () { 185 public boolean hasMoreElements() { 186 return names1.hasMoreElements() || names2.hasMoreElements(); 187 } 188 189 public Object nextElement() throws NoSuchElementException { 190 if (names1.hasMoreElements()) { 191 return PORTLET_SCOPE + names1.nextElement(); 192 } else if (names2.hasMoreElements()) { 193 return APP_SCOPE + names2.nextElement(); 194 } 195 196 throw new NoSuchElementException (); 197 } 198 }; 199 } 200 201 215 public void setAttribute(String name, Object value) { 216 if (name.startsWith(APP_SCOPE)) { 217 this.session.setAttribute(name.substring(APP_SCOPE.length()), 218 value, 219 javax.portlet.PortletSession.APPLICATION_SCOPE); 220 } else if (name.startsWith(PORTLET_SCOPE)) { 221 this.session.setAttribute(name.substring(PORTLET_SCOPE.length()), 222 value, 223 javax.portlet.PortletSession.PORTLET_SCOPE); 224 } else { 225 this.session.setAttribute(name, value, this.scope); 226 } 227 } 228 229 241 public void removeAttribute(String name) { 242 if (name.startsWith(APP_SCOPE)) { 243 this.session.removeAttribute(name.substring(APP_SCOPE.length()), 244 javax.portlet.PortletSession.APPLICATION_SCOPE); 245 } else if (name.startsWith(PORTLET_SCOPE)) { 246 this.session.removeAttribute(name.substring(PORTLET_SCOPE.length()), 247 javax.portlet.PortletSession.PORTLET_SCOPE); 248 } else { 249 this.session.removeAttribute(name, this.scope); 250 } 251 } 252 253 259 public void invalidate() { 260 this.session.invalidate(); 261 } 262 263 277 public boolean isNew() { 278 return this.session.isNew(); 279 } 280 } 281 | Popular Tags |