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.util.HashSet; |
23 |
|
import java.util.Set; |
24 |
|
|
25 |
|
import org.apache.commons.lang3.StringUtils; |
26 |
|
import org.slf4j.Logger; |
27 |
|
import org.xwiki.rendering.parser.ParseException; |
28 |
|
import org.xwiki.rendering.syntax.Syntax; |
29 |
|
import org.xwiki.rendering.syntax.SyntaxFactory; |
30 |
|
import org.xwiki.skin.Resource; |
31 |
|
import org.xwiki.skin.ResourceRepository; |
32 |
|
import org.xwiki.skin.Skin; |
33 |
|
|
34 |
|
|
35 |
|
@version |
36 |
|
@since |
37 |
|
|
|
|
| 83.1% |
Uncovered Elements: 11 (65) |
Complexity: 22 |
Complexity Density: 0.58 |
|
38 |
|
public abstract class AbstractSkin implements Skin |
39 |
|
{ |
40 |
|
protected Skin VOID = new Skin() |
41 |
|
{ |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
42 |
0 |
@Override... |
43 |
|
public Resource<?> getResource(String resource) |
44 |
|
{ |
45 |
0 |
return null; |
46 |
|
} |
47 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
48 |
90824 |
@Override... |
49 |
|
public Resource<?> getLocalResource(String resource) |
50 |
|
{ |
51 |
90827 |
return null; |
52 |
|
} |
53 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
54 |
91891 |
@Override... |
55 |
|
public Skin getParent() |
56 |
|
{ |
57 |
91889 |
return null; |
58 |
|
} |
59 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
60 |
182764 |
@Override... |
61 |
|
public String getId() |
62 |
|
{ |
63 |
182754 |
return null; |
64 |
|
} |
65 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
66 |
0 |
@Override... |
67 |
|
public Syntax getOutputSyntax() |
68 |
|
{ |
69 |
0 |
return null; |
70 |
|
} |
71 |
|
}; |
72 |
|
|
73 |
|
protected InternalSkinManager skinManager; |
74 |
|
|
75 |
|
protected InternalSkinConfiguration configuration; |
76 |
|
|
77 |
|
protected String id; |
78 |
|
|
79 |
|
protected Skin parent; |
80 |
|
|
81 |
|
private Logger logger; |
82 |
|
|
83 |
|
private SyntaxFactory syntaxFactory; |
84 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
85 |
303676 |
public AbstractSkin(String id, InternalSkinManager skinManager, InternalSkinConfiguration configuration,... |
86 |
|
Logger logger, SyntaxFactory syntaxFactory) |
87 |
|
{ |
88 |
303669 |
this.id = id; |
89 |
303663 |
this.skinManager = skinManager; |
90 |
303665 |
this.configuration = configuration; |
91 |
303665 |
this.logger = logger; |
92 |
303665 |
this.syntaxFactory = syntaxFactory; |
93 |
|
} |
94 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
95 |
257743 |
@Override... |
96 |
|
public String getId() |
97 |
|
{ |
98 |
257749 |
return this.id; |
99 |
|
} |
100 |
|
|
|
|
| 88.9% |
Uncovered Elements: 1 (9) |
Complexity: 3 |
Complexity Density: 0.6 |
|
101 |
93197 |
@Override... |
102 |
|
public Skin getParent() |
103 |
|
{ |
104 |
93200 |
if (this.parent == null) { |
105 |
93201 |
this.parent = createParent(); |
106 |
|
|
107 |
93194 |
if (this.parent == null) { |
108 |
196 |
this.parent = this.skinManager.getSkin(this.configuration.getDefaultParentSkinId()); |
109 |
|
} |
110 |
|
} |
111 |
|
|
112 |
93198 |
return this.parent; |
113 |
|
} |
114 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 5 |
Complexity Density: 0.62 |
|
115 |
139017 |
@Override... |
116 |
|
public Resource<?> getResource(String resourceName) |
117 |
|
{ |
118 |
139018 |
Resource<?> resource = getLocalResource(resourceName); |
119 |
|
|
120 |
139010 |
if (resource == null) { |
121 |
|
|
122 |
90955 |
Set<String> skins = new HashSet<String>(); |
123 |
90956 |
skins.add(getId()); |
124 |
181780 |
for (ResourceRepository parent = getParent(); parent != null && resource == null |
125 |
|
&& !skins.contains(parent.getId()); parent = parent.getParent()) { |
126 |
90835 |
resource = parent.getLocalResource(resourceName); |
127 |
90829 |
skins.add(parent.getId()); |
128 |
|
} |
129 |
|
} |
130 |
|
|
131 |
139002 |
return resource; |
132 |
|
} |
133 |
|
|
134 |
|
protected abstract Skin createParent(); |
135 |
|
|
|
|
| 77.8% |
Uncovered Elements: 4 (18) |
Complexity: 5 |
Complexity Density: 0.5 |
|
136 |
11168 |
@Override... |
137 |
|
public Syntax getOutputSyntax() |
138 |
|
{ |
139 |
11169 |
Syntax targetSyntax = null; |
140 |
11168 |
String targetSyntaxString = getOutputSyntaxString(); |
141 |
11168 |
if (StringUtils.isNotEmpty(targetSyntaxString)) { |
142 |
11087 |
targetSyntax = parseSyntax(this, targetSyntaxString); |
143 |
11082 |
if (targetSyntax != null) { |
144 |
11080 |
return targetSyntax; |
145 |
|
} |
146 |
|
} |
147 |
|
|
148 |
81 |
Skin parent = getParent(); |
149 |
81 |
if (parent != null) { |
150 |
0 |
targetSyntax = parent.getOutputSyntax(); |
151 |
|
} |
152 |
|
|
153 |
|
|
154 |
81 |
return targetSyntax != null ? targetSyntax : Syntax.XHTML_1_0; |
155 |
|
} |
156 |
|
|
157 |
|
|
158 |
|
@return |
159 |
|
|
160 |
|
protected abstract String getOutputSyntaxString(); |
161 |
|
|
|
|
| 50% |
Uncovered Elements: 2 (4) |
Complexity: 2 |
Complexity Density: 0.5 |
|
162 |
11086 |
private Syntax parseSyntax(Skin skin, String syntax)... |
163 |
|
{ |
164 |
11087 |
try { |
165 |
11086 |
return syntaxFactory.createSyntaxFromIdString(syntax); |
166 |
|
} catch (ParseException e) { |
167 |
0 |
logger.warn("Failed to parse the syntax [{}] configured by the skin [{}].", |
168 |
|
syntax, skin.getId()); |
169 |
|
} |
170 |
|
|
171 |
|
|
172 |
0 |
return null; |
173 |
|
} |
174 |
|
} |