1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.engine.servlet;
18
19 import java.util.Collections;
20 import java.util.Enumeration;
21 import java.util.HashSet;
22
23 import javax.servlet.http.HttpSession;
24
25 import org.apache.jetspeed.Jetspeed;
26 import org.apache.jetspeed.container.namespace.JetspeedNamespaceMapper;
27 import org.apache.jetspeed.container.namespace.JetspeedNamespaceMapperFactory;
28 import org.apache.pluto.om.common.ObjectID;
29
30 /***
31 * @author Scott T Weaver
32 *
33 */
34 public class NamespaceEncodedSession extends HttpSessionWrapper
35 {
36
37 private JetspeedNamespaceMapper nameSpaceMapper;
38
39 private ObjectID webAppId;
40
41 private HashSet mappedNames = new HashSet();
42
43 /***
44 * @param session
45 */
46 public NamespaceEncodedSession(HttpSession session, ObjectID webAppId)
47 {
48 super(session);
49 this.nameSpaceMapper = ((JetspeedNamespaceMapperFactory) Jetspeed.getComponentManager().getComponent(
50 org.apache.pluto.util.NamespaceMapper.class)).getJetspeedNamespaceMapper();
51 this.webAppId = webAppId;
52 }
53
54 /***
55 * <p>
56 * setAttribute
57 * </p>
58 *
59 * @see javax.servlet.ServletRequest#setAttribute(java.lang.String,
60 * java.lang.Object)
61 * @param arg0
62 * @param arg1
63 */
64 public void setAttribute(String name, Object value)
65 {
66
67 if (name == null)
68 {
69 throw new IllegalArgumentException("Attribute name == null");
70 }
71
72 if (skipEncode(name))
73 {
74 super.setAttribute(name, value);
75 }
76 else
77 {
78 String encodedKey = nameSpaceMapper.encode(webAppId, name);
79 mappedNames.add(name);
80 super.setAttribute(encodedKey, value);
81 }
82
83 }
84
85 /***
86 * @see javax.servlet.http.HttpServletRequest#getAttribute(java.lang.String)
87 */
88 public Object getAttribute(String name)
89 {
90 if (skipEncode(name))
91 {
92 return super.getAttribute(name);
93 }
94 else
95 {
96 return super.getAttribute(nameSpaceMapper.encode(webAppId, name));
97 }
98 }
99
100 private boolean skipEncode(String name)
101 {
102 return name.startsWith(nameSpaceMapper.getPrefix()) || name.startsWith("javax.portlet") || name.startsWith("javax.servlet") || name.startsWith("org.apache.jetspeed");
103 }
104
105
106
107
108
109
110 public Enumeration getAttributeNames()
111 {
112 Enumeration names = super.getAttributeNames();
113 while (names.hasMoreElements())
114 {
115 String name = (String) names.nextElement();
116 if (skipEncode(name))
117 {
118 mappedNames.add(name);
119 }
120 }
121
122 return Collections.enumeration(mappedNames);
123 }
124
125
126
127
128
129
130 public void removeAttribute(String name)
131 {
132 if (skipEncode(name))
133 {
134 super.removeAttribute(name);
135 }
136 else
137 {
138 mappedNames.add(name);
139 super.removeAttribute(nameSpaceMapper.encode(webAppId, name));
140 }
141 }
142 }