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.logs;
12  
13  import jakarta.inject.Inject;
14  import jakarta.servlet.http.HttpServletRequest;
15  import jakarta.servlet.http.HttpServletResponse;
16  
17  import java.util.List;
18  
19  import org.springframework.beans.factory.annotation.Value;
20  import org.springframework.stereotype.Controller;
21  import org.springframework.web.bind.ServletRequestUtils;
22  import org.springframework.web.bind.annotation.RequestMapping;
23  import org.springframework.web.servlet.ModelAndView;
24  import org.springframework.web.servlet.mvc.ParameterizableViewController;
25  
26  import psiprobe.beans.LogResolverBean;
27  import psiprobe.tools.logging.LogDestination;
28  
29  /**
30   * The Class ListLogsController.
31   */
32  @Controller
33  public class ListLogsController extends ParameterizableViewController {
34  
35    /** The error view. */
36    private String errorView;
37  
38    /** The log resolver. */
39    @Inject
40    private LogResolverBean logResolver;
41  
42    /**
43     * Gets the error view.
44     *
45     * @return the error view
46     */
47    public String getErrorView() {
48      return errorView;
49    }
50  
51    /**
52     * Sets the error view.
53     *
54     * @param errorView the new error view
55     */
56    @Value("logs_notsupported")
57    public void setErrorView(String errorView) {
58      this.errorView = errorView;
59    }
60  
61    /**
62     * Gets the log resolver.
63     *
64     * @return the log resolver
65     */
66    public LogResolverBean getLogResolver() {
67      return logResolver;
68    }
69  
70    /**
71     * Sets the log resolver.
72     *
73     * @param logResolver the new log resolver
74     */
75    public void setLogResolver(LogResolverBean logResolver) {
76      this.logResolver = logResolver;
77    }
78  
79    @RequestMapping(path = {"/logs", "/list.htm"})
80    @Override
81    public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
82        throws Exception {
83      return super.handleRequest(request, response);
84    }
85  
86    @Override
87    protected ModelAndView handleRequestInternal(HttpServletRequest request,
88        HttpServletResponse response) throws Exception {
89  
90      boolean showAll = ServletRequestUtils.getBooleanParameter(request, "apps", false);
91      List<LogDestination> uniqueList = logResolver.getLogDestinations(showAll);
92      if (!uniqueList.isEmpty()) {
93        return new ModelAndView(getViewName()).addObject("logs", uniqueList);
94      }
95      return new ModelAndView(errorView);
96    }
97  
98    @Value("logs")
99    @Override
100   public void setViewName(String viewName) {
101     super.setViewName(viewName);
102   }
103 
104 }