001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *     http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.commons.el;
018
019import javax.servlet.jsp.PageContext;
020import javax.servlet.jsp.el.ELException;
021import javax.servlet.jsp.el.VariableResolver;
022
023/**
024 *
025 * <p>This is the JSTL-specific implementation of VariableResolver.
026 * It looks up variable references in the PageContext, and also
027 * recognizes references to implicit objects.
028 * 
029 * @author Nathan Abramson - Art Technology Group
030 * @version $Change: 181177 $$DateTime: 2001/06/26 08:45:09 $$Author: mbenson $
031 **/
032
033public class VariableResolverImpl
034  implements VariableResolver
035{
036  //-------------------------------------
037  // Member variables
038  //-------------------------------------
039
040  private PageContext mCtx;
041
042  //-------------------------------------
043  /**
044   *
045   * Constructor
046   **/
047  public VariableResolverImpl (PageContext pCtx)
048  {
049    mCtx = pCtx;
050  }
051  
052  //-------------------------------------
053  /**
054   *
055   * Resolves the specified variable within the given context.
056   * Returns null if the variable is not found.
057   **/
058  public Object resolveVariable (String pName)
059    throws ELException
060  {
061    // Check for implicit objects
062    if ("pageContext".equals (pName)) {
063      return mCtx;
064    }
065    else if ("pageScope".equals (pName)) {
066      return ImplicitObjects.
067        getImplicitObjects (mCtx).
068        getPageScopeMap ();
069    }
070    else if ("requestScope".equals (pName)) {
071      return ImplicitObjects.
072        getImplicitObjects (mCtx).
073        getRequestScopeMap ();
074    }
075    else if ("sessionScope".equals (pName)) {
076      return ImplicitObjects.
077        getImplicitObjects (mCtx).
078        getSessionScopeMap ();
079    }
080    else if ("applicationScope".equals (pName)) {
081      return ImplicitObjects.
082        getImplicitObjects (mCtx).
083        getApplicationScopeMap ();
084    }
085    else if ("param".equals (pName)) {
086      return ImplicitObjects.
087        getImplicitObjects (mCtx).
088        getParamMap ();
089    }
090    else if ("paramValues".equals (pName)) {
091      return ImplicitObjects.
092        getImplicitObjects (mCtx).
093        getParamsMap ();
094    }
095    else if ("header".equals (pName)) {
096      return ImplicitObjects.
097        getImplicitObjects (mCtx).
098        getHeaderMap ();
099    }
100    else if ("headerValues".equals (pName)) {
101      return ImplicitObjects.
102        getImplicitObjects (mCtx).
103        getHeadersMap ();
104    }
105    else if ("initParam".equals (pName)) {
106      return ImplicitObjects.
107        getImplicitObjects (mCtx).
108        getInitParamMap ();
109    }
110    else if ("cookie".equals (pName)) {
111      return ImplicitObjects.
112        getImplicitObjects (mCtx).
113        getCookieMap ();
114    }
115
116    // Otherwise, just look it up in the page context
117    else {
118      return mCtx.findAttribute (pName);
119    }
120  }
121                                        
122  //-------------------------------------
123}