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 super(config);
66 this._vars = this.tag.getAttributes().getAll();
67 this._location = location;
68
69 Collection<DefineHandler> defines = TagHandlerUtils.findNextByType(nextHandler, DefineHandler.class);
70 if (defines.isEmpty())
71 {
72 _handlers = null;
73 }
74 else
75 {
76 _handlers = new HashMap<String, DefineHandler>();
77 for (DefineHandler handler : defines)
78 {
79 _handlers.put(handler.getName(), handler);
80 }
81 }
82 }
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 VariableMapper orig = ctx.getVariableMapper();
96
97 AbstractFaceletContext actx = (AbstractFaceletContext) ctx;
98
99 try
100 {
101 String[] names = null;
102 ValueExpression[] values = null;
103 if (this._vars.length > 0)
104 {
105 names = new String[_vars.length];
106 values = new ValueExpression[_vars.length];
107 for (int i = 0; i < _vars.length; i++)
108 {
109 names[i] = _vars[i].getLocalName();
110 values[i] = _vars[i].getValueExpression(ctx, Object.class);
111 }
112 }
113
114 actx.pushClient(this);
115
116 if (this._vars.length > 0)
117 {
118 VariableMapper varMapper = new VariableMapperWrapper(orig);
119 for (int i = 0; i < this._vars.length; i++)
120 {
121 varMapper.setVariable(names[i], values[i]);
122 }
123 ctx.setVariableMapper(varMapper);
124 }
125 actx.getTemplateContext().setAllowCacheELExpressions(false);
126
127 ctx.includeFacelet(parent, this._location);
128 }
129 catch (FileNotFoundException e)
130 {
131 throw new TagException(this.tag, e.getMessage());
132 }
133 finally
134 {
135
136
137 actx.popClient(this);
138
139 ctx.setVariableMapper(orig);
140 }
141 }
142
143 public boolean apply(FaceletContext ctx, UIComponent parent, String name) throws IOException, FacesException,
144 FaceletException, ELException
145 {
146 if (name != null)
147 {
148 if (this._handlers == null)
149 {
150 return false;
151 }
152 DefineHandler handler = (DefineHandler) this._handlers.get(name);
153 if (handler != null)
154 {
155 AbstractFaceletContext actx = (AbstractFaceletContext) ctx;
156
157 try
158 {
159 handler.applyDefinition(ctx, parent);
160 }
161 finally
162 {
163
164 }
165 return true;
166 }
167 else
168 {
169 return false;
170 }
171 }
172 else
173 {
174 AbstractFaceletContext actx = (AbstractFaceletContext) ctx;
175
176 try
177 {
178 this.nextHandler.apply(ctx, parent);
179 }
180 finally
181 {
182
183 }
184 return true;
185 }
186 }
187
188 }