001    /**
002     * Copyright (c) 2000-2013 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 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    }