1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.myfaces.spi.impl;
20
21 import org.apache.myfaces.shared.util.ClassUtils;
22 import org.apache.myfaces.spi.FaceletConfigResourceProvider;
23 import org.apache.myfaces.spi.FaceletConfigResourceProviderFactory;
24 import org.apache.myfaces.spi.ServiceProviderFinderFactory;
25 import org.apache.myfaces.view.facelets.compiler.DefaultFaceletConfigResourceProvider;
26
27 import javax.faces.FacesException;
28 import javax.faces.context.ExternalContext;
29 import java.lang.reflect.InvocationTargetException;
30 import java.security.AccessController;
31 import java.security.PrivilegedActionException;
32 import java.util.List;
33 import java.util.logging.Level;
34 import java.util.logging.Logger;
35
36
37
38
39
40
41 public class DefaultFaceletConfigResourceProviderFactory extends FaceletConfigResourceProviderFactory
42 {
43 public static final String FACELET_CONFIG_PROVIDER = FaceletConfigResourceProvider.class.getName();
44
45 public static final String FACELET_CONFIG_PROVIDER_LIST = FaceletConfigResourceProvider.class.getName()+".LIST";
46
47 private Logger getLogger()
48 {
49 return Logger.getLogger(DefaultFaceletConfigResourceProviderFactory.class.getName());
50 }
51
52 @Override
53 public FaceletConfigResourceProvider createFaceletConfigResourceProvider(
54 ExternalContext externalContext)
55 {
56 FaceletConfigResourceProvider returnValue = null;
57 final ExternalContext extContext = externalContext;
58 try
59 {
60 if (System.getSecurityManager() != null)
61 {
62 returnValue = AccessController.doPrivileged(new java.security.PrivilegedExceptionAction<FaceletConfigResourceProvider>()
63 {
64 public FaceletConfigResourceProvider run() throws ClassNotFoundException,
65 NoClassDefFoundError,
66 InstantiationException,
67 IllegalAccessException,
68 InvocationTargetException,
69 PrivilegedActionException
70 {
71 return resolveFaceletConfigResourceProviderFromService(extContext);
72 }
73 });
74 }
75 else
76 {
77 returnValue = resolveFaceletConfigResourceProviderFromService(extContext);
78 }
79 }
80 catch (ClassNotFoundException e)
81 {
82
83 }
84 catch (NoClassDefFoundError e)
85 {
86
87 }
88 catch (InstantiationException e)
89 {
90 getLogger().log(Level.SEVERE, "", e);
91 }
92 catch (IllegalAccessException e)
93 {
94 getLogger().log(Level.SEVERE, "", e);
95 }
96 catch (InvocationTargetException e)
97 {
98 getLogger().log(Level.SEVERE, "", e);
99 }
100 catch (PrivilegedActionException e)
101 {
102 throw new FacesException(e);
103 }
104 return returnValue;
105 }
106
107 private FaceletConfigResourceProvider resolveFaceletConfigResourceProviderFromService(
108 ExternalContext externalContext) throws ClassNotFoundException,
109 NoClassDefFoundError,
110 InstantiationException,
111 IllegalAccessException,
112 InvocationTargetException,
113 PrivilegedActionException
114 {
115 List<String> classList = (List<String>) externalContext.getApplicationMap().get(FACELET_CONFIG_PROVIDER_LIST);
116 if (classList == null)
117 {
118 classList = ServiceProviderFinderFactory.getServiceProviderFinder(externalContext).getServiceProviderList(FACELET_CONFIG_PROVIDER);
119 externalContext.getApplicationMap().put(FACELET_CONFIG_PROVIDER_LIST, classList);
120 }
121
122 return ClassUtils.buildApplicationObject(FaceletConfigResourceProvider.class, classList, new DefaultFaceletConfigResourceProvider());
123 }
124
125 }