1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.jxpath.servlet;
18
19 import java.util.Enumeration;
20 import java.util.HashSet;
21 import java.util.Set;
22
23 import javax.servlet.ServletContext;
24
25 import org.apache.commons.jxpath.DynamicPropertyHandler;
26
27
28
29
30
31
32
33
34 public class ServletContextHandler implements DynamicPropertyHandler {
35
36 private static final int DEFAULT_PROPERTY_COUNT = 16;
37
38 public String[] getPropertyNames(Object context) {
39 Set list = new HashSet(DEFAULT_PROPERTY_COUNT);
40 collectPropertyNames(list, context);
41 return (String[]) list.toArray(new String[list.size()]);
42 }
43
44
45
46
47
48
49 protected void collectPropertyNames(Set set, Object bean) {
50 if (bean instanceof HttpSessionAndServletContext) {
51 bean = ((HttpSessionAndServletContext) bean).getServletContext();
52 }
53 Enumeration e = ((ServletContext) bean).getAttributeNames();
54 while (e.hasMoreElements()) {
55 set.add(e.nextElement());
56 }
57 }
58
59 public Object getProperty(Object context, String property) {
60 return ((ServletContext) context).getAttribute(property);
61 }
62
63 public void setProperty(Object context, String property, Object value) {
64 ((ServletContext) context).setAttribute(property, value);
65 }
66 }