001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
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 void addInitParameter(String name, String value) {
049                    _parameters.put(name, value);
050            }
051    
052            @Override
053            public String getFilterName() {
054                    return _filterName;
055            }
056    
057            @Override
058            public String getInitParameter(String name) {
059                    return _parameters.get(name);
060            }
061    
062            @Override
063            public Enumeration<String> getInitParameterNames() {
064                    return Collections.enumeration(_parameters.keySet());
065            }
066    
067            @Override
068            public ServletContext getServletContext() {
069                    return _servletContext;
070            }
071    
072            private String _filterName;
073            private Map<String, String> _parameters =
074                    new LinkedHashMap<String, String>();
075            private ServletContext _servletContext;
076    
077    }