1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.commons.chain.web.portlet;
17
18
19 import java.util.Collections;
20 import java.util.Map;
21 import javax.portlet.PortletContext;
22 import javax.portlet.PortletRequest;
23 import javax.portlet.PortletResponse;
24 import org.apache.commons.chain.web.WebContext;
25
26
27 /***
28 * <p>Concrete implementation of {@link WebContext} suitable for use in
29 * portlets. The abstract methods are mapped to the appropriate
30 * collections of the underlying portlet context, request, and response
31 * instances that are passed to the constructor (or the initialize method).</p>
32 *
33 * @author Craig R. McClanahan
34 * @version $Revision: 1.6 $ $Date: 2004/02/25 00:01:06 $
35 */
36
37 public class PortletWebContext extends WebContext {
38
39
40
41
42
43 /***
44 * <p>Construct an uninitialized {@link PortletWebContext} instance.</p>
45 */
46 public PortletWebContext() {
47
48 ;
49
50 }
51
52
53 /***
54 * <p>Construct a {@link PortletWebContext} instance that is initialized
55 * with the specified Portlet API objects.</p>
56 *
57 * @param context The <code>PortletContext</code> for this web application
58 * @param request The <code>PortletRequest</code> for this request
59 * @param response The <code>PortletResponse</code> for this request
60 */
61 public PortletWebContext(PortletContext context,
62 PortletRequest request,
63 PortletResponse response) {
64
65 initialize(context, request, response);
66
67 }
68
69
70
71
72
73 /***
74 * <p>The lazily instantiated <code>Map</code> of application scope
75 * attributes.</p>
76 */
77 private Map applicationScope = null;
78
79
80 /***
81 * <p>The <code>PortletContext</code> for this web application.</p>
82 */
83 protected PortletContext context = null;
84
85
86 /***
87 * <p>The lazily instantiated <code>Map</code> of header name-value
88 * combinations (immutable).</p>
89 */
90 private Map header = null;
91
92
93 /***
94 * <p>The lazily instantitated <code>Map</code> of header name-values
95 * combinations (immutable).</p>
96 */
97 private Map headerValues = null;
98
99
100 /***
101 * <p>The lazily instantiated <code>Map</code> of context initialization
102 * parameters.</p>
103 */
104 private Map initParam = null;
105
106
107 /***
108 * <p>The lazily instantiated <code>Map</code> of request
109 * parameter name-value.</p>
110 */
111 private Map param = null;
112
113
114 /***
115 * <p>The lazily instantiated <code>Map</code> of request
116 * parameter name-values.</p>
117 */
118 private Map paramValues = null;
119
120
121 /***
122 * <p>The <code>PortletRequest</code> for this request.</p>
123 */
124 protected PortletRequest request = null;
125
126
127 /***
128 * <p>The lazily instantiated <code>Map</code> of request scope
129 * attributes.</p>
130 */
131 private Map requestScope = null;
132
133
134 /***
135 * <p>The <code>PortletResponse</code> for this request.</p>
136 */
137 protected PortletResponse response = null;
138
139
140 /***
141 * <p>The lazily instantiated <code>Map</code> of session scope
142 * attributes.</p>
143 */
144 private Map sessionScope = null;
145
146
147
148
149
150 /***
151 * <p>Return the {@link PortletContext} for this context.</p>
152 */
153 public PortletContext getContext() {
154
155 return (this.context);
156
157 }
158
159
160 /***
161 * <p>Return the {@link PortletRequest} for this context.</p>
162 */
163 public PortletRequest getRequest() {
164
165 return (this.request);
166
167 }
168
169
170 /***
171 * <p>Return the {@link PortletResponse} for this context.</p>
172 */
173 public PortletResponse getResponse() {
174
175 return (this.response);
176
177 }
178
179
180 /***
181 * <p>Initialize (or reinitialize) this {@link PortletWebContext} instance
182 * for the specified Portlet API objects.</p>
183 *
184 * @param context The <code>PortletContext</code> for this web application
185 * @param request The <code>PortletRequest</code> for this request
186 * @param response The <code>PortletResponse</code> for this request
187 */
188 public void initialize(PortletContext context,
189 PortletRequest request,
190 PortletResponse response) {
191
192
193 this.context = context;
194 this.request = request;
195 this.response = response;
196
197
198
199 }
200
201
202 /***
203 * <p>Release references to allocated resources acquired in
204 * <code>initialize()</code> of via subsequent processing. After this
205 * method is called, subsequent calls to any other method than
206 * <code>initialize()</code> will return undefined results.</p>
207 */
208 public void release() {
209
210
211 applicationScope = null;
212 header = null;
213 headerValues = null;
214 initParam = null;
215 param = null;
216 paramValues = null;
217 requestScope = null;
218 sessionScope = null;
219
220
221 context = null;
222 request = null;
223 response = null;
224
225 }
226
227
228
229
230
231
232 public Map getApplicationScope() {
233
234 if ((applicationScope == null) && (context != null)) {
235 applicationScope = new PortletApplicationScopeMap(context);
236 }
237 return (applicationScope);
238
239 }
240
241
242 public Map getHeader() {
243
244 if ((header == null) && (request != null)) {
245
246 header = Collections.EMPTY_MAP;
247 }
248 return (header);
249
250 }
251
252
253 public Map getHeaderValues() {
254
255 if ((headerValues == null) && (request != null)) {
256
257 headerValues = Collections.EMPTY_MAP;
258 }
259 return (headerValues);
260
261 }
262
263
264 public Map getInitParam() {
265
266 if ((initParam == null) && (context != null)) {
267 initParam = new PortletInitParamMap(context);
268 }
269 return (initParam);
270
271 }
272
273
274 public Map getParam() {
275
276 if ((param == null) && (request != null)) {
277 param = new PortletParamMap(request);
278 }
279 return (param);
280
281 }
282
283
284 public Map getParamValues() {
285
286 if ((paramValues == null) && (request != null)) {
287 paramValues = new PortletParamValuesMap(request);
288 }
289 return (paramValues);
290
291 }
292
293
294 public Map getRequestScope() {
295
296 if ((requestScope == null) && (request != null)) {
297 requestScope = new PortletRequestScopeMap(request);
298 }
299 return (requestScope);
300
301 }
302
303
304 public Map getSessionScope() {
305
306 if ((sessionScope == null) && (request != null)) {
307 sessionScope =
308 new PortletSessionScopeMap(request.getPortletSession());
309 }
310 return (sessionScope);
311
312 }
313
314
315
316 }