1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.environment.internal; |
21 |
|
|
22 |
|
import java.io.File; |
23 |
|
import java.io.IOException; |
24 |
|
import java.io.InputStream; |
25 |
|
import java.net.MalformedURLException; |
26 |
|
import java.net.URL; |
27 |
|
|
28 |
|
import javax.inject.Singleton; |
29 |
|
|
30 |
|
import org.xwiki.component.annotation.Component; |
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
@version |
36 |
|
@since |
37 |
|
|
38 |
|
@Component |
39 |
|
@Singleton |
|
|
| 77.4% |
Uncovered Elements: 7 (31) |
Complexity: 10 |
Complexity Density: 0.53 |
|
40 |
|
public class StandardEnvironment extends AbstractEnvironment |
41 |
|
{ |
42 |
|
|
43 |
|
@see |
44 |
|
|
45 |
|
private File resourceDirectory; |
46 |
|
|
47 |
|
|
48 |
|
@see |
49 |
|
|
50 |
|
private ClassLoader resourceClassLoader = StandardEnvironment.class.getClassLoader(); |
51 |
|
|
52 |
|
|
53 |
|
@param |
54 |
|
|
55 |
|
|
56 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
57 |
33 |
public void setResourceDirectory(File resourceDirectory)... |
58 |
|
{ |
59 |
33 |
this.resourceDirectory = resourceDirectory; |
60 |
|
} |
61 |
|
|
62 |
|
|
63 |
|
@param |
64 |
|
|
65 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
66 |
0 |
public void setResourceClassLoader(ClassLoader classLoader)... |
67 |
|
{ |
68 |
0 |
this.resourceClassLoader = classLoader; |
69 |
|
} |
70 |
|
|
|
|
| 55.6% |
Uncovered Elements: 4 (9) |
Complexity: 3 |
Complexity Density: 0.43 |
|
71 |
135 |
@Override... |
72 |
|
public InputStream getResourceAsStream(String resourceName) |
73 |
|
{ |
74 |
135 |
InputStream resourceStream = null; |
75 |
|
|
76 |
135 |
URL resourceURL = getResource(resourceName); |
77 |
135 |
if (resourceURL != null) { |
78 |
0 |
try { |
79 |
0 |
resourceStream = resourceURL.openStream(); |
80 |
|
} catch (IOException e) { |
81 |
0 |
this.logger.debug("Failed to get Input stream for resource [{}]", resourceName, e); |
82 |
|
} |
83 |
|
} |
84 |
|
|
85 |
135 |
return resourceStream; |
86 |
|
} |
87 |
|
|
|
|
| 93.8% |
Uncovered Elements: 1 (16) |
Complexity: 5 |
Complexity Density: 0.5 |
|
88 |
195 |
@Override... |
89 |
|
public URL getResource(String resourceName) |
90 |
|
{ |
91 |
195 |
URL resourceURL = null; |
92 |
|
|
93 |
|
|
94 |
195 |
if (this.resourceDirectory != null) { |
95 |
2 |
try { |
96 |
|
|
97 |
2 |
File resourceFile = new File(this.resourceDirectory, resourceName); |
98 |
2 |
if (resourceFile.exists()) { |
99 |
1 |
resourceURL = resourceFile.toURI().toURL(); |
100 |
|
} |
101 |
|
} catch (MalformedURLException e) { |
102 |
0 |
this.logger.debug("Failed to access resource [{}]", resourceName, e); |
103 |
|
} |
104 |
|
} |
105 |
|
|
106 |
|
|
107 |
195 |
if (resourceURL == null) { |
108 |
194 |
resourceURL = this.resourceClassLoader.getResource(resourceName); |
109 |
|
} |
110 |
|
|
111 |
195 |
return resourceURL; |
112 |
|
} |
113 |
|
} |