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.security.PrivilegedExceptionAction; |
33 | |
import java.util.List; |
34 | |
import java.util.logging.Level; |
35 | |
import java.util.logging.Logger; |
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | 0 | public class DefaultFaceletConfigResourceProviderFactory extends FaceletConfigResourceProviderFactory |
43 | |
{ |
44 | 0 | public static final String FACELET_CONFIG_PROVIDER = FaceletConfigResourceProvider.class.getName(); |
45 | |
|
46 | 0 | public static final String FACELET_CONFIG_PROVIDER_LIST = FaceletConfigResourceProvider.class.getName()+".LIST"; |
47 | |
|
48 | |
private Logger getLogger() |
49 | |
{ |
50 | 0 | return Logger.getLogger(DefaultFaceletConfigResourceProviderFactory.class.getName()); |
51 | |
} |
52 | |
|
53 | |
@Override |
54 | |
public FaceletConfigResourceProvider createFaceletConfigResourceProvider( |
55 | |
ExternalContext externalContext) |
56 | |
{ |
57 | 0 | FaceletConfigResourceProvider returnValue = null; |
58 | 0 | final ExternalContext extContext = externalContext; |
59 | |
try |
60 | |
{ |
61 | 0 | if (System.getSecurityManager() != null) |
62 | |
{ |
63 | 0 | returnValue |
64 | |
= AccessController.doPrivileged(new PrivilegedExceptionAction<FaceletConfigResourceProvider>() |
65 | 0 | { |
66 | |
public FaceletConfigResourceProvider run() throws ClassNotFoundException, |
67 | |
NoClassDefFoundError, |
68 | |
InstantiationException, |
69 | |
IllegalAccessException, |
70 | |
InvocationTargetException, |
71 | |
PrivilegedActionException |
72 | |
{ |
73 | 0 | return resolveFaceletConfigResourceProviderFromService(extContext); |
74 | |
} |
75 | |
}); |
76 | |
} |
77 | |
else |
78 | |
{ |
79 | 0 | returnValue = resolveFaceletConfigResourceProviderFromService(extContext); |
80 | |
} |
81 | |
} |
82 | 0 | catch (ClassNotFoundException e) |
83 | |
{ |
84 | |
|
85 | |
} |
86 | 0 | catch (NoClassDefFoundError e) |
87 | |
{ |
88 | |
|
89 | |
} |
90 | 0 | catch (InstantiationException e) |
91 | |
{ |
92 | 0 | getLogger().log(Level.SEVERE, "", e); |
93 | |
} |
94 | 0 | catch (IllegalAccessException e) |
95 | |
{ |
96 | 0 | getLogger().log(Level.SEVERE, "", e); |
97 | |
} |
98 | 0 | catch (InvocationTargetException e) |
99 | |
{ |
100 | 0 | getLogger().log(Level.SEVERE, "", e); |
101 | |
} |
102 | 0 | catch (PrivilegedActionException e) |
103 | |
{ |
104 | 0 | throw new FacesException(e); |
105 | 0 | } |
106 | 0 | return returnValue; |
107 | |
} |
108 | |
|
109 | |
private FaceletConfigResourceProvider resolveFaceletConfigResourceProviderFromService( |
110 | |
ExternalContext externalContext) throws ClassNotFoundException, |
111 | |
NoClassDefFoundError, |
112 | |
InstantiationException, |
113 | |
IllegalAccessException, |
114 | |
InvocationTargetException, |
115 | |
PrivilegedActionException |
116 | |
{ |
117 | 0 | List<String> classList = (List<String>) externalContext.getApplicationMap().get(FACELET_CONFIG_PROVIDER_LIST); |
118 | 0 | if (classList == null) |
119 | |
{ |
120 | 0 | classList = ServiceProviderFinderFactory.getServiceProviderFinder(externalContext). |
121 | |
getServiceProviderList(FACELET_CONFIG_PROVIDER); |
122 | 0 | externalContext.getApplicationMap().put(FACELET_CONFIG_PROVIDER_LIST, classList); |
123 | |
} |
124 | |
|
125 | 0 | return ClassUtils.buildApplicationObject(FaceletConfigResourceProvider.class, classList, |
126 | |
new DefaultFaceletConfigResourceProvider()); |
127 | |
} |
128 | |
|
129 | |
} |