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.HashMap;
11: import java.util.Hashtable;
12: import java.util.Map;
13:
14: import javax.servlet.http.HttpServletRequest;
15: import javax.servlet.http.HttpServletRequestWrapper;
16:
17: /**
18: * HttpServletRequestWrapper that wraps the attributes of the parent request.
19: *
20: * @author Eric Andresen eandresen at unicon.net
21: */
22: public class AttributeRequestWrapper extends HttpServletRequestWrapper {
23: private final Map attributes;
24:
25: public AttributeRequestWrapper(final HttpServletRequest request) {
26: super (request);
27: this .attributes = new Hashtable();
28: }
29:
30: public Object getAttribute(final String name) {
31: Object rslt = this .attributes.get(name);
32:
33: if (rslt == null)
34: rslt = super .getAttribute(name);
35:
36: return rslt;
37: }
38:
39: public Enumeration getAttributeNames() {
40: return Collections.enumeration(getFullAttributesMap().keySet());
41: }
42:
43: public void setAttribute(String name, Object obj) {
44: this .attributes.put(name, obj);
45: }
46:
47: private Map getFullAttributesMap() {
48: Map rslt = new HashMap();
49:
50: Enumeration en = super .getAttributeNames();
51: while (en.hasMoreElements()) {
52: String key = (String) en.nextElement();
53: rslt.put(key, super.getAttribute(key));
54: }
55:
56: rslt.putAll(this.attributes);
57:
58: return Collections.unmodifiableMap(rslt);
59: }
60: }
|