01: /* Copyright 2004 The JA-SIG Collaborative. All rights reserved.
02: * See license distributed with this file and
03: * available online at http://www.uportal.org/license.html
04: */
05:
06: package org.jasig.portal.container.servlet;
07:
08: import java.util.Collections;
09: import java.util.Enumeration;
10: import java.util.Map;
11:
12: import javax.servlet.http.HttpServletRequest;
13: import javax.servlet.http.HttpServletRequestWrapper;
14:
15: /**
16: * This {@link javax.servlet.http.HttpServletRequestWrapper} overrides the
17: * parameter related methods of a {@link javax.servlet.http.HttpServletRequest}.
18: * It will either use an empty {@link Map} or the {@link Map} provided to the
19: * constructer to answer parameter questions.
20: *
21: * @author Eric Dalquist <a href="mailto:edalquist@unicon.net">edalquist@unicon.net</a>
22: * @version $Revision: 36796 $
23: */
24: public class DummyParameterRequestWrapper extends
25: AttributeRequestWrapper {
26: final Map params;
27:
28: /**
29: * Creates a wrapper that has no parameters. This will hide and parameters
30: * from the wrapped request.
31: *
32: * @param request The request to wrap.
33: */
34: public DummyParameterRequestWrapper(final HttpServletRequest request) {
35: this (request, null);
36: }
37:
38: /**
39: * Creates a wrapper that uses the specified parameters. Passing
40: * <code>null</code> in is the same as calling {@link DummyParameterRequestWrapper#DummyParameterRequestWrapper(HttpServletRequest)}.
41: *
42: * @param request The request to wrap.
43: * @param dummyParameters The {@link Map} to use as the backing for the paramters of this request, may be <code>null</code>.
44: */
45: public DummyParameterRequestWrapper(
46: final HttpServletRequest request, final Map dummyParameters) {
47: super (request);
48:
49: if (dummyParameters != null)
50: params = Collections.unmodifiableMap(dummyParameters);
51: else
52: params = Collections.EMPTY_MAP;
53: }
54:
55: /*
56: * @see javax.servlet.ServletRequest#getParameter(java.lang.String)
57: */
58: public String getParameter(final String name) {
59: final String[] values = this .getParameterValues(name);
60:
61: if (values != null)
62: return values[0];
63: else
64: return null;
65: }
66:
67: /*
68: * @see javax.servlet.ServletRequest#getParameterMap()
69: */
70: public Map getParameterMap() {
71: return this .params;
72: }
73:
74: /*
75: * @see javax.servlet.ServletRequest#getParameterNames()
76: */
77: public Enumeration getParameterNames() {
78: return Collections.enumeration(this .params.keySet());
79: }
80:
81: /*
82: * @see javax.servlet.ServletRequest#getParameterValues(java.lang.String)
83: */
84: public String[] getParameterValues(final String name) {
85: return (String[]) this.params.get(name);
86: }
87: }
|