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.apps;
12  
13  import java.util.List;
14  
15  import javax.servlet.http.HttpServletRequest;
16  import javax.servlet.http.HttpServletResponse;
17  
18  import org.apache.catalina.Context;
19  import org.springframework.beans.factory.annotation.Value;
20  import org.springframework.stereotype.Controller;
21  import org.springframework.web.bind.annotation.RequestMapping;
22  import org.springframework.web.servlet.ModelAndView;
23  
24  import psiprobe.controllers.AbstractContextHandlerController;
25  import psiprobe.model.Attribute;
26  import psiprobe.tools.ApplicationUtils;
27  import psiprobe.tools.SecurityUtils;
28  
29  /**
30   * Retrieves a list of servlet context attributes for a web application.
31   */
32  @Controller
33  public class ListAppAttributesController extends AbstractContextHandlerController {
34  
35    @RequestMapping(path = "/appattributes.htm")
36    @Override
37    public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
38        throws Exception {
39      return super.handleRequest(request, response);
40    }
41  
42    @Override
43    protected ModelAndView handleContext(String contextName, Context context,
44        HttpServletRequest request, HttpServletResponse response) throws Exception {
45  
46      List<Attribute> appAttrs = ApplicationUtils.getApplicationAttributes(context);
47      ModelAndView mv = new ModelAndView(getViewName(), "appAttributes", appAttrs);
48  
49      if (SecurityUtils.hasAttributeValueRole(getServletContext())) {
50        mv.addObject("displayValues", Boolean.TRUE);
51      }
52      return mv;
53    }
54  
55    @Value("appattributes")
56    @Override
57    public void setViewName(String viewName) {
58      super.setViewName(viewName);
59    }
60  
61  }