01: package com.opensymphony.webwork.dispatcher;
02:
03: import com.opensymphony.xwork.ActionContext;
04: import com.opensymphony.xwork.util.OgnlValueStack;
05:
06: import javax.servlet.http.HttpServletRequest;
07: import javax.servlet.http.HttpServletRequestWrapper;
08:
09: /**
10: * <!-- START SNIPPET: javadoc -->
11: *
12: * All WebWork requests are wrapped with this class, which provides simple JSTL accessibility. This is because JSTL
13: * works with request attributes, so this class delegates to the value stack except for a few cases where required to
14: * prevent infinite loops. Namely, we don't let any attribute name with "#" in it delegate out to the value stack, as it
15: * could potentially cause an infinite loop. For example, an infinite loop would take place if you called:
16: * request.getAttribute("#attr.foo").
17: *
18: * <!-- END SNIPPET: javadoc -->
19: *
20: * @since 2.2
21: */
22: public class WebWorkRequestWrapper extends HttpServletRequestWrapper {
23: public WebWorkRequestWrapper(HttpServletRequest req) {
24: super (req);
25: }
26:
27: public Object getAttribute(String s) {
28: if (s != null && s.startsWith("javax.servlet")) {
29: // don't bother with the standard javax.servlet attributes, we can short-circuit this
30: // see WW-953 and the forums post linked in that issue for more info
31: return super .getAttribute(s);
32: }
33:
34: Object attribute = super .getAttribute(s);
35:
36: boolean alreadyIn = false;
37: //WW-1365
38: ActionContext ctx = ActionContext.getContext();
39: Boolean b = (Boolean) ctx.get("__requestWrapper.getAttribute");
40: if (b != null) {
41: alreadyIn = b.booleanValue();
42: }
43:
44: // note: we don't let # come through or else a request for
45: // #attr.foo or #request.foo could cause an endless loop
46: if (!alreadyIn && attribute == null && s.indexOf("#") == -1) {
47: try {
48: // If not found, then try the ValueStack
49: ctx.put("__requestWrapper.getAttribute", Boolean.TRUE);
50: OgnlValueStack stack = ctx.getValueStack();
51: if (stack != null) {
52: attribute = stack.findValue(s);
53: }
54: } finally {
55: ctx.put("__requestWrapper.getAttribute", Boolean.FALSE);
56: }
57: }
58: return attribute;
59: }
60: }
|