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  
16  import java.io.File;
17  
18  import org.apache.catalina.Context;
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  
24  import psiprobe.Utils;
25  import psiprobe.controllers.AbstractContextHandlerController;
26  
27  /**
28   * The Class DownloadServletController.
29   */
30  @Controller
31  public class DownloadServletController extends AbstractContextHandlerController {
32  
33    @RequestMapping(path = "/app/downloadserv.htm")
34    @Override
35    public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
36        throws Exception {
37      return super.handleRequest(request, response);
38    }
39  
40    @Override
41    protected ModelAndView handleContext(String contextName, Context context,
42        HttpServletRequest request, HttpServletResponse response) throws Exception {
43  
44      String jspName = ServletRequestUtils.getStringParameter(request, "source");
45  
46      if (jspName != null) {
47        String servletName =
48            getContainerWrapper().getTomcatContainer().getServletFileNameForJsp(context, jspName);
49        if (servletName != null) {
50          File servletFile = new File(servletName);
51          if (servletFile.exists()) {
52            Utils.sendFile(request, response, servletFile);
53          }
54        }
55      }
56      return null;
57    }
58  
59  }