1 /**
2 * Waffle (https://github.com/dblock/waffle)
3 *
4 * Copyright (c) 2010 - 2015 Application Security, Inc.
5 *
6 * All rights reserved. This program and the accompanying materials
7 * are made available under the terms of the Eclipse Public License v1.0
8 * which accompanies this distribution, and is available at
9 * http://www.eclipse.org/legal/epl-v10.html
10 *
11 * Contributors:
12 * Application Security, Inc.
13 */
14 package waffle.mock.http;
15
16 import java.util.ArrayList;
17 import java.util.Collections;
18 import java.util.Enumeration;
19 import java.util.List;
20 import java.util.Map;
21 import java.util.TreeMap;
22
23 import javax.servlet.FilterConfig;
24 import javax.servlet.ServletContext;
25
26 /**
27 * The Class SimpleFilterConfig.
28 *
29 * @author dblock[at]dblock[dot]org
30 */
31 public class SimpleFilterConfig implements FilterConfig {
32
33 /** The filter name. */
34 private String filterName = "Simple Filter";
35
36 /** The parameters. */
37 private final Map<String, String> parameters = new TreeMap<String, String>();
38
39 /* (non-Javadoc)
40 * @see javax.servlet.FilterConfig#getFilterName()
41 */
42 @Override
43 public String getFilterName() {
44 return this.filterName;
45 }
46
47 /**
48 * Sets the filter name.
49 *
50 * @param value
51 * the new filter name
52 */
53 public void setFilterName(final String value) {
54 this.filterName = value;
55 }
56
57 /* (non-Javadoc)
58 * @see javax.servlet.FilterConfig#getInitParameter(java.lang.String)
59 */
60 @Override
61 public String getInitParameter(final String s) {
62 return this.parameters.get(s);
63 }
64
65 /* (non-Javadoc)
66 * @see javax.servlet.FilterConfig#getInitParameterNames()
67 */
68 @Override
69 public Enumeration<String> getInitParameterNames() {
70 final List<String> keys = new ArrayList<String>();
71 keys.addAll(this.parameters.keySet());
72 return Collections.enumeration(keys);
73 }
74
75 /* (non-Javadoc)
76 * @see javax.servlet.FilterConfig#getServletContext()
77 */
78 @Override
79 public ServletContext getServletContext() {
80 return null;
81 }
82
83 /**
84 * Sets the parameter.
85 *
86 * @param parameterName
87 * the parameter name
88 * @param parameterValue
89 * the parameter value
90 */
91 public void setParameter(final String parameterName, final String parameterValue) {
92 this.parameters.put(parameterName, parameterValue);
93 }
94 }