1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
package org.apache.commons.el; |
18 | |
|
19 | |
import java.util.ArrayList; |
20 | |
import java.util.Enumeration; |
21 | |
import java.util.HashMap; |
22 | |
import java.util.List; |
23 | |
import java.util.Map; |
24 | |
|
25 | |
import javax.servlet.ServletContext; |
26 | |
import javax.servlet.http.Cookie; |
27 | |
import javax.servlet.http.HttpServletRequest; |
28 | |
import javax.servlet.jsp.PageContext; |
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
public class ImplicitObjects |
41 | |
{ |
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
static final String sAttributeName = |
47 | |
"org.apache.commons.el.ImplicitObjects"; |
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
PageContext mContext; |
54 | |
Map mPage; |
55 | |
Map mRequest; |
56 | |
Map mSession; |
57 | |
Map mApplication; |
58 | |
Map mParam; |
59 | |
Map mParams; |
60 | |
Map mHeader; |
61 | |
Map mHeaders; |
62 | |
Map mInitParam; |
63 | |
Map mCookie; |
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
public ImplicitObjects (PageContext pContext) |
71 | 0 | { |
72 | 0 | mContext = pContext; |
73 | 0 | } |
74 | |
|
75 | |
|
76 | |
|
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | |
public static ImplicitObjects getImplicitObjects (PageContext pContext) |
82 | |
{ |
83 | 0 | ImplicitObjects objs = |
84 | |
(ImplicitObjects) |
85 | |
pContext.getAttribute (sAttributeName, |
86 | |
PageContext.PAGE_SCOPE); |
87 | 0 | if (objs == null) { |
88 | 0 | objs = new ImplicitObjects (pContext); |
89 | 0 | pContext.setAttribute (sAttributeName, |
90 | |
objs, |
91 | |
PageContext.PAGE_SCOPE); |
92 | |
} |
93 | 0 | return objs; |
94 | |
} |
95 | |
|
96 | |
|
97 | |
|
98 | |
|
99 | |
|
100 | |
|
101 | |
public Map getPageScopeMap () |
102 | |
{ |
103 | 0 | if (mPage == null) { |
104 | 0 | mPage = createPageScopeMap (mContext); |
105 | |
} |
106 | 0 | return mPage; |
107 | |
} |
108 | |
|
109 | |
|
110 | |
|
111 | |
|
112 | |
|
113 | |
|
114 | |
public Map getRequestScopeMap () |
115 | |
{ |
116 | 0 | if (mRequest == null) { |
117 | 0 | mRequest = createRequestScopeMap (mContext); |
118 | |
} |
119 | 0 | return mRequest; |
120 | |
} |
121 | |
|
122 | |
|
123 | |
|
124 | |
|
125 | |
|
126 | |
|
127 | |
public Map getSessionScopeMap () |
128 | |
{ |
129 | 0 | if (mSession == null) { |
130 | 0 | mSession = createSessionScopeMap (mContext); |
131 | |
} |
132 | 0 | return mSession; |
133 | |
} |
134 | |
|
135 | |
|
136 | |
|
137 | |
|
138 | |
|
139 | |
|
140 | |
public Map getApplicationScopeMap () |
141 | |
{ |
142 | 0 | if (mApplication == null) { |
143 | 0 | mApplication = createApplicationScopeMap (mContext); |
144 | |
} |
145 | 0 | return mApplication; |
146 | |
} |
147 | |
|
148 | |
|
149 | |
|
150 | |
|
151 | |
|
152 | |
|
153 | |
|
154 | |
public Map getParamMap () |
155 | |
{ |
156 | 0 | if (mParam == null) { |
157 | 0 | mParam = createParamMap (mContext); |
158 | |
} |
159 | 0 | return mParam; |
160 | |
} |
161 | |
|
162 | |
|
163 | |
|
164 | |
|
165 | |
|
166 | |
|
167 | |
|
168 | |
public Map getParamsMap () |
169 | |
{ |
170 | 0 | if (mParams == null) { |
171 | 0 | mParams = createParamsMap (mContext); |
172 | |
} |
173 | 0 | return mParams; |
174 | |
} |
175 | |
|
176 | |
|
177 | |
|
178 | |
|
179 | |
|
180 | |
|
181 | |
|
182 | |
public Map getHeaderMap () |
183 | |
{ |
184 | 0 | if (mHeader == null) { |
185 | 0 | mHeader = createHeaderMap (mContext); |
186 | |
} |
187 | 0 | return mHeader; |
188 | |
} |
189 | |
|
190 | |
|
191 | |
|
192 | |
|
193 | |
|
194 | |
|
195 | |
|
196 | |
public Map getHeadersMap () |
197 | |
{ |
198 | 0 | if (mHeaders == null) { |
199 | 0 | mHeaders = createHeadersMap (mContext); |
200 | |
} |
201 | 0 | return mHeaders; |
202 | |
} |
203 | |
|
204 | |
|
205 | |
|
206 | |
|
207 | |
|
208 | |
|
209 | |
|
210 | |
public Map getInitParamMap () |
211 | |
{ |
212 | 0 | if (mInitParam == null) { |
213 | 0 | mInitParam = createInitParamMap (mContext); |
214 | |
} |
215 | 0 | return mInitParam; |
216 | |
} |
217 | |
|
218 | |
|
219 | |
|
220 | |
|
221 | |
|
222 | |
|
223 | |
|
224 | |
public Map getCookieMap () |
225 | |
{ |
226 | 0 | if (mCookie == null) { |
227 | 0 | mCookie = createCookieMap (mContext); |
228 | |
} |
229 | 0 | return mCookie; |
230 | |
} |
231 | |
|
232 | |
|
233 | |
|
234 | |
|
235 | |
|
236 | |
|
237 | |
|
238 | |
|
239 | |
public static Map createPageScopeMap (PageContext pContext) |
240 | |
{ |
241 | 0 | final PageContext context = pContext; |
242 | 0 | return new EnumeratedMap () |
243 | 0 | { |
244 | |
public Enumeration enumerateKeys () |
245 | |
{ |
246 | 0 | return context.getAttributeNamesInScope |
247 | |
(PageContext.PAGE_SCOPE); |
248 | |
} |
249 | |
|
250 | |
public Object getValue (Object pKey) |
251 | |
{ |
252 | 0 | if (pKey instanceof String) { |
253 | 0 | return context.getAttribute |
254 | |
((String) pKey, |
255 | |
PageContext.PAGE_SCOPE); |
256 | |
} |
257 | |
else { |
258 | 0 | return null; |
259 | |
} |
260 | |
} |
261 | |
|
262 | |
public boolean isMutable () |
263 | |
{ |
264 | 0 | return true; |
265 | |
} |
266 | |
}; |
267 | |
} |
268 | |
|
269 | |
|
270 | |
|
271 | |
|
272 | |
|
273 | |
|
274 | |
public static Map createRequestScopeMap (PageContext pContext) |
275 | |
{ |
276 | 0 | final PageContext context = pContext; |
277 | 0 | return new EnumeratedMap () |
278 | 0 | { |
279 | |
public Enumeration enumerateKeys () |
280 | |
{ |
281 | 0 | return context.getAttributeNamesInScope |
282 | |
(PageContext.REQUEST_SCOPE); |
283 | |
} |
284 | |
|
285 | |
public Object getValue (Object pKey) |
286 | |
{ |
287 | 0 | if (pKey instanceof String) { |
288 | 0 | return context.getAttribute |
289 | |
((String) pKey, |
290 | |
PageContext.REQUEST_SCOPE); |
291 | |
} |
292 | |
else { |
293 | 0 | return null; |
294 | |
} |
295 | |
} |
296 | |
|
297 | |
public boolean isMutable () |
298 | |
{ |
299 | 0 | return true; |
300 | |
} |
301 | |
}; |
302 | |
} |
303 | |
|
304 | |
|
305 | |
|
306 | |
|
307 | |
|
308 | |
|
309 | |
public static Map createSessionScopeMap (PageContext pContext) |
310 | |
{ |
311 | 0 | final PageContext context = pContext; |
312 | 0 | return new EnumeratedMap () |
313 | 0 | { |
314 | |
public Enumeration enumerateKeys () |
315 | |
{ |
316 | 0 | return context.getAttributeNamesInScope |
317 | |
(PageContext.SESSION_SCOPE); |
318 | |
} |
319 | |
|
320 | |
public Object getValue (Object pKey) |
321 | |
{ |
322 | 0 | if (pKey instanceof String) { |
323 | 0 | return context.getAttribute |
324 | |
((String) pKey, |
325 | |
PageContext.SESSION_SCOPE); |
326 | |
} |
327 | |
else { |
328 | 0 | return null; |
329 | |
} |
330 | |
} |
331 | |
|
332 | |
public boolean isMutable () |
333 | |
{ |
334 | 0 | return true; |
335 | |
} |
336 | |
}; |
337 | |
} |
338 | |
|
339 | |
|
340 | |
|
341 | |
|
342 | |
|
343 | |
|
344 | |
public static Map createApplicationScopeMap (PageContext pContext) |
345 | |
{ |
346 | 0 | final PageContext context = pContext; |
347 | 0 | return new EnumeratedMap () |
348 | 0 | { |
349 | |
public Enumeration enumerateKeys () |
350 | |
{ |
351 | 0 | return context.getAttributeNamesInScope |
352 | |
(PageContext.APPLICATION_SCOPE); |
353 | |
} |
354 | |
|
355 | |
public Object getValue (Object pKey) |
356 | |
{ |
357 | 0 | if (pKey instanceof String) { |
358 | 0 | return context.getAttribute |
359 | |
((String) pKey, |
360 | |
PageContext.APPLICATION_SCOPE); |
361 | |
} |
362 | |
else { |
363 | 0 | return null; |
364 | |
} |
365 | |
} |
366 | |
|
367 | |
public boolean isMutable () |
368 | |
{ |
369 | 0 | return true; |
370 | |
} |
371 | |
}; |
372 | |
} |
373 | |
|
374 | |
|
375 | |
|
376 | |
|
377 | |
|
378 | |
|
379 | |
|
380 | |
public static Map createParamMap (PageContext pContext) |
381 | |
{ |
382 | 0 | final HttpServletRequest request = |
383 | |
(HttpServletRequest) pContext.getRequest (); |
384 | 0 | return new EnumeratedMap () |
385 | 0 | { |
386 | |
public Enumeration enumerateKeys () |
387 | |
{ |
388 | 0 | return request.getParameterNames (); |
389 | |
} |
390 | |
|
391 | |
public Object getValue (Object pKey) |
392 | |
{ |
393 | 0 | if (pKey instanceof String) { |
394 | 0 | return request.getParameter ((String) pKey); |
395 | |
} |
396 | |
else { |
397 | 0 | return null; |
398 | |
} |
399 | |
} |
400 | |
|
401 | |
public boolean isMutable () |
402 | |
{ |
403 | 0 | return false; |
404 | |
} |
405 | |
}; |
406 | |
} |
407 | |
|
408 | |
|
409 | |
|
410 | |
|
411 | |
|
412 | |
|
413 | |
|
414 | |
public static Map createParamsMap (PageContext pContext) |
415 | |
{ |
416 | 0 | final HttpServletRequest request = |
417 | |
(HttpServletRequest) pContext.getRequest (); |
418 | 0 | return new EnumeratedMap () |
419 | 0 | { |
420 | |
public Enumeration enumerateKeys () |
421 | |
{ |
422 | 0 | return request.getParameterNames (); |
423 | |
} |
424 | |
|
425 | |
public Object getValue (Object pKey) |
426 | |
{ |
427 | 0 | if (pKey instanceof String) { |
428 | 0 | return request.getParameterValues ((String) pKey); |
429 | |
} |
430 | |
else { |
431 | 0 | return null; |
432 | |
} |
433 | |
} |
434 | |
|
435 | |
public boolean isMutable () |
436 | |
{ |
437 | 0 | return false; |
438 | |
} |
439 | |
}; |
440 | |
} |
441 | |
|
442 | |
|
443 | |
|
444 | |
|
445 | |
|
446 | |
|
447 | |
|
448 | |
public static Map createHeaderMap (PageContext pContext) |
449 | |
{ |
450 | 0 | final HttpServletRequest request = |
451 | |
(HttpServletRequest) pContext.getRequest (); |
452 | 0 | return new EnumeratedMap () |
453 | 0 | { |
454 | |
public Enumeration enumerateKeys () |
455 | |
{ |
456 | 0 | return request.getHeaderNames (); |
457 | |
} |
458 | |
|
459 | |
public Object getValue (Object pKey) |
460 | |
{ |
461 | 0 | if (pKey instanceof String) { |
462 | 0 | return request.getHeader ((String) pKey); |
463 | |
} |
464 | |
else { |
465 | 0 | return null; |
466 | |
} |
467 | |
} |
468 | |
|
469 | |
public boolean isMutable () |
470 | |
{ |
471 | 0 | return false; |
472 | |
} |
473 | |
}; |
474 | |
} |
475 | |
|
476 | |
|
477 | |
|
478 | |
|
479 | |
|
480 | |
|
481 | |
|
482 | |
public static Map createHeadersMap (PageContext pContext) |
483 | |
{ |
484 | 0 | final HttpServletRequest request = |
485 | |
(HttpServletRequest) pContext.getRequest (); |
486 | 0 | return new EnumeratedMap () |
487 | 0 | { |
488 | |
public Enumeration enumerateKeys () |
489 | |
{ |
490 | 0 | return request.getHeaderNames (); |
491 | |
} |
492 | |
|
493 | |
public Object getValue (Object pKey) |
494 | |
{ |
495 | 0 | if (pKey instanceof String) { |
496 | |
|
497 | 0 | List l = new ArrayList (); |
498 | 0 | Enumeration e = request.getHeaders ((String) pKey); |
499 | 0 | if (e != null) { |
500 | 0 | while (e.hasMoreElements ()) { |
501 | 0 | l.add (e.nextElement ()); |
502 | |
} |
503 | |
} |
504 | 0 | String [] ret = (String []) l.toArray (new String [l.size ()]); |
505 | 0 | return ret; |
506 | |
} |
507 | |
else { |
508 | 0 | return null; |
509 | |
} |
510 | |
} |
511 | |
|
512 | |
public boolean isMutable () |
513 | |
{ |
514 | 0 | return false; |
515 | |
} |
516 | |
}; |
517 | |
} |
518 | |
|
519 | |
|
520 | |
|
521 | |
|
522 | |
|
523 | |
|
524 | |
|
525 | |
public static Map createInitParamMap (PageContext pContext) |
526 | |
{ |
527 | 0 | final ServletContext context = pContext.getServletContext (); |
528 | 0 | return new EnumeratedMap () |
529 | 0 | { |
530 | |
public Enumeration enumerateKeys () |
531 | |
{ |
532 | 0 | return context.getInitParameterNames (); |
533 | |
} |
534 | |
|
535 | |
public Object getValue (Object pKey) |
536 | |
{ |
537 | 0 | if (pKey instanceof String) { |
538 | 0 | return context.getInitParameter ((String) pKey); |
539 | |
} |
540 | |
else { |
541 | 0 | return null; |
542 | |
} |
543 | |
} |
544 | |
|
545 | |
public boolean isMutable () |
546 | |
{ |
547 | 0 | return false; |
548 | |
} |
549 | |
}; |
550 | |
} |
551 | |
|
552 | |
|
553 | |
|
554 | |
|
555 | |
|
556 | |
|
557 | |
|
558 | |
public static Map createCookieMap (PageContext pContext) |
559 | |
{ |
560 | |
|
561 | 0 | HttpServletRequest request = (HttpServletRequest) pContext.getRequest (); |
562 | 0 | Cookie [] cookies = request.getCookies (); |
563 | 0 | Map ret = new HashMap (); |
564 | 0 | for (int i = 0; cookies != null && i < cookies.length; i++) { |
565 | 0 | Cookie cookie = cookies [i]; |
566 | 0 | if (cookie != null) { |
567 | 0 | String name = cookie.getName (); |
568 | 0 | if (!ret.containsKey (name)) { |
569 | 0 | ret.put (name, cookie); |
570 | |
} |
571 | |
} |
572 | |
} |
573 | 0 | return ret; |
574 | |
} |
575 | |
|
576 | |
|
577 | |
} |