1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
package org.apache.myfaces.resource; |
20 | |
|
21 | |
import java.io.InputStream; |
22 | |
import java.net.URL; |
23 | |
import org.apache.myfaces.shared.resource.ContractResourceLoader; |
24 | |
import org.apache.myfaces.shared.resource.ResourceMeta; |
25 | |
import org.apache.myfaces.shared.resource.ResourceMetaImpl; |
26 | |
import org.apache.myfaces.shared.util.ClassUtils; |
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
public class ClassLoaderContractResourceLoader extends ContractResourceLoader |
33 | |
{ |
34 | |
|
35 | |
public ClassLoaderContractResourceLoader(String prefix) |
36 | |
{ |
37 | 0 | super(prefix); |
38 | 0 | } |
39 | |
|
40 | |
@Override |
41 | |
public String getLibraryVersion(String path, String contractName) |
42 | |
{ |
43 | 0 | return null; |
44 | |
} |
45 | |
|
46 | |
@Override |
47 | |
public InputStream getResourceInputStream(ResourceMeta resourceMeta) |
48 | |
{ |
49 | 0 | InputStream is = null; |
50 | 0 | if (getPrefix() != null && !"".equals(getPrefix())) |
51 | |
{ |
52 | 0 | String name = getPrefix() + '/' + resourceMeta.getContractName() |
53 | |
+ '/' + resourceMeta.getResourceIdentifier(); |
54 | 0 | is = getClassLoader().getResourceAsStream(name); |
55 | 0 | if (is == null) |
56 | |
{ |
57 | 0 | is = this.getClass().getClassLoader().getResourceAsStream(name); |
58 | |
} |
59 | 0 | return is; |
60 | |
} |
61 | |
else |
62 | |
{ |
63 | 0 | String name = resourceMeta.getContractName() |
64 | |
+ '/' + resourceMeta.getResourceIdentifier(); |
65 | 0 | is = getClassLoader().getResourceAsStream(name); |
66 | 0 | if (is == null) |
67 | |
{ |
68 | 0 | is = this.getClass().getClassLoader().getResourceAsStream(name); |
69 | |
} |
70 | 0 | return is; |
71 | |
} |
72 | |
} |
73 | |
|
74 | |
@Override |
75 | |
public URL getResourceURL(ResourceMeta resourceMeta) |
76 | |
{ |
77 | 0 | URL url = null; |
78 | 0 | if (getPrefix() != null && !"".equals(getPrefix())) |
79 | |
{ |
80 | 0 | String name = getPrefix() + '/' + resourceMeta.getContractName() + |
81 | |
'/' + resourceMeta.getResourceIdentifier(); |
82 | 0 | url = getClassLoader().getResource(name); |
83 | 0 | if (url == null) |
84 | |
{ |
85 | 0 | url = this.getClass().getClassLoader().getResource(name); |
86 | |
} |
87 | 0 | return url; |
88 | |
} |
89 | |
else |
90 | |
{ |
91 | 0 | String name = resourceMeta.getContractName() + '/' + resourceMeta.getResourceIdentifier(); |
92 | 0 | url = getClassLoader().getResource(name); |
93 | 0 | if (url == null) |
94 | |
{ |
95 | 0 | url = this.getClass().getClassLoader().getResource(name); |
96 | |
} |
97 | 0 | return url; |
98 | |
} |
99 | |
} |
100 | |
|
101 | |
@Override |
102 | |
public String getResourceVersion(String path, String contractName) |
103 | |
{ |
104 | 0 | return null; |
105 | |
} |
106 | |
|
107 | |
@Override |
108 | |
public ResourceMeta createResourceMeta(String prefix, String libraryName, String libraryVersion, |
109 | |
String resourceName, String resourceVersion, |
110 | |
String contractName) |
111 | |
{ |
112 | 0 | return new ResourceMetaImpl(prefix, libraryName, libraryVersion, resourceName, |
113 | |
resourceVersion, contractName); |
114 | |
} |
115 | |
|
116 | |
|
117 | |
|
118 | |
|
119 | |
|
120 | |
|
121 | |
|
122 | |
protected ClassLoader getClassLoader() |
123 | |
{ |
124 | 0 | return ClassUtils.getContextClassLoader(); |
125 | |
} |
126 | |
|
127 | |
@Override |
128 | |
public boolean libraryExists(String libraryName, String contractName) |
129 | |
{ |
130 | 0 | if (getPrefix() != null && !"".equals(getPrefix())) |
131 | |
{ |
132 | 0 | String name = getPrefix() + '/' + |
133 | |
contractName + '/' + libraryName; |
134 | 0 | URL url = getClassLoader().getResource(name); |
135 | 0 | if (url == null) |
136 | |
{ |
137 | 0 | url = this.getClass().getClassLoader().getResource(name); |
138 | |
} |
139 | 0 | if (url != null) |
140 | |
{ |
141 | 0 | return true; |
142 | |
} |
143 | 0 | } |
144 | |
else |
145 | |
{ |
146 | 0 | String name = contractName + '/' + libraryName; |
147 | 0 | URL url = getClassLoader().getResource(name); |
148 | 0 | if (url == null) |
149 | |
{ |
150 | 0 | url = this.getClass().getClassLoader().getResource(name); |
151 | |
} |
152 | 0 | if (url != null) |
153 | |
{ |
154 | 0 | return true; |
155 | |
} |
156 | |
} |
157 | 0 | return false; |
158 | |
} |
159 | |
|
160 | |
} |