View Javadoc

1   package org.appfuse.webapp.controller;
2   
3   import org.apache.commons.logging.Log;
4   import org.apache.commons.logging.LogFactory;
5   import org.appfuse.webapp.listener.StartupListener;
6   import org.springframework.stereotype.Controller;
7   import org.springframework.web.bind.annotation.RequestMapping;
8   import org.springframework.web.bind.annotation.RequestMethod;
9   import org.springframework.web.servlet.ModelAndView;
10  
11  import javax.servlet.http.HttpServletRequest;
12  import javax.servlet.http.HttpServletResponse;
13  import java.io.PrintWriter;
14  import java.util.ArrayList;
15  import java.util.List;
16  
17  
18  /**
19   * This class is used to reload the drop-downs initialized in the
20   * StartupListener.
21   *
22   * <p>
23   * <a href="ReloadController.java.html"><i>View Source</i></a>
24   * </p>
25   *
26   * @author <a href="mailto:matt@raibledesigns.com">Matt Raible</a>
27   */
28  @Controller
29  @RequestMapping("/admin/reload*")
30  public class ReloadController {
31      private transient final Log log = LogFactory.getLog(ReloadController.class);
32  
33      @RequestMapping(method = RequestMethod.GET)
34      @SuppressWarnings("unchecked")
35      public ModelAndView handleRequest(HttpServletRequest request,
36                                        HttpServletResponse response)
37      throws Exception {
38          if (log.isDebugEnabled()) {
39              log.debug("Entering 'execute' method");
40          }
41  
42          StartupListener.setupContext(request.getSession().getServletContext());
43  
44          String referer = request.getHeader("Referer");
45  
46          if (referer != null) {
47              log.info("reload complete, reloading user back to: " + referer);
48              List<String> messages = (List) request.getSession().getAttribute(BaseFormController.MESSAGES_KEY);
49  
50              if (messages == null) {
51                  messages = new ArrayList();
52              }
53  
54              messages.add("Reloading options completed successfully.");
55              request.getSession().setAttribute(BaseFormController.MESSAGES_KEY, messages);
56  
57              response.sendRedirect(response.encodeRedirectURL(referer));
58              return null;
59          } else {
60              response.setContentType("text/html");
61  
62              PrintWriter out = response.getWriter();
63  
64              out.println("<html>");
65              out.println("<head>");
66              out.println("<title>Context Reloaded</title>");
67              out.println("</head>");
68              out.println("<body bgcolor=\"white\">");
69              out.println("<script type=\"text/javascript\">");
70              out.println("alert('Context Reload Succeeded! Click OK to continue.');");
71              out.println("history.back();");
72              out.println("</script>");
73              out.println("</body>");
74              out.println("</html>");
75          }
76  
77          return null;
78      }
79      
80  }