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