001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.util.servlet.filters;
016    
017    import java.util.Collections;
018    import java.util.Enumeration;
019    import java.util.LinkedHashMap;
020    import java.util.Map;
021    
022    import javax.servlet.FilterConfig;
023    import javax.servlet.ServletContext;
024    
025    /**
026     * @author Brian Wing Shun Chan
027     * @author Bruno Farache
028     */
029    public class DynamicFilterConfig implements FilterConfig {
030    
031            public DynamicFilterConfig(FilterConfig filterConfig) {
032                    Enumeration<String> enu = filterConfig.getInitParameterNames();
033    
034                    while (enu.hasMoreElements()) {
035                            String name = enu.nextElement();
036    
037                            addInitParameter(name, filterConfig.getInitParameter(name));
038                    }
039            }
040    
041            public DynamicFilterConfig(
042                    String filterName, ServletContext servletContext) {
043    
044                    _filterName = filterName;
045                    _servletContext = servletContext;
046            }
047    
048            public String getFilterName() {
049                    return _filterName;
050            }
051    
052            public ServletContext getServletContext() {
053                    return _servletContext;
054            }
055    
056            public void addInitParameter(String name, String value) {
057                    _parameters.put(name, value);
058            }
059    
060            public String getInitParameter(String name) {
061                    return _parameters.get(name);
062            }
063    
064            public Enumeration<String> getInitParameterNames() {
065                    return Collections.enumeration(_parameters.keySet());
066            }
067    
068            private String _filterName;
069            private ServletContext _servletContext;
070            private Map<String, String> _parameters =
071                    new LinkedHashMap<String, String>();
072    
073    }