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:
20: import javax.servlet.jsp.PageContext;
21:
22: /**
23: * A lightweight wrapper for PageContext that restricts access
24: * to attributes of the "page" scope. This object is needed so that
25: * XPath "foo" would lookup the attribute "foo" in all scopes, while
26: * "$page/foo" would only look in the "page" scope.
27: *
28: * @author Dmitri Plotnikov
29: * @version $Revision: 1.5 $ $Date: 2004/02/29 14:17:40 $
30: */
31: public class PageScopeContext {
32: private PageContext pageContext;
33:
34: public PageScopeContext(PageContext pageContext) {
35: this .pageContext = pageContext;
36: }
37:
38: /**
39: * Returns attributes of the pageContext declared in the "page" scope.
40: */
41: public Enumeration getAttributeNames() {
42: return pageContext
43: .getAttributeNamesInScope(PageContext.PAGE_SCOPE);
44: }
45:
46: public Object getAttribute(String attribute) {
47: return pageContext.getAttribute(attribute,
48: PageContext.PAGE_SCOPE);
49: }
50:
51: public void setAttribute(String attribute, Object value) {
52: pageContext.setAttribute(attribute, value,
53: PageContext.PAGE_SCOPE);
54: }
55: }
|