View Javadoc
1   /*
2    * MIT License
3    *
4    * Copyright (c) 2010-2024 The Waffle Project Contributors: https://github.com/Waffle/waffle/graphs/contributors
5    *
6    * Permission is hereby granted, free of charge, to any person obtaining a copy
7    * of this software and associated documentation files (the "Software"), to deal
8    * in the Software without restriction, including without limitation the rights
9    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10   * copies of the Software, and to permit persons to whom the Software is
11   * furnished to do so, subject to the following conditions:
12   *
13   * The above copyright notice and this permission notice shall be included in all
14   * copies or substantial portions of the Software.
15   *
16   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22   * SOFTWARE.
23   */
24  package waffle.mock.http;
25  
26  import java.util.ArrayList;
27  import java.util.Collections;
28  import java.util.Enumeration;
29  import java.util.List;
30  import java.util.Map;
31  import java.util.TreeMap;
32  
33  import javax.servlet.FilterConfig;
34  import javax.servlet.ServletContext;
35  
36  /**
37   * The Class SimpleFilterConfig.
38   */
39  public class SimpleFilterConfig implements FilterConfig {
40  
41      /** The filter name. */
42      private String filterName = "Simple Filter";
43  
44      /** The parameters. */
45      private final Map<String, String> parameters = new TreeMap<>();
46  
47      @Override
48      public String getFilterName() {
49          return this.filterName;
50      }
51  
52      /**
53       * Sets the filter name.
54       *
55       * @param value
56       *            the new filter name
57       */
58      public void setFilterName(final String value) {
59          this.filterName = value;
60      }
61  
62      @Override
63      public String getInitParameter(final String s) {
64          return this.parameters.get(s);
65      }
66  
67      @Override
68      public Enumeration<String> getInitParameterNames() {
69          final List<String> keys = new ArrayList<>();
70          keys.addAll(this.parameters.keySet());
71          return Collections.enumeration(keys);
72      }
73  
74      @Override
75      public ServletContext getServletContext() {
76          return null;
77      }
78  
79      /**
80       * Sets the parameter.
81       *
82       * @param parameterName
83       *            the parameter name
84       * @param parameterValue
85       *            the parameter value
86       */
87      public void setParameter(final String parameterName, final String parameterValue) {
88          this.parameters.put(parameterName, parameterValue);
89      }
90  }