Coverage details for org.chwf.servlet.RequestParameterMap

LineHitsSource
1 /*
2 Chrysalis Web Framework [http://chrysalis.sourceforge.net]
3 Copyright (c) 2002, 2003, 2004, Paul Strack
4  
5 All rights reserved.
6  
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9  
10 1. Redistributions of source code must retain the above copyright notice, this
11 list of conditions and the following disclaimer.
12  
13 2. Redistributions in binary form must reproduce the above copyright notice,
14 this list of conditions and the following disclaimer in the documentation
15 and/or other materials provided with the distribution.
16  
17 3. Neither the name of the copyright holder nor the names of its contributors
18 may be used to endorse or promote products derived from this software without
19 specific prior written permission.
20  
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
22 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
25 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
28 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32  
33 package org.chwf.servlet;
34  
35 import java.util.Enumeration;
36 import java.util.HashMap;
37  
38 import javax.servlet.ServletRequest;
39  
40 /**
41  * <p>A Map class to that caches servlet request data. Internally,
42  * this map holds arrays of strings (to handle request parameters
43  * with multiple values), but its <code>get()</code> method returns
44  * individual string objects (the first string in the array). This
45  * class overrides the <code>put()</code> and <code>remove()</code>
46  * methods to disable them.</p>
47  *
48  * <p>This object does not keep a reference to the request, so it is safe
49  * to cache this object in the session or to serialize it.</p>
50  *
51  * @author <a href="mailto:pfstrack@users.sourceforge.net">Paul Strack</a>
52  */
531public class RequestParameterMap extends HashMap {
54   // Unused at the moment.
55  
56   /** Name used to cache the map in the request or session. */
571  public static final String CACHING_NAME = RequestParameterMap.class.getName();
58  
59   /**
60    * Constructor that initializes the map from the request.<p>
61    *
62    * @param request The request.
63    */
6411  public RequestParameterMap(ServletRequest request) {
6511    Enumeration e = request.getParameterNames();
6630    while (e.hasMoreElements()) {
678      String key = (String) e.nextElement();
688      String[] values = request.getParameterValues(key);
698      super.put(key, values);
70     }
7111  }
72  
73   /**
74    * Throws <code>UnsupportedOperationException</code>.<p>
75    *
76    * @param key The key.
77    * @param value The value.
78    * @return The original value.
79    */
80   public Object put(Object key, Object value) {
811    throw new UnsupportedOperationException();
82   }
83  
84   /**
85    * Throws <code>UnsupportedOperationException</code>.<p>
86    *
87    * @param key The key.
88    * @return The original value.
89    */
90   public Object remove(Object key) {
911    throw new UnsupportedOperationException();
92   }
93  
94   /**
95    * Overrides the <code>Map</code> method to return a single string.<p>
96    *
97    * @param key The key.
98    * @return The value.
99    */
100   public Object get(Object key) {
1013    String[] values = (String[]) super.get(key);
1023    if ((values == null) || (values.length == 0)) {
1031      return null;
104     } else {
1052      return values[0];
106     }
107   }
108  
109   /**
110    * Returns a single parameter value for the given name.<p>
111    *
112    * @param name The parameter name.
113    * @return The value as a String or null if not found.
114    */
115   public String getParameter(String name) {
1161    return (String) get(name);
117   }
118  
119   /**
120    * Returns all parameter values for the given name.<p>
121    *
122    * @param name The parameter name.
123    * @return The values in an array of Strings or null if not found.
124    */
125   public String[] getParameterValues(String name) {
1261    return (String[]) super.get(name);
127   }
128 }

this report was generated by version 1.0.5 of jcoverage.
visit www.jcoverage.com for updates.

copyright © 2003, jcoverage ltd. all rights reserved.
Java is a trademark of Sun Microsystems, Inc. in the United States and other countries.