1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.commons.jxpath.servlet;
17
18 import java.util.Enumeration;
19 import java.util.HashSet;
20
21 import javax.servlet.jsp.PageContext;
22
23 import org.apache.commons.jxpath.DynamicPropertyHandler;
24
25 /***
26 * Implementation of the DynamicPropertyHandler interface that provides
27 * access to attributes of a PageContext in all scopes.
28 *
29 * @author Dmitri Plotnikov
30 * @version $Revision: 1.6 $ $Date: 2004/05/08 15:10:49 $
31 */
32 public class PageContextHandler implements DynamicPropertyHandler {
33
34 public String[] getPropertyNames(Object pageContext) {
35 HashSet list = new HashSet();
36 Enumeration e =
37 ((PageContext) pageContext).getAttributeNamesInScope(
38 PageContext.PAGE_SCOPE);
39 while (e.hasMoreElements()) {
40 list.add(e.nextElement());
41 }
42 e =
43 ((PageContext) pageContext).getAttributeNamesInScope(
44 PageContext.REQUEST_SCOPE);
45 while (e.hasMoreElements()) {
46 list.add(e.nextElement());
47 }
48 e =
49 ((PageContext) pageContext).getAttributeNamesInScope(
50 PageContext.SESSION_SCOPE);
51 while (e.hasMoreElements()) {
52 list.add(e.nextElement());
53 }
54 e =
55 ((PageContext) pageContext).getAttributeNamesInScope(
56 PageContext.APPLICATION_SCOPE);
57 while (e.hasMoreElements()) {
58 list.add(e.nextElement());
59 }
60 return (String[]) list.toArray(new String[0]);
61 }
62
63 /***
64 * Returns <code>pageContext.findAttribute(property)</code>.
65 */
66 public Object getProperty(Object pageContext, String property) {
67 return ((PageContext) pageContext).findAttribute(property);
68 }
69
70 public void setProperty(
71 Object pageContext,
72 String property,
73 Object value)
74 {
75 ((PageContext) pageContext).setAttribute(
76 property,
77 value,
78 PageContext.PAGE_SCOPE);
79 }
80 }