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.tag.ui; |
20 | |
|
21 | |
import java.io.IOException; |
22 | |
import java.util.Collection; |
23 | |
import java.util.HashMap; |
24 | |
import java.util.Map; |
25 | |
import java.util.logging.Level; |
26 | |
import java.util.logging.Logger; |
27 | |
import javax.el.ELException; |
28 | |
import javax.el.VariableMapper; |
29 | |
import javax.faces.FacesException; |
30 | |
import javax.faces.application.StateManager; |
31 | |
import javax.faces.component.UIComponent; |
32 | |
import javax.faces.event.PhaseId; |
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.TagHandler; |
38 | |
import org.apache.myfaces.view.facelets.AbstractFaceletContext; |
39 | |
import org.apache.myfaces.view.facelets.FaceletCompositionContext; |
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.TagHandlerUtils; |
43 | |
import org.apache.myfaces.view.facelets.tag.jsf.ComponentSupport; |
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
public final class LegacyDecorateHandler extends TagHandler implements TemplateClient |
63 | |
{ |
64 | |
|
65 | |
|
66 | 0 | private static final Logger log = Logger.getLogger(DecorateHandler.class.getName()); |
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
private final TagAttribute _template; |
77 | |
|
78 | |
private final Map<String, DefineHandler> _handlers; |
79 | |
|
80 | |
private final LegacyParamHandler[] _params; |
81 | |
|
82 | |
|
83 | |
|
84 | |
|
85 | |
public LegacyDecorateHandler(TagConfig config) |
86 | |
{ |
87 | 0 | super(config); |
88 | 0 | _template = getRequiredAttribute("template"); |
89 | 0 | _handlers = new HashMap<String, DefineHandler>(); |
90 | |
|
91 | 0 | for (DefineHandler handler : TagHandlerUtils.findNextByType(nextHandler, DefineHandler.class)) |
92 | |
{ |
93 | 0 | _handlers.put(handler.getName(), handler); |
94 | 0 | if (log.isLoggable(Level.FINE)) |
95 | |
{ |
96 | 0 | log.fine(tag + " found Define[" + handler.getName() + "]"); |
97 | |
} |
98 | 0 | } |
99 | |
|
100 | 0 | Collection<LegacyParamHandler> params = TagHandlerUtils.findNextByType(nextHandler, |
101 | |
LegacyParamHandler.class); |
102 | 0 | if (!params.isEmpty()) |
103 | |
{ |
104 | 0 | int i = 0; |
105 | 0 | _params = new LegacyParamHandler[params.size()]; |
106 | 0 | for (LegacyParamHandler handler : params) |
107 | |
{ |
108 | 0 | _params[i++] = handler; |
109 | 0 | } |
110 | 0 | } |
111 | |
else |
112 | |
{ |
113 | 0 | _params = null; |
114 | |
} |
115 | 0 | } |
116 | |
|
117 | |
|
118 | |
|
119 | |
|
120 | |
|
121 | |
|
122 | |
|
123 | |
public void apply(FaceletContext ctx, UIComponent parent) throws IOException, FacesException, FaceletException, |
124 | |
ELException |
125 | |
{ |
126 | 0 | VariableMapper orig = ctx.getVariableMapper(); |
127 | 0 | AbstractFaceletContext actx = (AbstractFaceletContext) ctx; |
128 | 0 | actx.pushClient(this); |
129 | |
|
130 | 0 | if (_params != null) |
131 | |
{ |
132 | 0 | VariableMapper vm = new VariableMapperWrapper(orig); |
133 | 0 | ctx.setVariableMapper(vm); |
134 | 0 | for (int i = 0; i < _params.length; i++) |
135 | |
{ |
136 | 0 | _params[i].apply(ctx, parent); |
137 | |
} |
138 | |
} |
139 | |
|
140 | 0 | FaceletCompositionContext fcc = FaceletCompositionContext.getCurrentInstance(ctx); |
141 | |
String path; |
142 | 0 | boolean markInitialState = false; |
143 | 0 | if (!_template.isLiteral()) |
144 | |
{ |
145 | 0 | String uniqueId = actx.generateUniqueFaceletTagId(fcc.startComponentUniqueIdSection(), tagId); |
146 | |
|
147 | 0 | String restoredPath = (String) ComponentSupport.restoreInitialTagState(ctx, fcc, parent, uniqueId); |
148 | 0 | if (restoredPath != null) |
149 | |
{ |
150 | |
|
151 | |
|
152 | 0 | if (!PhaseId.RESTORE_VIEW.equals(ctx.getFacesContext().getCurrentPhaseId())) |
153 | |
{ |
154 | 0 | path = this._template.getValue(ctx); |
155 | 0 | if (path == null || path.length() == 0) |
156 | |
{ |
157 | 0 | return; |
158 | |
} |
159 | 0 | if (!path.equals(restoredPath)) |
160 | |
{ |
161 | 0 | markInitialState = true; |
162 | |
} |
163 | |
} |
164 | |
else |
165 | |
{ |
166 | 0 | path = restoredPath; |
167 | |
} |
168 | |
} |
169 | |
else |
170 | |
{ |
171 | |
|
172 | 0 | path = this._template.getValue(ctx); |
173 | |
} |
174 | 0 | ComponentSupport.saveInitialTagState(ctx, fcc, parent, uniqueId, path); |
175 | 0 | } |
176 | |
else |
177 | |
{ |
178 | 0 | path = _template.getValue(ctx); |
179 | |
} |
180 | |
try |
181 | |
{ |
182 | |
try |
183 | |
{ |
184 | 0 | boolean oldMarkInitialState = false; |
185 | 0 | Boolean isBuildingInitialState = null; |
186 | 0 | if (markInitialState) |
187 | |
{ |
188 | |
|
189 | 0 | oldMarkInitialState = fcc.isMarkInitialState(); |
190 | 0 | fcc.setMarkInitialState(true); |
191 | 0 | isBuildingInitialState = (Boolean) ctx.getFacesContext().getAttributes().put( |
192 | |
StateManager.IS_BUILDING_INITIAL_STATE, Boolean.TRUE); |
193 | |
} |
194 | |
try |
195 | |
{ |
196 | 0 | ctx.includeFacelet(parent, path); |
197 | |
} |
198 | |
finally |
199 | |
{ |
200 | 0 | if (markInitialState) |
201 | |
{ |
202 | |
|
203 | 0 | if (isBuildingInitialState == null) |
204 | |
{ |
205 | 0 | ctx.getFacesContext().getAttributes().remove( |
206 | |
StateManager.IS_BUILDING_INITIAL_STATE); |
207 | |
} |
208 | |
else |
209 | |
{ |
210 | 0 | ctx.getFacesContext().getAttributes().put( |
211 | |
StateManager.IS_BUILDING_INITIAL_STATE, isBuildingInitialState); |
212 | |
} |
213 | 0 | fcc.setMarkInitialState(oldMarkInitialState); |
214 | |
} |
215 | |
} |
216 | |
} |
217 | |
finally |
218 | |
{ |
219 | 0 | ctx.setVariableMapper(orig); |
220 | 0 | actx.popClient(this); |
221 | 0 | } |
222 | |
} |
223 | |
finally |
224 | |
{ |
225 | 0 | if (!_template.isLiteral()) |
226 | |
{ |
227 | 0 | fcc.endComponentUniqueIdSection(); |
228 | |
} |
229 | |
} |
230 | 0 | if (!_template.isLiteral() && fcc.isUsingPSSOnThisView() && fcc.isRefreshTransientBuildOnPSS() && |
231 | |
!fcc.isRefreshingTransientBuild()) |
232 | |
{ |
233 | |
|
234 | 0 | ComponentSupport.markComponentToRestoreFully(ctx.getFacesContext(), parent); |
235 | |
} |
236 | 0 | if (!_template.isLiteral() && fcc.isDynamicComponentSection()) |
237 | |
{ |
238 | 0 | ComponentSupport.markComponentToRefreshDynamically(ctx.getFacesContext(), parent); |
239 | |
} |
240 | 0 | } |
241 | |
|
242 | |
public boolean apply(FaceletContext ctx, UIComponent parent, String name) throws IOException, FacesException, |
243 | |
FaceletException, ELException |
244 | |
{ |
245 | 0 | if (name != null) |
246 | |
{ |
247 | 0 | DefineHandler handler = _handlers.get(name); |
248 | 0 | if (handler != null) |
249 | |
{ |
250 | 0 | handler.applyDefinition(ctx, parent); |
251 | 0 | return true; |
252 | |
} |
253 | |
else |
254 | |
{ |
255 | 0 | return false; |
256 | |
} |
257 | |
} |
258 | |
else |
259 | |
{ |
260 | 0 | this.nextHandler.apply(ctx, parent); |
261 | 0 | return true; |
262 | |
} |
263 | |
} |
264 | |
} |