1 48 49 package org.jpublish.servlet; 50 51 import java.util.Enumeration ; 52 import java.util.Vector ; 53 54 import javax.servlet.ServletContext ; 55 import javax.servlet.http.HttpServletRequest ; 56 import javax.servlet.http.HttpSession ; 57 import javax.servlet.http.HttpSessionContext ; 58 59 65 66 public class HttpSessionFacade implements HttpSession { 67 68 private static final Vector EMPTY_VECTOR = new Vector (); 69 70 private HttpServletRequest request = null; 71 72 75 76 public HttpSessionFacade(HttpServletRequest request) { 77 this.request = request; 78 } 79 80 87 88 public long getCreationTime() { 89 HttpSession session = request.getSession(false); 90 if (session != null) { 91 return session.getCreationTime(); 92 } else { 93 return -1; 94 } 95 } 96 97 104 105 public String getId() { 106 HttpSession session = request.getSession(false); 107 if (session != null) { 108 return session.getId(); 109 } else { 110 return null; 111 } 112 } 113 114 122 123 public long getLastAccessedTime() { 124 HttpSession session = request.getSession(false); 125 if (session != null) { 126 return session.getLastAccessedTime(); 127 } else { 128 return -1; 129 } 130 } 131 132 137 138 public ServletContext getServletContext() { 139 return request.getSession().getServletContext(); 140 } 141 142 147 148 public int getMaxInactiveInterval() { 149 return request.getSession().getMaxInactiveInterval(); 150 } 151 152 157 158 public void setMaxInactiveInterval(int maxInactiveInterval) { 159 request.getSession().setMaxInactiveInterval(maxInactiveInterval); 160 } 161 162 167 168 public HttpSessionContext getSessionContext() { 169 return request.getSession().getSessionContext(); 170 } 171 172 182 183 public Object getAttribute(String name) { 184 HttpSession session = request.getSession(false); 185 if (session == null) { 186 return null; 187 } else { 188 return session.getAttribute(name); 189 } 190 } 191 192 199 200 public void setAttribute(String name, Object value) { 201 request.getSession().setAttribute(name, value); 202 } 203 204 214 215 public void removeAttribute(String name) { 216 HttpSession session = request.getSession(false); 217 if (session != null) { 218 session.removeAttribute(name); 219 } 220 } 221 222 231 232 public Enumeration getAttributeNames() { 233 HttpSession session = request.getSession(false); 234 if (session == null) { 235 return EMPTY_VECTOR.elements(); 236 } else { 237 return session.getAttributeNames(); 238 } 239 } 240 241 246 247 public Object getValue(String name) { 248 return getAttribute(name); 249 } 250 251 256 257 public void putValue(String name, Object value) { 258 setAttribute(name, value); 259 } 260 261 266 267 public void removeValue(String name) { 268 removeAttribute(name); 269 } 270 271 276 277 public String [] getValueNames() { 278 HttpSession session = request.getSession(false); 279 if (session == null) { 280 return new String [0]; 281 } else { 282 return session.getValueNames(); 283 } 284 } 285 286 289 290 public void invalidate() { 291 request.getSession().invalidate(); 292 } 293 294 301 302 public boolean isNew() { 303 return request.getSession().isNew(); 304 } 305 306 } 307 | Popular Tags |