View Javadoc

1   package org.paneris.util;
2   
3   import org.webmacro.servlet.WebContext;
4   import javax.servlet.http.HttpSession;
5   
6   /**
7    * Session Utility.
8    */
9   public class SessionUtil {
10  
11   /**
12    * Setup the url to return to.
13    */
14    public static synchronized void setReturnURL
15                                      (String name, WebContext context) {
16      HttpSession session = context.getSession();
17      // if we are being forced to record the return URL, save it away
18      if (context.getForm("return") != null) {
19        if (context.getCGI().getHTTP_REFERER() != null) 
20          context.getSession().setAttribute("LoginUserReturnURL", 
21                                        context.getCGI().getHTTP_REFERER());
22      }
23      // if we have explicitly been given a return url, set it
24      if (context.get(name) != null) 
25        session.setAttribute(name, (String) context.get(name));
26      if (context.getForm(name) != null) 
27        session.setAttribute(name, (String) context.getForm(name));
28      // otherwise we have somehow lost where we are going back to 
29      // - use the default home page
30      if (session.getAttribute(name) == null) {
31          session.setAttribute(name, "/");
32      }
33      System.err.println("Setting " + name + " to " + 
34                         session.getAttribute(name));
35      context.put(name, session.getAttribute(name));
36    }
37  }