1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
package org.apache.myfaces.config.impl.digester; |
20 | |
|
21 | |
import org.apache.myfaces.config.FacesConfigDispenser; |
22 | |
import org.apache.myfaces.config.element.ManagedBean; |
23 | |
import org.apache.myfaces.config.element.NavigationRule; |
24 | |
import org.apache.myfaces.config.element.Renderer; |
25 | |
import org.apache.myfaces.config.impl.digester.elements.Application; |
26 | |
import org.apache.myfaces.config.impl.digester.elements.Converter; |
27 | |
import org.apache.myfaces.config.impl.digester.elements.FacesConfig; |
28 | |
import org.apache.myfaces.config.impl.digester.elements.Factory; |
29 | |
import org.apache.myfaces.config.impl.digester.elements.LocaleConfig; |
30 | |
import org.apache.myfaces.config.impl.digester.elements.RenderKit; |
31 | |
import org.apache.myfaces.config.impl.digester.elements.ResourceBundle; |
32 | |
|
33 | |
import javax.faces.render.RenderKitFactory; |
34 | |
|
35 | |
import java.util.ArrayList; |
36 | |
import java.util.Collections; |
37 | |
import java.util.HashMap; |
38 | |
import java.util.Iterator; |
39 | |
import java.util.LinkedHashMap; |
40 | |
import java.util.List; |
41 | |
import java.util.Map; |
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | 0 | public class DigesterFacesConfigDispenserImpl implements |
47 | |
FacesConfigDispenser<FacesConfig> |
48 | |
{ |
49 | |
|
50 | 0 | private List<String> applicationFactories = new ArrayList<String>(); |
51 | 0 | private List<String> facesContextFactories = new ArrayList<String>(); |
52 | 0 | private List<String> lifecycleFactories = new ArrayList<String>(); |
53 | 0 | private List<String> renderKitFactories = new ArrayList<String>(); |
54 | 0 | private Map<String, String> components = new HashMap<String, String>(); |
55 | 0 | private Map<String, String> validators = new HashMap<String, String>(); |
56 | |
private String defaultRenderKitId; |
57 | |
private LocaleConfig localeConfig; |
58 | 0 | private List<String> actionListeners = new ArrayList<String>(); |
59 | 0 | private List<String> lifecyclePhaseListeners = new ArrayList<String>(); |
60 | |
private String messageBundle; |
61 | 0 | private List<String> navigationHandlers = new ArrayList<String>(); |
62 | 0 | private List<String> viewHandlers = new ArrayList<String>(); |
63 | 0 | private List<String> stateManagers = new ArrayList<String>(); |
64 | 0 | private List<String> propertyResolver = new ArrayList<String>(); |
65 | 0 | private List<String> variableResolver = new ArrayList<String>(); |
66 | 0 | private Map<String, String> converterById = new HashMap<String, String>(); |
67 | 0 | private Map<String, String> converterByClass = new HashMap<String, String>(); |
68 | 0 | private Map<String, Converter> converterConfigurationByClassName = new HashMap<String, Converter>(); |
69 | 0 | private Map<String, RenderKit> renderKits = new LinkedHashMap<String, RenderKit>(); |
70 | 0 | private List<ManagedBean> managedBeans = new ArrayList<ManagedBean>(); |
71 | 0 | private List<NavigationRule> navigationRules = new ArrayList<NavigationRule>(); |
72 | 0 | private List<ResourceBundle> resourceBundles = new ArrayList<ResourceBundle>(); |
73 | 0 | private List<String> elResolvers = new ArrayList<String>(); |
74 | |
|
75 | |
|
76 | |
|
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | |
public void feed(FacesConfig config) |
82 | |
{ |
83 | 0 | for (Factory factory : config.getFactories()) |
84 | |
{ |
85 | 0 | applicationFactories.addAll(factory.getApplicationFactory()); |
86 | 0 | facesContextFactories.addAll(factory.getFacesContextFactory()); |
87 | 0 | lifecycleFactories.addAll(factory.getLifecycleFactory()); |
88 | 0 | renderKitFactories.addAll(factory.getRenderkitFactory()); |
89 | |
} |
90 | 0 | components.putAll(config.getComponents()); |
91 | 0 | validators.putAll(config.getValidators()); |
92 | |
|
93 | 0 | for (Application application : config.getApplications()) |
94 | |
{ |
95 | 0 | if (!application.getDefaultRenderkitId().isEmpty()) |
96 | |
{ |
97 | 0 | defaultRenderKitId = application |
98 | |
.getDefaultRenderkitId().get( |
99 | |
application.getDefaultRenderkitId().size() - 1); |
100 | |
} |
101 | 0 | if (!application.getMessageBundle().isEmpty()) |
102 | |
{ |
103 | 0 | messageBundle = application.getMessageBundle().get( |
104 | |
application.getMessageBundle().size() - 1); |
105 | |
} |
106 | 0 | if (!application.getLocaleConfig().isEmpty()) |
107 | |
{ |
108 | 0 | localeConfig = application.getLocaleConfig() |
109 | |
.get(application.getLocaleConfig().size() - 1); |
110 | |
} |
111 | 0 | actionListeners.addAll(application.getActionListener()); |
112 | 0 | navigationHandlers.addAll(application.getNavigationHandler()); |
113 | 0 | viewHandlers.addAll(application.getViewHandler()); |
114 | 0 | stateManagers.addAll(application.getStateManager()); |
115 | 0 | propertyResolver.addAll(application.getPropertyResolver()); |
116 | 0 | variableResolver.addAll(application.getVariableResolver()); |
117 | 0 | resourceBundles.addAll(application.getResourceBundle()); |
118 | 0 | elResolvers.addAll(application.getElResolver()); |
119 | |
} |
120 | 0 | for (Converter converter : config.getConverters()) { |
121 | |
|
122 | 0 | if (converter.getConverterId() != null) |
123 | |
{ |
124 | 0 | converterById.put(converter.getConverterId(),converter |
125 | |
.getConverterClass()); |
126 | |
} |
127 | |
else |
128 | |
{ |
129 | 0 | converterByClass.put(converter.getForClass(),converter |
130 | |
.getConverterClass()); |
131 | |
} |
132 | |
|
133 | 0 | converterConfigurationByClassName.put( |
134 | |
converter.getConverterClass(), converter); |
135 | |
} |
136 | |
|
137 | 0 | for (RenderKit renderKit : config.getRenderKits()) |
138 | |
{ |
139 | 0 | String renderKitId = renderKit.getId(); |
140 | |
|
141 | 0 | if (renderKitId == null) |
142 | |
{ |
143 | 0 | renderKitId = RenderKitFactory.HTML_BASIC_RENDER_KIT; |
144 | |
} |
145 | |
|
146 | 0 | RenderKit existing = renderKits.get(renderKitId); |
147 | |
|
148 | 0 | if (existing == null) |
149 | |
{ |
150 | 0 | renderKits.put(renderKitId, renderKit); |
151 | |
} |
152 | |
else |
153 | |
{ |
154 | 0 | existing.merge(renderKit); |
155 | |
} |
156 | 0 | } |
157 | 0 | lifecyclePhaseListeners.addAll(config.getLifecyclePhaseListener()); |
158 | 0 | managedBeans.addAll(config.getManagedBeans()); |
159 | 0 | navigationRules.addAll(config.getNavigationRules()); |
160 | 0 | } |
161 | |
|
162 | |
|
163 | |
|
164 | |
|
165 | |
|
166 | |
|
167 | |
|
168 | |
public void feedApplicationFactory(String factoryClassName) |
169 | |
{ |
170 | 0 | applicationFactories.add(factoryClassName); |
171 | 0 | } |
172 | |
|
173 | |
|
174 | |
|
175 | |
|
176 | |
|
177 | |
|
178 | |
|
179 | |
public void feedFacesContextFactory(String factoryClassName) |
180 | |
{ |
181 | 0 | facesContextFactories.add(factoryClassName); |
182 | 0 | } |
183 | |
|
184 | |
|
185 | |
|
186 | |
|
187 | |
|
188 | |
|
189 | |
|
190 | |
public void feedLifecycleFactory(String factoryClassName) |
191 | |
{ |
192 | 0 | lifecycleFactories.add(factoryClassName); |
193 | 0 | } |
194 | |
|
195 | |
|
196 | |
|
197 | |
|
198 | |
|
199 | |
|
200 | |
|
201 | |
public void feedRenderKitFactory(String factoryClassName) |
202 | |
{ |
203 | 0 | renderKitFactories.add(factoryClassName); |
204 | 0 | } |
205 | |
|
206 | |
|
207 | |
|
208 | |
|
209 | |
public Iterator<String> getApplicationFactoryIterator() |
210 | |
{ |
211 | 0 | return applicationFactories.iterator(); |
212 | |
} |
213 | |
|
214 | |
|
215 | |
|
216 | |
|
217 | |
public Iterator<String> getFacesContextFactoryIterator() |
218 | |
{ |
219 | 0 | return facesContextFactories.iterator(); |
220 | |
} |
221 | |
|
222 | |
|
223 | |
|
224 | |
|
225 | |
public Iterator<String> getLifecycleFactoryIterator() |
226 | |
{ |
227 | 0 | return lifecycleFactories.iterator(); |
228 | |
} |
229 | |
|
230 | |
|
231 | |
|
232 | |
|
233 | |
public Iterator<String> getRenderKitFactoryIterator() |
234 | |
{ |
235 | 0 | return renderKitFactories.iterator(); |
236 | |
} |
237 | |
|
238 | |
|
239 | |
|
240 | |
|
241 | |
public Iterator<String> getActionListenerIterator() |
242 | |
{ |
243 | 0 | List<String> listeners = new ArrayList<String>(actionListeners); |
244 | 0 | return listeners.iterator(); |
245 | |
} |
246 | |
|
247 | |
|
248 | |
|
249 | |
|
250 | |
public String getDefaultRenderKitId() |
251 | |
{ |
252 | 0 | return defaultRenderKitId; |
253 | |
} |
254 | |
|
255 | |
|
256 | |
|
257 | |
|
258 | |
public String getMessageBundle() |
259 | |
{ |
260 | 0 | return messageBundle; |
261 | |
} |
262 | |
|
263 | |
|
264 | |
|
265 | |
|
266 | |
public Iterator<String> getNavigationHandlerIterator() |
267 | |
{ |
268 | 0 | List<String> handlers = new ArrayList<String>(navigationHandlers); |
269 | 0 | return handlers.iterator(); |
270 | |
} |
271 | |
|
272 | |
|
273 | |
|
274 | |
|
275 | |
public Iterator<String> getViewHandlerIterator() |
276 | |
{ |
277 | 0 | List<String> handlers = new ArrayList<String>(viewHandlers); |
278 | 0 | return handlers.iterator(); |
279 | |
} |
280 | |
|
281 | |
|
282 | |
|
283 | |
|
284 | |
public Iterator<String> getStateManagerIterator() |
285 | |
{ |
286 | 0 | List<String> managers = new ArrayList<String>(stateManagers); |
287 | 0 | return managers.iterator(); |
288 | |
} |
289 | |
|
290 | |
|
291 | |
|
292 | |
|
293 | |
public Iterator<String> getPropertyResolverIterator() |
294 | |
{ |
295 | 0 | List<String> resolver = new ArrayList<String>(propertyResolver); |
296 | 0 | return resolver.iterator(); |
297 | |
} |
298 | |
|
299 | |
|
300 | |
|
301 | |
|
302 | |
public Iterator<String> getVariableResolverIterator() |
303 | |
{ |
304 | 0 | List<String> resolver = new ArrayList<String>(variableResolver); |
305 | |
|
306 | 0 | return resolver.iterator(); |
307 | |
} |
308 | |
|
309 | |
|
310 | |
|
311 | |
|
312 | |
public String getDefaultLocale() |
313 | |
{ |
314 | 0 | if (localeConfig != null) |
315 | |
{ |
316 | 0 | return localeConfig.getDefaultLocale(); |
317 | |
} |
318 | 0 | return null; |
319 | |
} |
320 | |
|
321 | |
|
322 | |
|
323 | |
|
324 | |
public Iterator getSupportedLocalesIterator() |
325 | |
{ |
326 | 0 | if (localeConfig != null) |
327 | |
{ |
328 | 0 | return localeConfig.getSupportedLocales().iterator(); |
329 | |
} |
330 | 0 | return Collections.EMPTY_LIST.iterator(); |
331 | |
} |
332 | |
|
333 | |
|
334 | |
|
335 | |
|
336 | |
public Iterator getComponentTypes() |
337 | |
{ |
338 | 0 | return components.keySet().iterator(); |
339 | |
} |
340 | |
|
341 | |
|
342 | |
|
343 | |
|
344 | |
public String getComponentClass(String componentType) |
345 | |
{ |
346 | 0 | return components.get(componentType); |
347 | |
} |
348 | |
|
349 | |
|
350 | |
|
351 | |
|
352 | |
public Iterator<String> getConverterIds() |
353 | |
{ |
354 | 0 | return converterById.keySet().iterator(); |
355 | |
} |
356 | |
|
357 | |
|
358 | |
|
359 | |
|
360 | |
public Iterator<String> getConverterClasses() |
361 | |
{ |
362 | 0 | return converterByClass.keySet().iterator(); |
363 | |
} |
364 | |
|
365 | |
public Iterator<String> getConverterConfigurationByClassName() |
366 | |
{ |
367 | 0 | return converterConfigurationByClassName.keySet().iterator(); |
368 | |
} |
369 | |
|
370 | |
public Converter getConverterConfiguration(String converterClassName) |
371 | |
{ |
372 | 0 | return converterConfigurationByClassName.get(converterClassName); |
373 | |
} |
374 | |
|
375 | |
|
376 | |
|
377 | |
|
378 | |
public String getConverterClassById(String converterId) |
379 | |
{ |
380 | 0 | return converterById.get(converterId); |
381 | |
} |
382 | |
|
383 | |
|
384 | |
|
385 | |
|
386 | |
public String getConverterClassByClass(String className) |
387 | |
{ |
388 | 0 | return converterByClass.get(className); |
389 | |
} |
390 | |
|
391 | |
|
392 | |
|
393 | |
|
394 | |
public Iterator getValidatorIds() |
395 | |
{ |
396 | 0 | return validators.keySet().iterator(); |
397 | |
} |
398 | |
|
399 | |
|
400 | |
|
401 | |
|
402 | |
public String getValidatorClass(String validatorId) |
403 | |
{ |
404 | 0 | return validators.get(validatorId); |
405 | |
} |
406 | |
|
407 | |
|
408 | |
|
409 | |
|
410 | |
|
411 | |
public Iterator<ManagedBean> getManagedBeans() |
412 | |
{ |
413 | 0 | return managedBeans.iterator(); |
414 | |
} |
415 | |
|
416 | |
|
417 | |
|
418 | |
|
419 | |
|
420 | |
public Iterator<NavigationRule> getNavigationRules() |
421 | |
{ |
422 | 0 | return navigationRules.iterator(); |
423 | |
} |
424 | |
|
425 | |
|
426 | |
|
427 | |
|
428 | |
public Iterator<String> getRenderKitIds() |
429 | |
{ |
430 | 0 | return renderKits.keySet().iterator(); |
431 | |
} |
432 | |
|
433 | |
|
434 | |
|
435 | |
|
436 | |
public String getRenderKitClass(String renderKitId) |
437 | |
{ |
438 | 0 | RenderKit renderKit = renderKits.get(renderKitId); |
439 | 0 | return renderKit.getRenderKitClass(); |
440 | |
} |
441 | |
|
442 | |
|
443 | |
|
444 | |
|
445 | |
|
446 | |
|
447 | |
public Iterator<Renderer> getRenderers(String renderKitId) |
448 | |
{ |
449 | 0 | RenderKit renderKit = renderKits.get(renderKitId); |
450 | 0 | return renderKit.getRenderer().iterator(); |
451 | |
} |
452 | |
|
453 | |
|
454 | |
|
455 | |
|
456 | |
|
457 | |
public Iterator<String> getLifecyclePhaseListeners() |
458 | |
{ |
459 | 0 | return lifecyclePhaseListeners.iterator(); |
460 | |
} |
461 | |
|
462 | |
public Iterator<ResourceBundle> getResourceBundles() |
463 | |
{ |
464 | 0 | return resourceBundles.iterator(); |
465 | |
} |
466 | |
|
467 | |
public Iterator<String> getElResolvers() |
468 | |
{ |
469 | 0 | return elResolvers.iterator(); |
470 | |
} |
471 | |
|
472 | |
} |