KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opensymphony > webwork > dispatcher > multipart > WebWorkRequestWrapper


1 package com.opensymphony.webwork.dispatcher.multipart;
2
3 import com.opensymphony.xwork.ActionContext;
4 import com.opensymphony.xwork.util.OgnlValueStack;
5
6 import javax.servlet.http.HttpServletRequest JavaDoc;
7 import javax.servlet.http.HttpServletRequestWrapper JavaDoc;
8
9 /**
10  * All WebWork requests are wrapped with class, which provides simple JSTL accessibility.
11  * This is because JSTL works with request attributes, so this class delegates to the
12  * value stack except for a few cases where required to prevent infinite loops. Namely,
13  * we don't let any attribute name with "#" in it delegate out to the value stack, as
14  * it could potentially cause an infinite loop. For example, an infinite loop would
15  * take place if you called: request.getAttribute("#attr.foo").
16  *
17  * @since 2.2
18  */

19 public class WebWorkRequestWrapper extends HttpServletRequestWrapper JavaDoc {
20     public WebWorkRequestWrapper(HttpServletRequest JavaDoc req) {
21         super(req);
22     }
23
24     public Object JavaDoc getAttribute(String JavaDoc s) {
25         Object JavaDoc attribute = super.getAttribute(s);
26
27         boolean alreadyIn = true;
28         Boolean JavaDoc b = (Boolean JavaDoc) ActionContext.getContext().get("__requestWrapper.getAttribute");
29         if (b != null) {
30             alreadyIn = b.booleanValue();
31         }
32
33         // note: we don't let # come through or else a request for
34
// #attr.foo or #request.foo could cause an endless loop
35
if (alreadyIn && attribute == null && s.indexOf("#") == -1) {
36             try {
37                 // If not found, then try the ValueStack
38
ActionContext.getContext().put("__requestWrapper.getAttribute", Boolean.TRUE);
39                 OgnlValueStack stack = ActionContext.getContext().getValueStack();
40                 if (stack != null) {
41                     attribute = stack.findValue(s);
42                 }
43             } finally {
44                 ActionContext.getContext().put("__requestWrapper.getAttribute", Boolean.FALSE);
45             }
46         }
47         return attribute;
48     }
49 }
50
Popular Tags