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 jakarta.servlet.http.HttpServletRequest;
14  import jakarta.servlet.http.HttpServletResponse;
15  import jakarta.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  
51      Summary summary = (Summary) session.getAttribute(SUMMARY_ATTRIBUTE);
52      if (summary == null || !contextName.equals(summary.getName())) {
53        summary = new Summary();
54        summary.setName(contextName);
55      }
56      containerWrapper.getTomcatContainer().listContextJsps(context, summary, compile);
57  
58      session.setAttribute(SUMMARY_ATTRIBUTE, summary);
59  
60      if (compile) {
61        return new ModelAndView(new RedirectView(
62            request.getRequestURI() + "?webapp=" + (contextName.isEmpty() ? "/" : contextName)));
63      }
64      return new ModelAndView(getViewName(), "summary", summary);
65    }
66  
67    @Value("showjsps")
68    @Override
69    public void setViewName(String viewName) {
70      super.setViewName(viewName);
71    }
72  
73  }