1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
package org.apache.myfaces.view.facelets.el; |
20 | |
|
21 | |
import java.util.HashMap; |
22 | |
import java.util.Map; |
23 | |
|
24 | |
import javax.el.ValueExpression; |
25 | |
import javax.el.VariableMapper; |
26 | |
|
27 | |
import org.apache.myfaces.view.facelets.PageContext; |
28 | |
import org.apache.myfaces.view.facelets.TemplateContext; |
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
public final class DefaultVariableMapper extends VariableMapperBase |
41 | |
{ |
42 | |
private Map<String, ValueExpression> _vars; |
43 | |
|
44 | |
private PageContext _pageContext; |
45 | |
|
46 | |
private TemplateContext _templateContext; |
47 | |
|
48 | |
private VariableMapper _delegate; |
49 | |
|
50 | |
public boolean _trackResolveVariables; |
51 | |
|
52 | |
public boolean _variableResolved; |
53 | |
|
54 | |
public DefaultVariableMapper() |
55 | |
{ |
56 | 0 | super(); |
57 | 0 | _trackResolveVariables = false; |
58 | 0 | _variableResolved = false; |
59 | 0 | } |
60 | |
|
61 | |
public DefaultVariableMapper(VariableMapper delegate) |
62 | |
{ |
63 | 0 | super(); |
64 | 0 | this._delegate = delegate; |
65 | 0 | } |
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
public ValueExpression resolveVariable(String name) |
71 | |
{ |
72 | 0 | ValueExpression returnValue = null; |
73 | |
|
74 | 0 | if (_vars != null) |
75 | |
{ |
76 | 0 | returnValue = _vars.get(name); |
77 | |
} |
78 | |
|
79 | |
|
80 | 0 | if (returnValue == null) |
81 | |
{ |
82 | |
|
83 | 0 | if (_pageContext != null && _pageContext.getAttributeCount() > 0) |
84 | |
{ |
85 | 0 | if (_pageContext.getAttributes().containsKey(name)) |
86 | |
{ |
87 | 0 | returnValue = _pageContext.getAttributes().get(name); |
88 | 0 | if (_trackResolveVariables) |
89 | |
{ |
90 | 0 | if (returnValue instanceof CacheableValueExpression) |
91 | |
{ |
92 | 0 | if (returnValue instanceof CacheableValueExpressionWrapper) |
93 | |
{ |
94 | 0 | returnValue = ((CacheableValueExpressionWrapper)returnValue). |
95 | |
getWrapped(); |
96 | |
} |
97 | |
} |
98 | |
else |
99 | |
{ |
100 | 0 | _variableResolved = true; |
101 | |
} |
102 | |
} |
103 | 0 | return returnValue; |
104 | |
} |
105 | |
} |
106 | |
|
107 | 0 | if (_templateContext != null) |
108 | |
{ |
109 | 0 | if (!_templateContext.isParameterEmpty() && |
110 | |
_templateContext.containsParameter(name)) |
111 | |
{ |
112 | 0 | returnValue = _templateContext.getParameter(name); |
113 | 0 | if (_trackResolveVariables && |
114 | |
!(returnValue instanceof CacheableValueExpression)) |
115 | |
{ |
116 | 0 | _variableResolved = true; |
117 | |
} |
118 | 0 | return returnValue; |
119 | |
} |
120 | 0 | else if (!_templateContext.isKnownParametersEmpty() && |
121 | |
_templateContext.containsKnownParameter(name)) |
122 | |
{ |
123 | |
|
124 | |
|
125 | |
|
126 | |
|
127 | |
|
128 | |
|
129 | |
|
130 | 0 | if (_trackResolveVariables) |
131 | |
{ |
132 | 0 | _variableResolved = true; |
133 | |
} |
134 | |
} |
135 | |
} |
136 | |
|
137 | 0 | if (_delegate != null) |
138 | |
{ |
139 | 0 | returnValue = _delegate.resolveVariable(name); |
140 | |
} |
141 | |
} |
142 | 0 | else if (_trackResolveVariables) |
143 | |
{ |
144 | |
|
145 | |
|
146 | 0 | _variableResolved = true; |
147 | |
} |
148 | |
|
149 | 0 | return returnValue; |
150 | |
} |
151 | |
|
152 | |
|
153 | |
|
154 | |
|
155 | |
public ValueExpression setVariable(String name, ValueExpression expression) |
156 | |
{ |
157 | 0 | if (_vars == null) |
158 | |
{ |
159 | 0 | _vars = new HashMap<String, ValueExpression>(); |
160 | |
} |
161 | |
|
162 | 0 | return _vars.put(name, expression); |
163 | |
} |
164 | |
|
165 | |
|
166 | |
|
167 | |
|
168 | |
|
169 | |
|
170 | |
public void setPageContext(PageContext pageContext) |
171 | |
{ |
172 | 0 | this._pageContext = pageContext; |
173 | 0 | } |
174 | |
|
175 | |
|
176 | |
|
177 | |
|
178 | |
|
179 | |
|
180 | |
public void setTemplateContext(TemplateContext templateContext) |
181 | |
{ |
182 | 0 | this._templateContext = templateContext; |
183 | 0 | } |
184 | |
|
185 | |
@Override |
186 | |
public boolean isAnyFaceletsVariableResolved() |
187 | |
{ |
188 | 0 | if (_trackResolveVariables) |
189 | |
{ |
190 | 0 | return _variableResolved; |
191 | |
} |
192 | |
else |
193 | |
{ |
194 | |
|
195 | 0 | return true; |
196 | |
} |
197 | |
} |
198 | |
|
199 | |
@Override |
200 | |
public void beforeConstructELExpression() |
201 | |
{ |
202 | 0 | _trackResolveVariables = true; |
203 | 0 | _variableResolved = false; |
204 | 0 | } |
205 | |
|
206 | |
@Override |
207 | |
public void afterConstructELExpression() |
208 | |
{ |
209 | 0 | _trackResolveVariables = false; |
210 | 0 | _variableResolved = false; |
211 | 0 | } |
212 | |
} |