1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.apache.struts2.portlet.servlet;
23
24 import java.util.ArrayList;
25 import java.util.Enumeration;
26 import java.util.List;
27
28 import javax.portlet.PortletSession;
29 import javax.servlet.ServletContext;
30 import javax.servlet.http.HttpSession;
31 import javax.servlet.http.HttpSessionContext;
32
33 /***
34 * Wrapper object exposing a {@link PortletSession} as a {@link HttpSession} instance.
35 * Clients accessing this session object will in fact operate on the
36 * {@link PortletSession} object wrapped by this session object.
37 */
38 public class PortletHttpSession implements HttpSession {
39
40 private PortletSession portletSession;
41
42 public PortletHttpSession(PortletSession portletSession) {
43 this.portletSession = portletSession;
44 }
45
46
47
48
49
50
51 public Object getAttribute(String name) {
52 return portletSession.getAttribute(name);
53 }
54
55
56
57
58
59
60 public Enumeration getAttributeNames() {
61 return portletSession.getAttributeNames();
62 }
63
64
65
66
67
68
69 public long getCreationTime() {
70 return portletSession.getCreationTime();
71 }
72
73
74
75
76
77
78 public String getId() {
79 return portletSession.getId();
80 }
81
82
83
84
85
86
87 public long getLastAccessedTime() {
88 return portletSession.getLastAccessedTime();
89 }
90
91
92
93
94
95
96 public int getMaxInactiveInterval() {
97 return portletSession.getMaxInactiveInterval();
98 }
99
100
101
102
103
104
105 public ServletContext getServletContext() {
106 return new PortletServletContext(portletSession.getPortletContext());
107 }
108
109 /***
110 * @see javax.servlet.http.HttpSession#getSessionContext()
111 * @throws IllegalStateException
112 * Not supported in a portlet.
113 */
114 public HttpSessionContext getSessionContext() {
115 throw new IllegalStateException("Not supported in a portlet");
116 }
117
118
119
120
121
122
123 public Object getValue(String name) {
124 return getAttribute(name);
125 }
126
127
128
129
130
131
132 public String[] getValueNames() {
133 List<String> names = new ArrayList<String>();
134 Enumeration attrNames = getAttributeNames();
135 while (attrNames.hasMoreElements()) {
136 names.add((String) attrNames.nextElement());
137 }
138 return names.toArray(new String[0]);
139 }
140
141
142
143
144
145
146 public void invalidate() {
147 portletSession.invalidate();
148 }
149
150
151
152
153
154
155 public boolean isNew() {
156 return portletSession.isNew();
157 }
158
159
160
161
162
163
164
165 public void putValue(String name, Object value) {
166 setAttribute(name, value);
167 }
168
169
170
171
172
173
174 public void removeAttribute(String name) {
175 portletSession.removeAttribute(name);
176 }
177
178
179
180
181
182
183 public void removeValue(String name) {
184 removeAttribute(name);
185 }
186
187
188
189
190
191
192
193 public void setAttribute(String name, Object value) {
194 portletSession.setAttribute(name, value);
195 }
196
197
198
199
200
201
202 public void setMaxInactiveInterval(int interval) {
203 portletSession.setMaxInactiveInterval(interval);
204 }
205
206 /***
207 * Get the wrapped portlet session.
208 *
209 * @return The wrapped portlet session.
210 */
211 public PortletSession getPortletSession() {
212 return portletSession;
213 }
214
215 }