View Javadoc
1   /*
2    * Licensed under the GPL License. You may not use this file except in compliance with the License.
3    * You may obtain a copy of the License at
4    *
5    *   https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
6    *
7    * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
8    * WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
9    * PURPOSE.
10   */
11  package psiprobe.controllers.jsp;
12  
13  import javax.servlet.http.HttpServletRequest;
14  import javax.servlet.http.HttpServletResponse;
15  import javax.servlet.http.HttpSession;
16  
17  import org.apache.catalina.Context;
18  import org.springframework.beans.factory.annotation.Value;
19  import org.springframework.stereotype.Controller;
20  import org.springframework.web.bind.ServletRequestUtils;
21  import org.springframework.web.bind.annotation.RequestMapping;
22  import org.springframework.web.servlet.ModelAndView;
23  import org.springframework.web.servlet.view.RedirectView;
24  
25  import psiprobe.controllers.AbstractContextHandlerController;
26  import psiprobe.model.jsp.Summary;
27  
28  /**
29   * The Class DisplayJspController.
30   */
31  @Controller
32  public class DisplayJspController extends AbstractContextHandlerController {
33  
34    /** The Constant SUMMARY_ATTRIBUTE. */
35    public static final String SUMMARY_ATTRIBUTE = "jsp.summary";
36  
37    @RequestMapping(path = "/app/jsp.htm")
38    @Override
39    public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
40        throws Exception {
41      return super.handleRequest(request, response);
42    }
43  
44    @Override
45    protected ModelAndView handleContext(String contextName, Context context,
46        HttpServletRequest request, HttpServletResponse response) throws Exception {
47      boolean compile = ServletRequestUtils.getBooleanParameter(request, "compile", false);
48  
49      HttpSession session = request.getSession(false);
50      Summary summary = (Summary) session.getAttribute(SUMMARY_ATTRIBUTE);
51      if (summary == null || !contextName.equals(summary.getName())) {
52        summary = new Summary();
53        summary.setName(contextName);
54      }
55      getContainerWrapper().getTomcatContainer().listContextJsps(context, summary, compile);
56  
57      request.getSession(false).setAttribute(SUMMARY_ATTRIBUTE, summary);
58  
59      if (compile) {
60        return new ModelAndView(new RedirectView(
61            request.getRequestURI() + "?webapp=" + (contextName.length() == 0 ? "/" : contextName)));
62      }
63      return new ModelAndView(getViewName(), "summary", summary);
64    }
65  
66    @Value("showjsps")
67    @Override
68    public void setViewName(String viewName) {
69      super.setViewName(viewName);
70    }
71  
72  }