1 package org.roller.presentation; 2 3 import org.apache.commons.collections.ArrayStack; 4 import org.apache.commons.logging.Log; 5 import org.apache.commons.logging.LogFactory; 6 7 import javax.servlet.http.HttpServletRequest ; 8 import javax.servlet.http.HttpSession ; 9 import javax.servlet.http.HttpSessionActivationListener ; 10 import javax.servlet.http.HttpSessionEvent ; 11 import javax.servlet.http.HttpSessionListener ; 12 import java.io.Serializable ; 13 14 15 20 public class RollerSession 21 implements HttpSessionListener , HttpSessionActivationListener , Serializable 22 { 23 static final long serialVersionUID = 5890132909166913727L; 26 27 private static Log mLogger = 28 LogFactory.getFactory().getInstance(RollerSession.class); 29 30 public static final String ROLLER_SESSION = "org.roller.rollersession"; 31 public static final String BREADCRUMB = "org.roller.breadcrumb"; 32 public static final String ERROR_MESSAGE = "rollererror_message"; 33 public static final String STATUS_MESSAGE = "rollerstatus_message"; 34 35 36 38 public void sessionCreated(HttpSessionEvent se) 39 { 40 se.getSession().setAttribute( ROLLER_SESSION, this ); 42 43 RollerContext rctx = RollerContext.getRollerContext( 44 se.getSession().getServletContext()); 45 rctx.sessionCreated(se); 46 } 47 48 public void sessionDestroyed(HttpSessionEvent se) 50 { 51 RollerContext rctx = RollerContext.getRollerContext( 52 se.getSession().getServletContext()); 53 rctx.sessionDestroyed(se); 54 55 clearSession(se); 56 } 57 58 60 public void sessionDidActivate(HttpSessionEvent se) 61 { 62 } 63 64 69 public static void clearBreadCrumbTrail( HttpServletRequest req ) 70 { 71 HttpSession ses = req.getSession(false); 72 if (ses != null && ses.getAttribute(BREADCRUMB) != null) 73 { 74 ArrayStack stack = (ArrayStack)ses.getAttribute(BREADCRUMB); 75 stack.clear(); 76 } 77 } 78 79 84 public static String getBreadCrumb( 85 HttpServletRequest req, boolean useReferer ) 86 { 87 String crumb = null; 88 89 HttpSession ses = req.getSession(false); 90 if (ses != null && ses.getAttribute(BREADCRUMB) != null) 91 { 92 ArrayStack stack = (ArrayStack) ses.getAttribute(BREADCRUMB); 93 if (stack != null && !stack.empty()) 94 { 95 crumb = (String )stack.peek(); 96 } 97 } 98 99 if ( crumb == null && useReferer ) 100 { 101 crumb = req.getHeader("referer"); 102 } 103 104 return crumb; 105 } 106 107 112 public static String getBreadCrumb( HttpServletRequest req ) 113 { 114 return getBreadCrumb(req,true); 115 } 116 117 123 public void sessionWillPassivate(HttpSessionEvent se) 124 { 125 clearSession(se); 126 } 127 128 private void clearSession( HttpSessionEvent se ) 130 { 131 HttpSession session = se.getSession(); 132 try 133 { 134 session.removeAttribute( BREADCRUMB ); 135 } 136 catch (Throwable e) 137 { 138 if (mLogger.isDebugEnabled()) 139 { 140 mLogger.debug("EXCEPTION PURGING session attributes",e); 142 } 143 } 144 } 145 } 146 147 | Popular Tags |