1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
package org.apache.myfaces.config; |
20 | |
|
21 | |
import java.io.IOException; |
22 | |
import java.net.URL; |
23 | |
import java.util.ArrayList; |
24 | |
import java.util.Collection; |
25 | |
import java.util.Enumeration; |
26 | |
import java.util.List; |
27 | |
|
28 | |
import javax.faces.context.ExternalContext; |
29 | |
import org.apache.myfaces.shared.config.MyfacesConfig; |
30 | |
|
31 | |
import org.apache.myfaces.shared.util.ClassUtils; |
32 | |
import org.apache.myfaces.spi.FacesConfigResourceProvider; |
33 | |
import org.apache.myfaces.util.ContainerUtils; |
34 | |
import org.apache.myfaces.config.util.GAEUtils; |
35 | |
import org.apache.myfaces.view.facelets.util.Classpath; |
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
public class DefaultFacesConfigResourceProvider extends FacesConfigResourceProvider |
43 | |
{ |
44 | |
private static final String META_INF_PREFIX = "META-INF/"; |
45 | |
|
46 | |
private static final String FACES_CONFIG_SUFFIX = ".faces-config.xml"; |
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
private static final String FACES_CONFIG_IMPLICIT = "META-INF/faces-config.xml"; |
53 | |
|
54 | |
|
55 | |
public DefaultFacesConfigResourceProvider() |
56 | |
{ |
57 | 0 | super(); |
58 | 0 | } |
59 | |
|
60 | |
@Override |
61 | |
public Collection<URL> getMetaInfConfigurationResources( |
62 | |
ExternalContext context) throws IOException |
63 | |
{ |
64 | 0 | List<URL> urlSet = new ArrayList<URL>(); |
65 | |
|
66 | |
|
67 | |
|
68 | 0 | Enumeration<URL> resources = getClassLoader().getResources(FACES_CONFIG_IMPLICIT); |
69 | 0 | while (resources.hasMoreElements()) |
70 | |
{ |
71 | 0 | urlSet.add(resources.nextElement()); |
72 | |
} |
73 | |
|
74 | 0 | String jarFilesToScanParam = MyfacesConfig.getCurrentInstance(context).getGaeJsfJarFiles(); |
75 | 0 | jarFilesToScanParam = jarFilesToScanParam != null ? jarFilesToScanParam.trim() : null; |
76 | 0 | if (ContainerUtils.isRunningOnGoogleAppEngine(context) && |
77 | |
jarFilesToScanParam != null && |
78 | |
jarFilesToScanParam.length() > 0) |
79 | |
{ |
80 | 0 | Collection<URL> urlsGAE = GAEUtils.searchInWebLib( |
81 | |
context, getClassLoader(), jarFilesToScanParam, META_INF_PREFIX, FACES_CONFIG_SUFFIX); |
82 | 0 | if (urlsGAE != null) |
83 | |
{ |
84 | 0 | urlSet.addAll(urlsGAE); |
85 | |
} |
86 | 0 | } |
87 | |
else |
88 | |
{ |
89 | |
|
90 | 0 | URL[] urls = Classpath.search(getClassLoader(), META_INF_PREFIX, FACES_CONFIG_SUFFIX); |
91 | 0 | for (int i = 0; i < urls.length; i++) |
92 | |
{ |
93 | 0 | urlSet.add(urls[i]); |
94 | |
} |
95 | |
} |
96 | |
|
97 | 0 | return urlSet; |
98 | |
} |
99 | |
|
100 | |
private ClassLoader getClassLoader() |
101 | |
{ |
102 | 0 | ClassLoader loader = ClassUtils.getContextClassLoader(); |
103 | 0 | if (loader == null) |
104 | |
{ |
105 | 0 | loader = this.getClass().getClassLoader(); |
106 | |
} |
107 | 0 | return loader; |
108 | |
} |
109 | |
} |