1
2
3
4
5
6
7
8
9
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 java.util.ArrayList;
18 import java.util.Collections;
19 import java.util.List;
20
21 import org.apache.catalina.Context;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
24 import org.springframework.beans.factory.annotation.Value;
25 import org.springframework.stereotype.Controller;
26 import org.springframework.web.bind.ServletRequestUtils;
27 import org.springframework.web.bind.annotation.RequestMapping;
28 import org.springframework.web.servlet.ModelAndView;
29 import org.springframework.web.servlet.view.RedirectView;
30
31 import psiprobe.controllers.AbstractContextHandlerController;
32 import psiprobe.model.jsp.Summary;
33
34
35
36
37 @Controller
38 public class RecompileJspController extends AbstractContextHandlerController {
39
40
41 private static final Logger logger = LoggerFactory.getLogger(RecompileJspController.class);
42
43 @RequestMapping(path = "/app/recompile.htm")
44 @Override
45 public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
46 throws Exception {
47 return super.handleRequest(request, response);
48 }
49
50 @Override
51 protected ModelAndView handleContext(String contextName, Context context,
52 HttpServletRequest request, HttpServletResponse response) throws Exception {
53
54 HttpSession session = request.getSession(false);
55 Summary summary = (Summary) session.getAttribute(DisplayJspController.SUMMARY_ATTRIBUTE);
56
57 if (summary != null && "post".equalsIgnoreCase(request.getMethod())) {
58 List<String> names = new ArrayList<>();
59 for (String name : Collections.list(request.getParameterNames())) {
60 if ("on".equals(request.getParameter(name))) {
61 names.add(name);
62 }
63 }
64 getContainerWrapper().getTomcatContainer().recompileJsps(context, summary, names);
65 request.getSession(false).setAttribute(DisplayJspController.SUMMARY_ATTRIBUTE, summary);
66 } else if (summary != null && contextName.equals(summary.getName())) {
67 String name = ServletRequestUtils.getStringParameter(request, "source");
68 if (name != null) {
69 List<String> names = new ArrayList<>();
70 names.add(name);
71 getContainerWrapper().getTomcatContainer().recompileJsps(context, summary, names);
72 request.getSession(false).setAttribute(DisplayJspController.SUMMARY_ATTRIBUTE, summary);
73 } else {
74 logger.error("source is not passed, nothing to do");
75 }
76 }
77 return new ModelAndView(new RedirectView(request.getContextPath()
78 + ServletRequestUtils.getStringParameter(request, "view", getViewName()) + "?"
79 + request.getQueryString()));
80 }
81
82 @Value("/app/jsp.htm")
83 @Override
84 public void setViewName(String viewName) {
85 super.setViewName(viewName);
86 }
87
88 }