KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > jxpath > servlet > PageContextHandler


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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 JavaDoc;
19 import java.util.HashSet JavaDoc;
20
21 import javax.servlet.jsp.PageContext JavaDoc;
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 JavaDoc[] getPropertyNames(Object JavaDoc pageContext) {
35         HashSet JavaDoc list = new HashSet JavaDoc();
36         Enumeration JavaDoc e =
37             ((PageContext JavaDoc) pageContext).getAttributeNamesInScope(
38                 PageContext.PAGE_SCOPE);
39         while (e.hasMoreElements()) {
40             list.add(e.nextElement());
41         }
42         e =
43             ((PageContext JavaDoc) pageContext).getAttributeNamesInScope(
44                 PageContext.REQUEST_SCOPE);
45         while (e.hasMoreElements()) {
46             list.add(e.nextElement());
47         }
48         e =
49             ((PageContext JavaDoc) pageContext).getAttributeNamesInScope(
50                 PageContext.SESSION_SCOPE);
51         while (e.hasMoreElements()) {
52             list.add(e.nextElement());
53         }
54         e =
55             ((PageContext JavaDoc) pageContext).getAttributeNamesInScope(
56                 PageContext.APPLICATION_SCOPE);
57         while (e.hasMoreElements()) {
58             list.add(e.nextElement());
59         }
60         return (String JavaDoc[]) list.toArray(new String JavaDoc[0]);
61     }
62
63     /**
64      * Returns <code>pageContext.findAttribute(property)</code>.
65      */

66     public Object JavaDoc getProperty(Object JavaDoc pageContext, String JavaDoc property) {
67         return ((PageContext JavaDoc) pageContext).findAttribute(property);
68     }
69
70     public void setProperty(
71         Object JavaDoc pageContext,
72         String JavaDoc property,
73         Object JavaDoc value)
74     {
75         ((PageContext JavaDoc) pageContext).setAttribute(
76             property,
77             value,
78             PageContext.PAGE_SCOPE);
79     }
80 }
81
Popular Tags