1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package net.sf.morph.context.contexts;
17
18 import javax.servlet.http.HttpServletRequest;
19 import javax.servlet.jsp.PageContext;
20
21 import net.sf.morph.reflect.BeanReflector;
22 import net.sf.morph.reflect.reflectors.PageContextAttributeReflector;
23
24 /**
25 * <p>
26 * Context for JSP pages that evaluates page context attributes, request
27 * parameters, request attributes, session attributes, and application
28 * attributes, in that order. Exposing request parameters in this manner is
29 * somewhat unusual, so
30 * {@link HttpServletContext#setReflectingRequestParameters(boolean)}can be
31 * called to turn this behavior off.
32 * </p>
33 *
34 * <p>
35 * This class is <em>not</em> threadsafe, but since usually only a single
36 * thread is accessing a request at any given time, this should be OK.
37 * </p>
38 *
39 * @author Matt Sgarlata
40 * @since Dec 4, 2004
41 */
42 public class JspContext extends ReflectorHierarchicalContext {
43
44 private static final BeanReflector PAGE_CONTEXT_ATTRIBUTE_REFLECTOR = new PageContextAttributeReflector();
45
46 private HttpServletContext httpServletContext;
47
48 private PageContext pageContext;
49
50 public JspContext() {
51 httpServletContext = new HttpServletContext();
52
53 this.setBeanReflector(PAGE_CONTEXT_ATTRIBUTE_REFLECTOR);
54 this.setParentContext(httpServletContext);
55 }
56
57 public JspContext(PageContext pageContext) {
58 this();
59 setPageContext(pageContext);
60 }
61
62 /**
63 * @return Returns the pageContext.
64 */
65 public PageContext getPageContext() {
66 return pageContext;
67 }
68 /**
69 * @param pageContext The pageContext to set.
70 */
71 public void setPageContext(PageContext pageContext) {
72 this.pageContext = pageContext;
73 this.httpServletContext.setRequest((HttpServletRequest) pageContext.getRequest());
74 this.setDelegate(pageContext);
75 }
76 public boolean isReflectingRequestParameters() {
77 return httpServletContext.isReflectingRequestParameters();
78 }
79 public void setReflectingRequestParameters(
80 boolean reflectingRequestParameters) {
81 httpServletContext.setReflectingRequestParameters(reflectingRequestParameters);
82 }
83 }