001/* 002 * Copyright 2012 Anyware Services 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.ametys.core.servletwrapper.filter; 017 018import java.util.Enumeration; 019import java.util.Iterator; 020import java.util.Map; 021 022import javax.servlet.FilterConfig; 023import javax.servlet.ServletContext; 024 025/** 026 * The runtime filter configuration based on configuration parameters 027 */ 028public class ServletFilterWrapperConfig implements FilterConfig 029{ 030 private Map<String, String> _parameters; 031 032 private ServletContext _servletContext; 033 034 /** 035 * Creates a generic filter 036 * @param map A hashmap of parameters 037 * @param servlet A reference to the servlet context 038 * */ 039 public ServletFilterWrapperConfig(ServletContext servlet, Map<String, String> map) 040 { 041 _parameters = map; 042 _servletContext = servlet; 043 } 044 045 /** 046 * Gets the servlet context 047 */ 048 public ServletContext getServletContext() 049 { 050 return _servletContext; 051 } 052 053 /** 054 * Gets the filter name 055 */ 056 public String getFilterName() 057 { 058 return "ServletFilterWrapper"; 059 } 060 061 public String getInitParameter(String name) 062 { 063 return _parameters.get(name); 064 } 065 066 public Enumeration<String> getInitParameterNames() 067 { 068 return new IteratorEnumeration(_parameters.keySet().iterator()); 069 } 070 071 /** 072 * An enumeration based on an iterator 073 */ 074 public class IteratorEnumeration implements Enumeration<String> 075 { 076 private Iterator<String> _it; 077 078 /** 079 * Create an enumeration from an iterator 080 * @param it The iterator to enumerate 081 */ 082 public IteratorEnumeration (Iterator<String> it) 083 { 084 _it = it; 085 } 086 087 public boolean hasMoreElements() 088 { 089 return _it.hasNext(); 090 } 091 092 public String nextElement() 093 { 094 return _it.next(); 095 } 096 } 097}