KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > taglibs > standard > lang > jstl > JSTLVariableResolver


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
17 package org.apache.taglibs.standard.lang.jstl;
18
19 import javax.servlet.jsp.PageContext JavaDoc;
20
21 /**
22  *
23  * <p>This is the JSTL-specific implementation of VariableResolver.
24  * It looks up variable references in the PageContext, and also
25  * recognizes references to implicit objects.
26  *
27  * @author Nathan Abramson - Art Technology Group
28  * @version $Change: 181177 $$DateTime: 2001/06/26 08:45:09 $$Author: pierred $
29  **/

30
31 public class JSTLVariableResolver
32   implements VariableResolver
33 {
34   //-------------------------------------
35
/**
36    *
37    * Resolves the specified variable within the given context.
38    * Returns null if the variable is not found.
39    **/

40   public Object JavaDoc resolveVariable (String JavaDoc pName,
41                  Object JavaDoc pContext)
42     throws ELException
43   {
44     PageContext JavaDoc ctx = (PageContext JavaDoc) pContext;
45
46     // Check for implicit objects
47
if ("pageContext".equals (pName)) {
48       return ctx;
49     }
50     else if ("pageScope".equals (pName)) {
51       return ImplicitObjects.
52     getImplicitObjects (ctx).
53     getPageScopeMap ();
54     }
55     else if ("requestScope".equals (pName)) {
56       return ImplicitObjects.
57     getImplicitObjects (ctx).
58     getRequestScopeMap ();
59     }
60     else if ("sessionScope".equals (pName)) {
61       return ImplicitObjects.
62     getImplicitObjects (ctx).
63     getSessionScopeMap ();
64     }
65     else if ("applicationScope".equals (pName)) {
66       return ImplicitObjects.
67     getImplicitObjects (ctx).
68     getApplicationScopeMap ();
69     }
70     else if ("param".equals (pName)) {
71       return ImplicitObjects.
72     getImplicitObjects (ctx).
73     getParamMap ();
74     }
75     else if ("paramValues".equals (pName)) {
76       return ImplicitObjects.
77     getImplicitObjects (ctx).
78     getParamsMap ();
79     }
80     else if ("header".equals (pName)) {
81       return ImplicitObjects.
82     getImplicitObjects (ctx).
83     getHeaderMap ();
84     }
85     else if ("headerValues".equals (pName)) {
86       return ImplicitObjects.
87     getImplicitObjects (ctx).
88     getHeadersMap ();
89     }
90     else if ("initParam".equals (pName)) {
91       return ImplicitObjects.
92     getImplicitObjects (ctx).
93     getInitParamMap ();
94     }
95     else if ("cookie".equals (pName)) {
96       return ImplicitObjects.
97     getImplicitObjects (ctx).
98     getCookieMap ();
99     }
100
101     // Otherwise, just look it up in the page context
102
else {
103       return ctx.findAttribute (pName);
104     }
105   }
106                     
107   //-------------------------------------
108
}
109
Popular Tags