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