PageRenderTime 24ms CodeModel.GetById 7ms app.highlight 13ms RepoModel.GetById 1ms app.codeStats 1ms

/plugin-module-codegen-engine/src/main/java/com/atlassian/plugins/codegen/modules/common/servlet/ServletFilterProperties.java

https://bitbucket.org/mmeinhold/amps
Java | 120 lines | 94 code | 22 blank | 4 comment | 4 complexity | 7077ed6534f21899309e53e039a7914b MD5 | raw file
  1package com.atlassian.plugins.codegen.modules.common.servlet;
  2
  3import java.util.*;
  4
  5import com.atlassian.plugins.codegen.modules.BasicClassModuleProperties;
  6
  7/**
  8 *
  9 */
 10public class ServletFilterProperties extends BasicClassModuleProperties
 11{
 12    public static final String LOCATION = "LOCATION";
 13    public static final String WEIGHT = "WEIGHT";
 14    public static final String URL_PATTERN = "URL_PATTERN";
 15    public static final String DISPATCHERS = "DISPATCHERS";
 16    public static final String INIT_PARAMS = "INIT_PARAMS";
 17
 18    public static final List<String> ALLOWED_LOCATIONS = initLocations();
 19    public static final List<String> ALLOWED_DISPATCHERS = initDispatchers();
 20
 21    private static List<String> initLocations()
 22    {
 23        List<String> locations = new ArrayList<String>(4);
 24        locations.add("after-encoding");
 25        locations.add("before-login");
 26        locations.add("before-decoration");
 27        locations.add("before-dispatch");
 28
 29        return Collections.unmodifiableList(locations);
 30    }
 31
 32    private static List<String> initDispatchers()
 33    {
 34        List<String> dispatchers = new ArrayList<String>(4);
 35        dispatchers.add("REQUEST");
 36        dispatchers.add("INCLUDE");
 37        dispatchers.add("FORWARD");
 38        dispatchers.add("ERROR");
 39
 40        return Collections.unmodifiableList(dispatchers);
 41    }
 42
 43    public ServletFilterProperties()
 44    {
 45        this("MyServletFilter");
 46    }
 47
 48    public ServletFilterProperties(String fqClassName)
 49    {
 50        super(fqClassName);
 51        put(DISPATCHERS, new ArrayList<String>());
 52        put(INIT_PARAMS, new HashMap<String, String>());
 53
 54        //sane defaults
 55        setUrlPattern("/*");
 56        setLocation(ALLOWED_LOCATIONS.get(3));
 57        setWeight(100);
 58    }
 59
 60    public void setLocation(String location)
 61    {
 62        setProperty(LOCATION, location);
 63    }
 64
 65    public void setWeight(int weight)
 66    {
 67        setProperty(WEIGHT, Integer.toString(weight));
 68    }
 69
 70    public void setUrlPattern(String pattern)
 71    {
 72        setProperty(URL_PATTERN, pattern);
 73    }
 74
 75    public void setDispatchers(List<String> dispatchers)
 76    {
 77        put(DISPATCHERS, dispatchers);
 78    }
 79
 80    @SuppressWarnings(value = "unchecked")
 81    public void addDispatcher(String dispatcher)
 82    {
 83        List<String> dispatchers = (List<String>) get(DISPATCHERS);
 84        if (dispatchers == null)
 85        {
 86            dispatchers = new ArrayList<String>();
 87            setDispatchers(dispatchers);
 88        }
 89
 90        dispatchers.add(dispatcher);
 91    }
 92
 93    public void setInitParams(Map<String, String> params)
 94    {
 95        put(INIT_PARAMS, params);
 96    }
 97
 98    @SuppressWarnings(value = "unchecked")
 99    public void addInitParam(String name, String value)
100    {
101        Map<String, String> params = (Map<String, String>) get(INIT_PARAMS);
102        if (params == null)
103        {
104            params = new HashMap<String, String>();
105            setInitParams(params);
106        }
107
108        params.put(name, value);
109    }
110
111    public List<String> allowedLocations()
112    {
113        return ALLOWED_LOCATIONS;
114    }
115
116    public List<String> allowedDispatchers()
117    {
118        return ALLOWED_DISPATCHERS;
119    }
120}