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