1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package com.xpn.xwiki.internal.skin; |
21 |
|
|
22 |
|
import java.net.URL; |
23 |
|
import java.nio.file.Path; |
24 |
|
import java.nio.file.Paths; |
25 |
|
|
26 |
|
import javax.inject.Provider; |
27 |
|
|
28 |
|
import org.apache.commons.configuration.BaseConfiguration; |
29 |
|
import org.apache.commons.configuration.Configuration; |
30 |
|
import org.apache.commons.configuration.ConfigurationException; |
31 |
|
import org.apache.commons.configuration.PropertiesConfiguration; |
32 |
|
import org.apache.commons.lang3.exception.ExceptionUtils; |
33 |
|
import org.slf4j.Logger; |
34 |
|
import org.slf4j.LoggerFactory; |
35 |
|
import org.xwiki.environment.Environment; |
36 |
|
import org.xwiki.rendering.syntax.SyntaxFactory; |
37 |
|
import org.xwiki.skin.Resource; |
38 |
|
import org.xwiki.skin.Skin; |
39 |
|
|
40 |
|
import com.xpn.xwiki.XWikiContext; |
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
@version |
46 |
|
@since |
47 |
|
|
|
|
| 85.5% |
Uncovered Elements: 9 (62) |
Complexity: 17 |
Complexity Density: 0.45 |
|
48 |
|
public class EnvironmentSkin extends AbstractSkin |
49 |
|
{ |
50 |
|
private static final Logger LOGGER = LoggerFactory.getLogger(EnvironmentSkin.class); |
51 |
|
|
52 |
|
private Environment environment; |
53 |
|
|
54 |
|
private Configuration properties; |
55 |
|
|
56 |
|
private Provider<XWikiContext> xcontextProvider; |
57 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
58 |
303496 |
public EnvironmentSkin(String id, InternalSkinManager skinManager, InternalSkinConfiguration configuration,... |
59 |
|
Logger logger, SyntaxFactory syntaxFactory, Environment environment, Provider<XWikiContext> xcontextProvider) |
60 |
|
{ |
61 |
303505 |
super(id, skinManager, configuration, logger, syntaxFactory); |
62 |
|
|
63 |
303500 |
this.environment = environment; |
64 |
303496 |
this.xcontextProvider = xcontextProvider; |
65 |
|
} |
66 |
|
|
|
|
| 83.3% |
Uncovered Elements: 2 (12) |
Complexity: 3 |
Complexity Density: 0.38 |
|
67 |
93101 |
@Override... |
68 |
|
protected Skin createParent() |
69 |
|
{ |
70 |
93098 |
Skin skin; |
71 |
|
|
72 |
93098 |
String parentId = getProperties().getString("parent"); |
73 |
|
|
74 |
93104 |
if (parentId != null) { |
75 |
93012 |
if (parentId.isEmpty()) { |
76 |
|
|
77 |
93007 |
skin = VOID; |
78 |
|
} else { |
79 |
0 |
skin = this.skinManager.getSkin(parentId); |
80 |
|
} |
81 |
|
} else { |
82 |
97 |
skin = null; |
83 |
|
} |
84 |
|
|
85 |
93101 |
return skin; |
86 |
|
} |
87 |
|
|
|
|
| 85.7% |
Uncovered Elements: 2 (14) |
Complexity: 4 |
Complexity Density: 0.4 |
|
88 |
104236 |
public Configuration getProperties()... |
89 |
|
{ |
90 |
104252 |
if (this.properties == null) { |
91 |
104188 |
URL url = this.environment.getResource(getSkinFolder() + "skin.properties"); |
92 |
104201 |
if (url != null) { |
93 |
104093 |
try { |
94 |
104099 |
this.properties = new PropertiesConfiguration(url); |
95 |
|
} catch (ConfigurationException e) { |
96 |
0 |
LOGGER.error("Failed to load skin [{}] properties file ([])", this.id, url, |
97 |
|
ExceptionUtils.getRootCauseMessage(e)); |
98 |
|
|
99 |
0 |
this.properties = new BaseConfiguration(); |
100 |
|
} |
101 |
|
} else { |
102 |
97 |
LOGGER.debug("No properties found for skin [{}]", this.id); |
103 |
|
|
104 |
97 |
this.properties = new BaseConfiguration(); |
105 |
|
} |
106 |
|
} |
107 |
|
|
108 |
104251 |
return this.properties; |
109 |
|
} |
110 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
111 |
243125 |
public String getSkinFolder()... |
112 |
|
{ |
113 |
243125 |
return "/skins/" + this.id + '/'; |
114 |
|
} |
115 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
116 |
138944 |
@Override... |
117 |
|
public Resource<?> getLocalResource(String resourceName) |
118 |
|
{ |
119 |
138939 |
String resourcePath = getResourcePath(resourceName, false); |
120 |
|
|
121 |
138948 |
if (this.environment.getResource(resourcePath) != null) { |
122 |
48065 |
return createResource(resourcePath, resourceName); |
123 |
|
} |
124 |
|
|
125 |
90883 |
return null; |
126 |
|
} |
127 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
128 |
48060 |
protected AbstractEnvironmentResource createResource(String resourcePath, String resourceName)... |
129 |
|
{ |
130 |
48062 |
return new SkinEnvironmentResource(resourcePath, resourceName, this, this.environment, this.xcontextProvider); |
131 |
|
} |
132 |
|
|
|
|
| 68.8% |
Uncovered Elements: 5 (16) |
Complexity: 4 |
Complexity Density: 0.4 |
|
133 |
138936 |
private String getResourcePath(String resource, boolean testExist)... |
134 |
|
{ |
135 |
138932 |
String skinFolder = getSkinFolder(); |
136 |
138943 |
String resourcePath = skinFolder + resource; |
137 |
|
|
138 |
|
|
139 |
138937 |
Path normalizedResource = Paths.get(resourcePath).normalize(); |
140 |
138929 |
if (!normalizedResource.startsWith(skinFolder)) { |
141 |
1 |
LOGGER.warn("Direct access to template file [{}] refused. Possible break-in attempt!", normalizedResource); |
142 |
|
|
143 |
1 |
return null; |
144 |
|
} |
145 |
|
|
146 |
138914 |
if (testExist) { |
147 |
|
|
148 |
0 |
if (this.environment.getResource(resourcePath) == null) { |
149 |
0 |
return null; |
150 |
|
} |
151 |
|
} |
152 |
|
|
153 |
138923 |
return resourcePath; |
154 |
|
} |
155 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
156 |
11142 |
@Override... |
157 |
|
public String getOutputSyntaxString() |
158 |
|
{ |
159 |
11145 |
return getProperties().getString("outputSyntax"); |
160 |
|
} |
161 |
|
} |