|
|||||||||||||||||||
| 30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| FilterConfigWrapper.java | 20% | 30.4% | 42.9% | 30% |
|
||||||||||||||
| 1 |
/*
|
|
| 2 |
* ========================================================================
|
|
| 3 |
*
|
|
| 4 |
* Copyright 2001-2003 The Apache Software Foundation.
|
|
| 5 |
*
|
|
| 6 |
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
| 7 |
* you may not use this file except in compliance with the License.
|
|
| 8 |
* You may obtain a copy of the License at
|
|
| 9 |
*
|
|
| 10 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
| 11 |
*
|
|
| 12 |
* Unless required by applicable law or agreed to in writing, software
|
|
| 13 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
| 14 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
| 15 |
* See the License for the specific language governing permissions and
|
|
| 16 |
* limitations under the License.
|
|
| 17 |
*
|
|
| 18 |
* ========================================================================
|
|
| 19 |
*/
|
|
| 20 |
package org.apache.cactus.server;
|
|
| 21 |
|
|
| 22 |
import java.util.Enumeration;
|
|
| 23 |
import java.util.Hashtable;
|
|
| 24 |
import java.util.Vector;
|
|
| 25 |
|
|
| 26 |
import javax.servlet.FilterConfig;
|
|
| 27 |
import javax.servlet.ServletContext;
|
|
| 28 |
|
|
| 29 |
/**
|
|
| 30 |
* Wrapper around <code>FilterConfig</code> which overrides the
|
|
| 31 |
* <code>getServletContext()</code> method to return our own wrapper around
|
|
| 32 |
* <code>ServletContext</code>.
|
|
| 33 |
*
|
|
| 34 |
* @version $Id: FilterConfigWrapper.java 239054 2004-10-24 01:30:23Z felipeal $
|
|
| 35 |
* @see ServletContext
|
|
| 36 |
*/
|
|
| 37 |
public class FilterConfigWrapper implements FilterConfig |
|
| 38 |
{
|
|
| 39 |
/**
|
|
| 40 |
* The original filter config object
|
|
| 41 |
*/
|
|
| 42 |
private FilterConfig originalConfig;
|
|
| 43 |
|
|
| 44 |
/**
|
|
| 45 |
* List of parameters set using the <code>setInitParameter()</code> method.
|
|
| 46 |
*/
|
|
| 47 |
private Hashtable initParameters;
|
|
| 48 |
|
|
| 49 |
/**
|
|
| 50 |
* Simulated name of the filter
|
|
| 51 |
*/
|
|
| 52 |
private String filterName;
|
|
| 53 |
|
|
| 54 |
/**
|
|
| 55 |
* @param theOriginalConfig the original filter config object
|
|
| 56 |
*/
|
|
| 57 | 5 |
public FilterConfigWrapper(FilterConfig theOriginalConfig)
|
| 58 |
{
|
|
| 59 | 5 |
this.originalConfig = theOriginalConfig;
|
| 60 | 5 |
this.initParameters = new Hashtable(); |
| 61 |
} |
|
| 62 |
|
|
| 63 |
/**
|
|
| 64 |
* Sets a parameter as if it were set in the <code>web.xml</code> file.
|
|
| 65 |
*
|
|
| 66 |
* @param theName the parameter's name
|
|
| 67 |
* @param theValue the parameter's value
|
|
| 68 |
*/
|
|
| 69 | 4 |
public void setInitParameter(String theName, String theValue) |
| 70 |
{
|
|
| 71 | 4 |
this.initParameters.put(theName, theValue);
|
| 72 |
} |
|
| 73 |
|
|
| 74 |
/**
|
|
| 75 |
* Sets the filter name. That will be the value returned by the
|
|
| 76 |
* <code>getFilterName()</code> method.
|
|
| 77 |
*
|
|
| 78 |
* @param theFilterName the filter name
|
|
| 79 |
*/
|
|
| 80 | 0 |
public void setFilterName(String theFilterName) |
| 81 |
{
|
|
| 82 | 0 |
this.filterName = theFilterName;
|
| 83 |
} |
|
| 84 |
|
|
| 85 |
//--Overridden methods ----------------------------------------------------
|
|
| 86 |
|
|
| 87 |
/**
|
|
| 88 |
* @return the simulated filter's name if defined or the redirector
|
|
| 89 |
* filter's name
|
|
| 90 |
*/
|
|
| 91 | 0 |
public String getFilterName()
|
| 92 |
{
|
|
| 93 | 0 |
if (this.filterName != null) |
| 94 |
{
|
|
| 95 | 0 |
return this.filterName; |
| 96 |
} |
|
| 97 |
|
|
| 98 | 0 |
return this.originalConfig.getFilterName(); |
| 99 |
} |
|
| 100 |
|
|
| 101 |
/**
|
|
| 102 |
* @return our own wrapped servlet context object
|
|
| 103 |
*/
|
|
| 104 | 0 |
public ServletContext getServletContext()
|
| 105 |
{
|
|
| 106 | 0 |
return new ServletContextWrapper( |
| 107 |
this.originalConfig.getServletContext());
|
|
| 108 |
} |
|
| 109 |
|
|
| 110 |
/**
|
|
| 111 |
* Return the union of the parameters defined in the Redirector
|
|
| 112 |
* <code>web.xml</code> file and the one set using the
|
|
| 113 |
* <code>setInitParameter()</code> method. The parameters with the same
|
|
| 114 |
* name (and same case) are only returned once.
|
|
| 115 |
*
|
|
| 116 |
* @return the init parameters
|
|
| 117 |
*/
|
|
| 118 | 0 |
public Enumeration getInitParameterNames()
|
| 119 |
{
|
|
| 120 | 0 |
Vector names = new Vector();
|
| 121 |
|
|
| 122 |
// Add parameters that were added using setInitParameter()
|
|
| 123 | 0 |
Enumeration en = this.initParameters.keys();
|
| 124 |
|
|
| 125 | 0 |
while (en.hasMoreElements())
|
| 126 |
{
|
|
| 127 | 0 |
String value = (String) en.nextElement(); |
| 128 |
|
|
| 129 | 0 |
names.add(value); |
| 130 |
} |
|
| 131 |
|
|
| 132 |
// Add parameters from web.xml
|
|
| 133 | 0 |
en = this.originalConfig.getInitParameterNames();
|
| 134 |
|
|
| 135 | 0 |
while (en.hasMoreElements())
|
| 136 |
{
|
|
| 137 | 0 |
String value = (String) en.nextElement(); |
| 138 |
|
|
| 139 | 0 |
if (!names.contains(value))
|
| 140 |
{
|
|
| 141 | 0 |
names.add(value); |
| 142 |
} |
|
| 143 |
} |
|
| 144 |
|
|
| 145 | 0 |
return names.elements();
|
| 146 |
} |
|
| 147 |
|
|
| 148 |
/**
|
|
| 149 |
* @param theName the name of the parameter's value to return
|
|
| 150 |
* @return the value of the parameter, looking for it first in the list of
|
|
| 151 |
* parameters set using the <code>setInitParameter()</code> method
|
|
| 152 |
* and then in those set in <code>web.xml</code>.
|
|
| 153 |
*/
|
|
| 154 | 6 |
public String getInitParameter(String theName)
|
| 155 |
{
|
|
| 156 |
// Look first in the list of parameters set using the
|
|
| 157 |
// setInitParameter() method.
|
|
| 158 | 6 |
String value = (String) this.initParameters.get(theName);
|
| 159 |
|
|
| 160 | 6 |
if (value == null) |
| 161 |
{
|
|
| 162 | 2 |
value = this.originalConfig.getInitParameter(theName);
|
| 163 |
} |
|
| 164 |
|
|
| 165 | 6 |
return value;
|
| 166 |
} |
|
| 167 |
} |
|
| 168 |
|
|
||||||||||