|
|||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
FilterConfigWrapper.java | 0% | 0% | 0% | 0% |
|
1 |
/*
|
|
2 |
* ====================================================================
|
|
3 |
*
|
|
4 |
* The Apache Software License, Version 1.1
|
|
5 |
*
|
|
6 |
* Copyright (c) 2001-2003 The Apache Software Foundation. All rights
|
|
7 |
* reserved.
|
|
8 |
*
|
|
9 |
* Redistribution and use in source and binary forms, with or without
|
|
10 |
* modification, are permitted provided that the following conditions
|
|
11 |
* are met:
|
|
12 |
*
|
|
13 |
* 1. Redistributions of source code must retain the above copyright
|
|
14 |
* notice, this list of conditions and the following disclaimer.
|
|
15 |
*
|
|
16 |
* 2. Redistributions in binary form must reproduce the above copyright
|
|
17 |
* notice, this list of conditions and the following disclaimer in
|
|
18 |
* the documentation and/or other materials provided with the
|
|
19 |
* distribution.
|
|
20 |
*
|
|
21 |
* 3. The end-user documentation included with the redistribution, if
|
|
22 |
* any, must include the following acknowlegement:
|
|
23 |
* "This product includes software developed by the
|
|
24 |
* Apache Software Foundation (http://www.apache.org/)."
|
|
25 |
* Alternately, this acknowlegement may appear in the software itself,
|
|
26 |
* if and wherever such third-party acknowlegements normally appear.
|
|
27 |
*
|
|
28 |
* 4. The names "The Jakarta Project", "Cactus" and "Apache Software
|
|
29 |
* Foundation" must not be used to endorse or promote products
|
|
30 |
* derived from this software without prior written permission. For
|
|
31 |
* written permission, please contact apache@apache.org.
|
|
32 |
*
|
|
33 |
* 5. Products derived from this software may not be called "Apache"
|
|
34 |
* nor may "Apache" appear in their names without prior written
|
|
35 |
* permission of the Apache Group.
|
|
36 |
*
|
|
37 |
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
|
|
38 |
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
39 |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
40 |
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
|
|
41 |
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
42 |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
43 |
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
|
44 |
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
45 |
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
46 |
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
|
47 |
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
48 |
* SUCH DAMAGE.
|
|
49 |
* ====================================================================
|
|
50 |
*
|
|
51 |
* This software consists of voluntary contributions made by many
|
|
52 |
* individuals on behalf of the Apache Software Foundation. For more
|
|
53 |
* information on the Apache Software Foundation, please see
|
|
54 |
* <http://www.apache.org/>.
|
|
55 |
*
|
|
56 |
*/
|
|
57 |
package org.apache.cactus.server;
|
|
58 |
|
|
59 |
import java.util.Enumeration;
|
|
60 |
import java.util.Hashtable;
|
|
61 |
import java.util.Vector;
|
|
62 |
|
|
63 |
import javax.servlet.FilterConfig;
|
|
64 |
import javax.servlet.ServletContext;
|
|
65 |
|
|
66 |
/**
|
|
67 |
* Wrapper around <code>FilterConfig</code> which overrides the
|
|
68 |
* <code>getServletContext()</code> method to return our own wrapper around
|
|
69 |
* <code>ServletContext</code>.
|
|
70 |
*
|
|
71 |
* @author <a href="mailto:vmassol@apache.org">Vincent Massol</a>
|
|
72 |
*
|
|
73 |
* @version $Id: FilterConfigWrapper.java,v 1.7 2003/05/26 11:43:46 cmlenz Exp $
|
|
74 |
* @see ServletContext
|
|
75 |
*/
|
|
76 |
public class FilterConfigWrapper implements FilterConfig |
|
77 |
{ |
|
78 |
/**
|
|
79 |
* The original filter config object
|
|
80 |
*/
|
|
81 |
private FilterConfig originalConfig;
|
|
82 |
|
|
83 |
/**
|
|
84 |
* List of parameters set using the <code>setInitParameter()</code> method.
|
|
85 |
*/
|
|
86 |
private Hashtable initParameters;
|
|
87 |
|
|
88 |
/**
|
|
89 |
* Simulated name of the filter
|
|
90 |
*/
|
|
91 |
private String filterName;
|
|
92 |
|
|
93 |
/**
|
|
94 |
* @param theOriginalConfig the original filter config object
|
|
95 |
*/
|
|
96 | 0 |
public FilterConfigWrapper(FilterConfig theOriginalConfig)
|
97 |
{ |
|
98 | 0 |
this.originalConfig = theOriginalConfig;
|
99 | 0 |
this.initParameters = new Hashtable(); |
100 |
} |
|
101 |
|
|
102 |
/**
|
|
103 |
* Sets a parameter as if it were set in the <code>web.xml</code> file.
|
|
104 |
*
|
|
105 |
* @param theName the parameter's name
|
|
106 |
* @param theValue the parameter's value
|
|
107 |
*/
|
|
108 | 0 |
public void setInitParameter(String theName, String theValue) |
109 |
{ |
|
110 | 0 |
this.initParameters.put(theName, theValue);
|
111 |
} |
|
112 |
|
|
113 |
/**
|
|
114 |
* Sets the filter name. That will be the value returned by the
|
|
115 |
* <code>getFilterName()</code> method.
|
|
116 |
*
|
|
117 |
* @param theFilterName the filter name
|
|
118 |
*/
|
|
119 | 0 |
public void setFilterName(String theFilterName) |
120 |
{ |
|
121 | 0 |
this.filterName = theFilterName;
|
122 |
} |
|
123 |
|
|
124 |
//--Overridden methods ----------------------------------------------------
|
|
125 |
|
|
126 |
/**
|
|
127 |
* @return the simulated filter's name if defined or the redirector
|
|
128 |
* filter's name
|
|
129 |
*/
|
|
130 | 0 |
public String getFilterName()
|
131 |
{ |
|
132 | 0 |
if (this.filterName != null) |
133 |
{ |
|
134 | 0 |
return this.filterName; |
135 |
} |
|
136 |
|
|
137 | 0 |
return this.originalConfig.getFilterName(); |
138 |
} |
|
139 |
|
|
140 |
/**
|
|
141 |
* @return our own wrapped servlet context object
|
|
142 |
*/
|
|
143 | 0 |
public ServletContext getServletContext()
|
144 |
{ |
|
145 | 0 |
return new ServletContextWrapper( |
146 |
this.originalConfig.getServletContext());
|
|
147 |
} |
|
148 |
|
|
149 |
/**
|
|
150 |
* Return the union of the parameters defined in the Redirector
|
|
151 |
* <code>web.xml</code> file and the one set using the
|
|
152 |
* <code>setInitParameter()</code> method. The parameters with the same
|
|
153 |
* name (and same case) are only returned once.
|
|
154 |
*
|
|
155 |
* @return the init parameters
|
|
156 |
*/
|
|
157 | 0 |
public Enumeration getInitParameterNames()
|
158 |
{ |
|
159 | 0 |
Vector names = new Vector();
|
160 |
|
|
161 |
// Add parameters that were added using setInitParameter()
|
|
162 | 0 |
Enumeration enum = this.initParameters.keys();
|
163 |
|
|
164 | 0 |
while (enum.hasMoreElements())
|
165 |
{ |
|
166 | 0 |
String value = (String) enum.nextElement(); |
167 |
|
|
168 | 0 |
names.add(value); |
169 |
} |
|
170 |
|
|
171 |
// Add parameters from web.xml
|
|
172 | 0 |
enum = this.originalConfig.getInitParameterNames();
|
173 |
|
|
174 | 0 |
while (enum.hasMoreElements())
|
175 |
{ |
|
176 | 0 |
String value = (String) enum.nextElement(); |
177 |
|
|
178 | 0 |
if (!names.contains(value))
|
179 |
{ |
|
180 | 0 |
names.add(value); |
181 |
} |
|
182 |
} |
|
183 |
|
|
184 | 0 |
return names.elements();
|
185 |
} |
|
186 |
|
|
187 |
/**
|
|
188 |
* @param theName the name of the parameter's value to return
|
|
189 |
* @return the value of the parameter, looking for it first in the list of
|
|
190 |
* parameters set using the <code>setInitParameter()</code> method
|
|
191 |
* and then in those set in <code>web.xml</code>.
|
|
192 |
*/
|
|
193 | 0 |
public String getInitParameter(String theName)
|
194 |
{ |
|
195 |
// Look first in the list of parameters set using the
|
|
196 |
// setInitParameter() method.
|
|
197 | 0 |
String value = (String) this.initParameters.get(theName);
|
198 |
|
|
199 | 0 |
if (value == null) |
200 |
{ |
|
201 | 0 |
value = this.originalConfig.getInitParameter(theName);
|
202 |
} |
|
203 |
|
|
204 | 0 |
return value;
|
205 |
} |
|
206 |
} |
|
207 |
|
|