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.cache.rendering; |
21 |
|
|
22 |
|
import java.util.List; |
23 |
|
import java.util.regex.Pattern; |
24 |
|
|
25 |
|
import javax.inject.Inject; |
26 |
|
import javax.inject.Named; |
27 |
|
import javax.inject.Singleton; |
28 |
|
|
29 |
|
import org.xwiki.component.annotation.Component; |
30 |
|
import org.xwiki.configuration.ConfigurationSource; |
31 |
|
import org.xwiki.model.EntityType; |
32 |
|
import org.xwiki.model.ModelContext; |
33 |
|
import org.xwiki.model.reference.DocumentReference; |
34 |
|
import org.xwiki.model.reference.EntityReferenceSerializer; |
35 |
|
|
36 |
|
|
37 |
|
@link |
38 |
|
|
39 |
|
@version |
40 |
|
@since |
41 |
|
|
42 |
|
@Component |
43 |
|
@Singleton |
|
|
| 98.4% |
Uncovered Elements: 1 (62) |
Complexity: 23 |
Complexity Density: 0.66 |
|
44 |
|
public class DefaultRenderingCacheConfiguration implements RenderingCacheConfiguration |
45 |
|
{ |
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
private static final String PREFIX = "core.renderingcache."; |
50 |
|
|
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
private static final String PROPNAME_ENABLED = PREFIX + "enabled"; |
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
private static final String PROPNAME_DOCUMENTS = PREFIX + "documents"; |
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
private static final String PROPNAME_DURATION = PREFIX + "duration"; |
65 |
|
|
66 |
|
|
67 |
|
|
68 |
|
|
69 |
|
private static final int PROPVALUE_DURATION = 300; |
70 |
|
|
71 |
|
|
72 |
|
|
73 |
|
|
74 |
|
private static final String PROPNAME_SIZE = PREFIX + "size"; |
75 |
|
|
76 |
|
|
77 |
|
|
78 |
|
|
79 |
|
private static final int PROPVALUE_SIZE = 100; |
80 |
|
|
81 |
|
|
82 |
|
|
83 |
|
|
84 |
|
@Inject |
85 |
|
@Named("xwikiproperties") |
86 |
|
private ConfigurationSource farmConfiguration; |
87 |
|
|
88 |
|
|
89 |
|
|
90 |
|
|
91 |
|
@Inject |
92 |
|
@Named("wiki") |
93 |
|
private ConfigurationSource wikiConfiguration; |
94 |
|
|
95 |
|
|
96 |
|
|
97 |
|
|
98 |
|
@Inject |
99 |
|
private EntityReferenceSerializer<String> serializer; |
100 |
|
|
101 |
|
|
102 |
|
|
103 |
|
|
104 |
|
@Inject |
105 |
|
@Named("compactwiki") |
106 |
|
private EntityReferenceSerializer<String> wikiSerializer; |
107 |
|
|
108 |
|
|
109 |
|
|
110 |
|
|
111 |
|
@Inject |
112 |
|
private ModelContext modelContext; |
113 |
|
|
114 |
|
|
115 |
|
|
116 |
|
|
117 |
|
private Pattern farmPattern; |
118 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
119 |
47 |
@Override... |
120 |
|
public boolean isEnabled() |
121 |
|
{ |
122 |
47 |
return isFarmEnabled(); |
123 |
|
} |
124 |
|
|
125 |
|
|
126 |
|
@return |
127 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
128 |
12758 |
public boolean isFarmEnabled()... |
129 |
|
{ |
130 |
12758 |
return this.farmConfiguration.getProperty(PROPNAME_ENABLED, false); |
131 |
|
} |
132 |
|
|
133 |
|
|
134 |
|
@return |
135 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
136 |
4 |
public boolean isWikiEnabled()... |
137 |
|
{ |
138 |
4 |
return this.wikiConfiguration.getProperty(PROPNAME_ENABLED, true); |
139 |
|
} |
140 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
141 |
1 |
@Override... |
142 |
|
public int getDuration() |
143 |
|
{ |
144 |
1 |
return this.farmConfiguration.getProperty(PROPNAME_DURATION, PROPVALUE_DURATION); |
145 |
|
} |
146 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
147 |
1 |
@Override... |
148 |
|
public int getSize() |
149 |
|
{ |
150 |
1 |
return this.farmConfiguration.getProperty(PROPNAME_SIZE, PROPVALUE_SIZE); |
151 |
|
} |
152 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 4 |
Complexity Density: 0.8 |
|
153 |
12713 |
@Override... |
154 |
|
public boolean isCached(DocumentReference documentReference) |
155 |
|
{ |
156 |
12711 |
if (documentReference != null && isFarmEnabled()) { |
157 |
13 |
if (isCachedInFarm(documentReference)) { |
158 |
9 |
return true; |
159 |
|
} |
160 |
|
|
161 |
4 |
return isCachedInWiki(documentReference); |
162 |
|
} |
163 |
|
|
164 |
12699 |
return false; |
165 |
|
} |
166 |
|
|
167 |
|
|
168 |
|
|
169 |
|
|
170 |
|
@param |
171 |
|
@return |
172 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
173 |
13 |
private boolean isCachedInFarm(DocumentReference documentReference)... |
174 |
|
{ |
175 |
13 |
Pattern pattern = getFarmPattern(); |
176 |
|
|
177 |
13 |
if (pattern != null) { |
178 |
10 |
String documentReferenceString = this.serializer.serialize(documentReference); |
179 |
|
|
180 |
10 |
return pattern.matcher(documentReferenceString).matches(); |
181 |
|
} |
182 |
|
|
183 |
3 |
return false; |
184 |
|
} |
185 |
|
|
186 |
|
|
187 |
|
|
188 |
|
|
189 |
|
@param |
190 |
|
@return |
191 |
|
|
|
|
| 88.9% |
Uncovered Elements: 1 (9) |
Complexity: 5 |
Complexity Density: 1 |
|
192 |
4 |
public boolean isCachedInWiki(DocumentReference documentReference)... |
193 |
|
{ |
194 |
4 |
if (isWikiEnabled() |
195 |
|
&& this.modelContext.getCurrentEntityReference() != null |
196 |
|
&& documentReference.getWikiReference().getName() |
197 |
|
.equals(this.modelContext.getCurrentEntityReference().extractReference(EntityType.WIKI).getName())) { |
198 |
4 |
Pattern pattern = getWikiPattern(); |
199 |
|
|
200 |
4 |
if (pattern != null) { |
201 |
2 |
return pattern.matcher(this.serializer.serialize(documentReference)).matches() |
202 |
|
|| pattern.matcher(this.wikiSerializer.serialize(documentReference)).matches(); |
203 |
|
} |
204 |
|
} |
205 |
|
|
206 |
2 |
return false; |
207 |
|
} |
208 |
|
|
209 |
|
|
210 |
|
@return |
211 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
212 |
13 |
private Pattern getFarmPattern()... |
213 |
|
{ |
214 |
13 |
if (this.farmPattern == null) { |
215 |
9 |
this.farmPattern = getPattern(this.farmConfiguration.getProperty(PROPNAME_DOCUMENTS, List.class)); |
216 |
|
} |
217 |
|
|
218 |
13 |
return this.farmPattern; |
219 |
|
} |
220 |
|
|
221 |
|
|
222 |
|
@return |
223 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
224 |
4 |
private Pattern getWikiPattern()... |
225 |
|
{ |
226 |
4 |
return getPattern(this.wikiConfiguration.getProperty(PROPNAME_DOCUMENTS, List.class)); |
227 |
|
} |
228 |
|
|
229 |
|
|
230 |
|
@link |
231 |
|
|
232 |
|
@param@link@link |
233 |
|
@return@link@link |
234 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (15) |
Complexity: 4 |
Complexity Density: 0.36 |
|
235 |
13 |
private Pattern getPattern(List<String> configuration)... |
236 |
|
{ |
237 |
13 |
Pattern pattern = null; |
238 |
|
|
239 |
13 |
if (configuration != null && !configuration.isEmpty()) { |
240 |
8 |
StringBuffer patternBuffer = new StringBuffer(); |
241 |
|
|
242 |
8 |
for (String patternString : configuration) { |
243 |
12 |
if (patternBuffer.length() > 0) { |
244 |
4 |
patternBuffer.append('|'); |
245 |
|
} |
246 |
12 |
patternBuffer.append('('); |
247 |
12 |
patternBuffer.append(patternString); |
248 |
12 |
patternBuffer.append(')'); |
249 |
|
} |
250 |
|
|
251 |
8 |
pattern = Pattern.compile(patternBuffer.toString()); |
252 |
|
} |
253 |
|
|
254 |
13 |
return pattern; |
255 |
|
} |
256 |
|
} |