1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
package org.apache.myfaces.view.facelets.tag; |
21 | |
|
22 | |
import java.io.FileNotFoundException; |
23 | |
import java.io.IOException; |
24 | |
import java.net.URL; |
25 | |
import java.util.Collection; |
26 | |
import java.util.HashMap; |
27 | |
import java.util.Map; |
28 | |
import javax.el.ELException; |
29 | |
import javax.el.ValueExpression; |
30 | |
import javax.el.VariableMapper; |
31 | |
import javax.faces.FacesException; |
32 | |
import javax.faces.component.UIComponent; |
33 | |
import javax.faces.view.facelets.FaceletContext; |
34 | |
import javax.faces.view.facelets.FaceletException; |
35 | |
import javax.faces.view.facelets.TagAttribute; |
36 | |
import javax.faces.view.facelets.TagConfig; |
37 | |
import javax.faces.view.facelets.TagException; |
38 | |
import javax.faces.view.facelets.TagHandler; |
39 | |
import org.apache.myfaces.view.facelets.AbstractFaceletContext; |
40 | |
import org.apache.myfaces.view.facelets.TemplateClient; |
41 | |
import org.apache.myfaces.view.facelets.el.VariableMapperWrapper; |
42 | |
import org.apache.myfaces.view.facelets.tag.ui.DefineHandler; |
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
final class LegacyUserTagHandler extends TagHandler implements TemplateClient, ComponentContainerHandler |
52 | |
{ |
53 | |
|
54 | |
protected final TagAttribute[] _vars; |
55 | |
|
56 | |
protected final URL _location; |
57 | |
|
58 | |
protected final Map<String, DefineHandler> _handlers; |
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
public LegacyUserTagHandler(TagConfig config, URL location) |
64 | |
{ |
65 | 0 | super(config); |
66 | 0 | this._vars = this.tag.getAttributes().getAll(); |
67 | 0 | this._location = location; |
68 | |
|
69 | 0 | Collection<DefineHandler> defines = TagHandlerUtils.findNextByType(nextHandler, DefineHandler.class); |
70 | 0 | if (defines.isEmpty()) |
71 | |
{ |
72 | 0 | _handlers = null; |
73 | |
} |
74 | |
else |
75 | |
{ |
76 | 0 | _handlers = new HashMap<String, DefineHandler>(); |
77 | 0 | for (DefineHandler handler : defines) |
78 | |
{ |
79 | 0 | _handlers.put(handler.getName(), handler); |
80 | 0 | } |
81 | |
} |
82 | 0 | } |
83 | |
|
84 | |
|
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | |
|
90 | |
|
91 | |
|
92 | |
public void apply(FaceletContext ctx, UIComponent parent) throws IOException, FacesException, FaceletException, |
93 | |
ELException |
94 | |
{ |
95 | 0 | VariableMapper orig = ctx.getVariableMapper(); |
96 | |
|
97 | 0 | AbstractFaceletContext actx = (AbstractFaceletContext) ctx; |
98 | |
|
99 | |
try |
100 | |
{ |
101 | 0 | String[] names = null; |
102 | 0 | ValueExpression[] values = null; |
103 | 0 | if (this._vars.length > 0) |
104 | |
{ |
105 | 0 | names = new String[_vars.length]; |
106 | 0 | values = new ValueExpression[_vars.length]; |
107 | 0 | for (int i = 0; i < _vars.length; i++) |
108 | |
{ |
109 | 0 | names[i] = _vars[i].getLocalName(); |
110 | 0 | values[i] = _vars[i].getValueExpression(ctx, Object.class); |
111 | |
} |
112 | |
} |
113 | |
|
114 | 0 | actx.pushClient(this); |
115 | |
|
116 | 0 | if (this._vars.length > 0) |
117 | |
{ |
118 | 0 | VariableMapper varMapper = new VariableMapperWrapper(orig); |
119 | 0 | for (int i = 0; i < this._vars.length; i++) |
120 | |
{ |
121 | 0 | varMapper.setVariable(names[i], values[i]); |
122 | |
} |
123 | 0 | ctx.setVariableMapper(varMapper); |
124 | |
} |
125 | 0 | actx.getTemplateContext().setAllowCacheELExpressions(false); |
126 | |
|
127 | 0 | ctx.includeFacelet(parent, this._location); |
128 | |
} |
129 | 0 | catch (FileNotFoundException e) |
130 | |
{ |
131 | 0 | throw new TagException(this.tag, e.getMessage()); |
132 | |
} |
133 | |
finally |
134 | |
{ |
135 | |
|
136 | |
|
137 | 0 | actx.popClient(this); |
138 | |
|
139 | 0 | ctx.setVariableMapper(orig); |
140 | 0 | } |
141 | 0 | } |
142 | |
|
143 | |
public boolean apply(FaceletContext ctx, UIComponent parent, String name) throws IOException, FacesException, |
144 | |
FaceletException, ELException |
145 | |
{ |
146 | 0 | if (name != null) |
147 | |
{ |
148 | 0 | if (this._handlers == null) |
149 | |
{ |
150 | 0 | return false; |
151 | |
} |
152 | 0 | DefineHandler handler = (DefineHandler) this._handlers.get(name); |
153 | 0 | if (handler != null) |
154 | |
{ |
155 | 0 | AbstractFaceletContext actx = (AbstractFaceletContext) ctx; |
156 | |
|
157 | |
try |
158 | |
{ |
159 | 0 | handler.applyDefinition(ctx, parent); |
160 | |
} |
161 | |
finally |
162 | 0 | { |
163 | |
|
164 | 0 | } |
165 | 0 | return true; |
166 | |
} |
167 | |
else |
168 | |
{ |
169 | 0 | return false; |
170 | |
} |
171 | |
} |
172 | |
else |
173 | |
{ |
174 | 0 | AbstractFaceletContext actx = (AbstractFaceletContext) ctx; |
175 | |
|
176 | |
try |
177 | |
{ |
178 | 0 | this.nextHandler.apply(ctx, parent); |
179 | |
} |
180 | |
finally |
181 | 0 | { |
182 | |
|
183 | 0 | } |
184 | 0 | return true; |
185 | |
} |
186 | |
} |
187 | |
|
188 | |
} |