1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.util.servlet.filters;
16  
17  import java.util.Collections;
18  import java.util.Enumeration;
19  import java.util.LinkedHashMap;
20  import java.util.Map;
21  
22  import javax.servlet.FilterConfig;
23  import javax.servlet.ServletContext;
24  
25  /**
26   * <a href="DynamicFilterConfig.java.html"><b><i>View Source</i></b></a>
27   *
28   * @author Brian Wing Shun Chan
29   * @author Bruno Farache
30   */
31  public class DynamicFilterConfig implements FilterConfig {
32  
33      public DynamicFilterConfig(FilterConfig filterConfig) {
34          Enumeration<String> enu = filterConfig.getInitParameterNames();
35  
36          while (enu.hasMoreElements()) {
37              String name = enu.nextElement();
38  
39              addInitParameter(name, filterConfig.getInitParameter(name));
40          }
41      }
42  
43      public DynamicFilterConfig(
44          String filterName, ServletContext servletContext) {
45  
46          _filterName = filterName;
47          _servletContext = servletContext;
48      }
49  
50      public String getFilterName() {
51          return _filterName;
52      }
53  
54      public ServletContext getServletContext() {
55          return _servletContext;
56      }
57  
58      public void addInitParameter(String name, String value) {
59          _parameters.put(name, value);
60      }
61  
62      public String getInitParameter(String name) {
63          return _parameters.get(name);
64      }
65  
66      public Enumeration<String> getInitParameterNames() {
67          return Collections.enumeration(_parameters.keySet());
68      }
69  
70      private String _filterName;
71      private ServletContext _servletContext;
72      private Map<String, String> _parameters =
73          new LinkedHashMap<String, String>();
74  
75  }