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 javax.servlet.ServletRequest;
22
23
24
25
26
27
28
29
30
31 public class ServletRequestHandler extends HttpSessionHandler {
32
33 protected void collectPropertyNames(HashSet set, Object bean) {
34 super.collectPropertyNames(set, bean);
35 ServletRequestAndContext handle = (ServletRequestAndContext) bean;
36 ServletRequest servletRequest = handle.getServletRequest();
37 Enumeration e = servletRequest.getAttributeNames();
38 while (e.hasMoreElements()) {
39 set.add(e.nextElement());
40 }
41 e = servletRequest.getParameterNames();
42 while (e.hasMoreElements()) {
43 set.add(e.nextElement());
44 }
45 }
46
47 public Object getProperty(Object bean, String property) {
48 ServletRequestAndContext handle = (ServletRequestAndContext) bean;
49 ServletRequest servletRequest = handle.getServletRequest();
50 String[] strings = servletRequest.getParameterValues(property);
51
52 if (strings != null) {
53 if (strings.length == 0) {
54 return null;
55 }
56 if (strings.length == 1) {
57 return strings[0];
58 }
59 return strings;
60 }
61
62 Object object = servletRequest.getAttribute(property);
63 if (object != null) {
64 return object;
65 }
66
67 return super.getProperty(bean, property);
68 }
69
70 public void setProperty(Object request, String property, Object value) {
71 ((ServletRequestAndContext) request).getServletRequest().setAttribute(property, value);
72 }
73 }