01: /*
02: * Copyright 1999-2004 The Apache Software Foundation
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
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 = ((PageContext) pageContext)
37: .getAttributeNamesInScope(PageContext.PAGE_SCOPE);
38: while (e.hasMoreElements()) {
39: list.add(e.nextElement());
40: }
41: e = ((PageContext) pageContext)
42: .getAttributeNamesInScope(PageContext.REQUEST_SCOPE);
43: while (e.hasMoreElements()) {
44: list.add(e.nextElement());
45: }
46: e = ((PageContext) pageContext)
47: .getAttributeNamesInScope(PageContext.SESSION_SCOPE);
48: while (e.hasMoreElements()) {
49: list.add(e.nextElement());
50: }
51: e = ((PageContext) pageContext)
52: .getAttributeNamesInScope(PageContext.APPLICATION_SCOPE);
53: while (e.hasMoreElements()) {
54: list.add(e.nextElement());
55: }
56: return (String[]) list.toArray(new String[0]);
57: }
58:
59: /**
60: * Returns <code>pageContext.findAttribute(property)</code>.
61: */
62: public Object getProperty(Object pageContext, String property) {
63: return ((PageContext) pageContext).findAttribute(property);
64: }
65:
66: public void setProperty(Object pageContext, String property,
67: Object value) {
68: ((PageContext) pageContext).setAttribute(property, value,
69: PageContext.PAGE_SCOPE);
70: }
71: }
|