View Javadoc

1   /*
2    * Copyright 2004-2005 The Apache Software Foundation.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License")
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.apache.commons.configuration.web;
18  
19  import java.util.Iterator;
20  import java.util.List;
21  import javax.servlet.FilterConfig;
22  
23  import org.apache.commons.collections.iterators.EnumerationIterator;
24  import org.apache.commons.configuration.PropertyConverter;
25  
26  /***
27   * A configuration wrapper around a {@link FilterConfig}. This configuration is
28   * read only, adding or removing a property will throw an
29   * UnsupportedOperationException.
30   *
31   * @author <a href="mailto:ebourg@apache.org">Emmanuel Bourg</a>
32   * @version $Revision$, $Date: 2005-10-12 21:01:43 +0200 (Wed, 12 Oct 2005) $
33   * @since 1.1
34   */
35  public class ServletFilterConfiguration extends BaseWebConfiguration
36  {
37      /*** Stores the wrapped filter config.*/
38      protected FilterConfig config;
39  
40      /***
41       * Create a ServletFilterConfiguration using the filter initialization parameters.
42       *
43       * @param config the filter configuration
44       */
45      public ServletFilterConfiguration(FilterConfig config)
46      {
47          this.config = config;
48      }
49  
50      public Object getProperty(String key)
51      {
52          Object value = config.getInitParameter(key);
53          List list = PropertyConverter.split((String) value, getDelimiter());
54  
55          return list.size() > 1 ? list : value;
56      }
57  
58      public Iterator getKeys()
59      {
60          return new EnumerationIterator(config.getInitParameterNames());
61      }
62  }