| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
package com.xpn.xwiki.plugin.skinx; |
| 21 |
|
|
| 22 |
|
import java.io.UnsupportedEncodingException; |
| 23 |
|
import java.net.URLEncoder; |
| 24 |
|
import java.util.Collections; |
| 25 |
|
import java.util.HashMap; |
| 26 |
|
import java.util.LinkedHashSet; |
| 27 |
|
import java.util.Map; |
| 28 |
|
import java.util.Map.Entry; |
| 29 |
|
import java.util.Set; |
| 30 |
|
|
| 31 |
|
import org.slf4j.Logger; |
| 32 |
|
import org.slf4j.LoggerFactory; |
| 33 |
|
import org.xwiki.model.reference.DocumentReferenceResolver; |
| 34 |
|
import org.xwiki.model.reference.EntityReferenceSerializer; |
| 35 |
|
|
| 36 |
|
import com.xpn.xwiki.XWikiContext; |
| 37 |
|
import com.xpn.xwiki.api.Api; |
| 38 |
|
import com.xpn.xwiki.internal.cache.rendering.CachedItem; |
| 39 |
|
import com.xpn.xwiki.internal.cache.rendering.CachedItem.UsedExtension; |
| 40 |
|
import com.xpn.xwiki.internal.cache.rendering.RenderingCacheAware; |
| 41 |
|
import com.xpn.xwiki.plugin.XWikiDefaultPlugin; |
| 42 |
|
import com.xpn.xwiki.plugin.XWikiPluginInterface; |
| 43 |
|
import com.xpn.xwiki.web.Utils; |
| 44 |
|
|
| 45 |
|
|
| 46 |
|
|
| 47 |
|
|
| 48 |
|
|
| 49 |
|
|
| 50 |
|
|
| 51 |
|
@link |
| 52 |
|
|
| 53 |
|
|
| 54 |
|
|
| 55 |
|
|
| 56 |
|
|
| 57 |
|
|
| 58 |
|
@see |
| 59 |
|
@see |
| 60 |
|
@see |
| 61 |
|
@see |
| 62 |
|
@version |
| 63 |
|
|
| 64 |
|
@SuppressWarnings("deprecation") |
| |
|
| 92.4% |
Uncovered Elements: 7 (92) |
Complexity: 26 |
Complexity Density: 0.44 |
|
| 65 |
|
public abstract class AbstractSkinExtensionPlugin extends XWikiDefaultPlugin implements RenderingCacheAware |
| 66 |
|
{ |
| 67 |
|
|
| 68 |
|
private static final Logger LOGGER = LoggerFactory.getLogger(AbstractSkinExtensionPlugin.class); |
| 69 |
|
|
| 70 |
|
|
| 71 |
|
protected final String contextKey = this.getClass().getCanonicalName(); |
| 72 |
|
|
| 73 |
|
|
| 74 |
|
protected final String parametersContextKey = this.getClass().getCanonicalName() + "_parameters"; |
| 75 |
|
|
| 76 |
|
|
| 77 |
|
@see |
| 78 |
|
|
| 79 |
|
private EntityReferenceSerializer<String> defaultEntityReferenceSerializer; |
| 80 |
|
|
| 81 |
|
|
| 82 |
|
@see |
| 83 |
|
|
| 84 |
|
private DocumentReferenceResolver<String> currentDocumentReferenceResolver; |
| 85 |
|
|
| 86 |
|
|
| 87 |
|
|
| 88 |
|
|
| 89 |
|
@param |
| 90 |
|
@param |
| 91 |
|
@param |
| 92 |
|
@see |
| 93 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 94 |
160 |
public AbstractSkinExtensionPlugin(String name, String className, XWikiContext context)... |
| 95 |
|
{ |
| 96 |
160 |
super(name, className, context); |
| 97 |
|
} |
| 98 |
|
|
| 99 |
|
|
| 100 |
|
|
| 101 |
|
|
| 102 |
|
|
| 103 |
|
|
| 104 |
|
|
| 105 |
|
@param |
| 106 |
|
@param |
| 107 |
|
@return |
| 108 |
|
|
| 109 |
|
public abstract String getLink(String resource, XWikiContext context); |
| 110 |
|
|
| 111 |
|
|
| 112 |
|
|
| 113 |
|
|
| 114 |
|
|
| 115 |
|
|
| 116 |
|
@param |
| 117 |
|
@return |
| 118 |
|
|
| 119 |
|
|
| 120 |
|
public abstract Set<String> getAlwaysUsedExtensions(XWikiContext context); |
| 121 |
|
|
| 122 |
|
|
| 123 |
|
|
| 124 |
|
|
| 125 |
|
|
| 126 |
|
@param |
| 127 |
|
@return |
| 128 |
|
|
| 129 |
|
public abstract boolean hasPageExtensions(XWikiContext context); |
| 130 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 131 |
5601 |
@Override... |
| 132 |
|
public Api getPluginApi(XWikiPluginInterface plugin, XWikiContext context) |
| 133 |
|
{ |
| 134 |
5601 |
return new SkinExtensionPluginApi((AbstractSkinExtensionPlugin) plugin, context); |
| 135 |
|
} |
| 136 |
|
|
| 137 |
|
|
| 138 |
|
|
| 139 |
|
|
| 140 |
|
|
| 141 |
|
@param |
| 142 |
|
@param |
| 143 |
|
@see |
| 144 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 145 |
17540 |
public void use(String resource, XWikiContext context)... |
| 146 |
|
{ |
| 147 |
17541 |
LOGGER.debug("Using [{}] as [{}] extension", resource, this.getName()); |
| 148 |
17541 |
getPulledResources(context).add(resource); |
| 149 |
|
|
| 150 |
|
|
| 151 |
17541 |
getParametersMap(context).remove(resource); |
| 152 |
|
} |
| 153 |
|
|
| 154 |
|
|
| 155 |
|
|
| 156 |
|
|
| 157 |
|
|
| 158 |
|
|
| 159 |
|
|
| 160 |
|
|
| 161 |
|
|
| 162 |
|
@param |
| 163 |
|
@param |
| 164 |
|
@param |
| 165 |
|
@see |
| 166 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 167 |
17541 |
public void use(String resource, Map<String, Object> parameters, XWikiContext context)... |
| 168 |
|
{ |
| 169 |
17541 |
use(resource, context); |
| 170 |
17540 |
getParametersMap(context).put(resource, parameters); |
| 171 |
|
} |
| 172 |
|
|
| 173 |
|
|
| 174 |
|
|
| 175 |
|
|
| 176 |
|
|
| 177 |
|
@param |
| 178 |
|
@return |
| 179 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 180 |
56024 |
@SuppressWarnings("unchecked")... |
| 181 |
|
protected Set<String> getPulledResources(XWikiContext context) |
| 182 |
|
{ |
| 183 |
56024 |
initializeRequestListIfNeeded(context); |
| 184 |
56033 |
return (Set<String>) context.get(this.contextKey); |
| 185 |
|
} |
| 186 |
|
|
| 187 |
|
|
| 188 |
|
|
| 189 |
|
|
| 190 |
|
|
| 191 |
|
@param |
| 192 |
|
@return |
| 193 |
|
|
| 194 |
|
|
| 195 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 196 |
99684 |
@SuppressWarnings("unchecked")... |
| 197 |
|
protected Map<String, Map<String, Object>> getParametersMap(XWikiContext context) |
| 198 |
|
{ |
| 199 |
99685 |
initializeRequestListIfNeeded(context); |
| 200 |
99687 |
return (Map<String, Map<String, Object>>) context.get(this.parametersContextKey); |
| 201 |
|
} |
| 202 |
|
|
| 203 |
|
|
| 204 |
|
|
| 205 |
|
|
| 206 |
|
|
| 207 |
|
@param |
| 208 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 3 |
Complexity Density: 0.75 |
|
| 209 |
155711 |
protected void initializeRequestListIfNeeded(XWikiContext context)... |
| 210 |
|
{ |
| 211 |
155716 |
if (!context.containsKey(this.contextKey)) { |
| 212 |
34468 |
context.put(this.contextKey, new LinkedHashSet<String>()); |
| 213 |
|
} |
| 214 |
155712 |
if (!context.containsKey(this.parametersContextKey)) { |
| 215 |
34467 |
context.put(this.parametersContextKey, new HashMap<String, Map<String, Object>>()); |
| 216 |
|
} |
| 217 |
|
} |
| 218 |
|
|
| 219 |
|
|
| 220 |
|
|
| 221 |
|
|
| 222 |
|
|
| 223 |
|
@param |
| 224 |
|
@return |
| 225 |
|
|
| 226 |
|
|
| 227 |
|
|
| 228 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (13) |
Complexity: 2 |
Complexity Density: 0.18 |
|
| 229 |
34462 |
public String getImportString(XWikiContext context)... |
| 230 |
|
{ |
| 231 |
34464 |
StringBuilder result = new StringBuilder(); |
| 232 |
|
|
| 233 |
34458 |
Set<String> extensions = new LinkedHashSet<String>(); |
| 234 |
|
|
| 235 |
|
|
| 236 |
34458 |
extensions.addAll(getAlwaysUsedExtensions(context)); |
| 237 |
|
|
| 238 |
|
|
| 239 |
34459 |
extensions.addAll(getPulledResources(context)); |
| 240 |
|
|
| 241 |
|
|
| 242 |
34462 |
if (hasPageExtensions(context)) { |
| 243 |
|
|
| 244 |
|
|
| 245 |
56 |
EntityReferenceSerializer<String> serializer = getDefaultEntityReferenceSerializer(); |
| 246 |
56 |
String serializedCurrentDocumentName = serializer.serialize(context.getDoc().getDocumentReference()); |
| 247 |
|
|
| 248 |
|
|
| 249 |
56 |
extensions.add(serializedCurrentDocumentName); |
| 250 |
|
} |
| 251 |
|
|
| 252 |
34458 |
for (String documentName : extensions) { |
| 253 |
32568 |
result.append(getLink(documentName, context)); |
| 254 |
|
} |
| 255 |
34459 |
return result.toString(); |
| 256 |
|
} |
| 257 |
|
|
| 258 |
|
|
| 259 |
|
|
| 260 |
|
|
| 261 |
|
|
| 262 |
|
@param |
| 263 |
|
@param |
| 264 |
|
@return |
| 265 |
|
|
| 266 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
| 267 |
60573 |
protected Map<String, Object> getParametersForResource(String resource, XWikiContext context)... |
| 268 |
|
{ |
| 269 |
60572 |
Map<String, Object> result = getParametersMap(context).get(resource); |
| 270 |
60575 |
if (result == null) { |
| 271 |
23209 |
result = Collections.emptyMap(); |
| 272 |
|
} |
| 273 |
60575 |
return result; |
| 274 |
|
} |
| 275 |
|
|
| 276 |
|
|
| 277 |
|
|
| 278 |
|
|
| 279 |
|
@param |
| 280 |
|
@param |
| 281 |
|
@param |
| 282 |
|
@return |
| 283 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 284 |
24991 |
protected Object getParameter(String parameterName, String resource, XWikiContext context)... |
| 285 |
|
{ |
| 286 |
24991 |
return getParametersForResource(resource, context).get(parameterName); |
| 287 |
|
} |
| 288 |
|
|
| 289 |
|
|
| 290 |
|
|
| 291 |
|
@link |
| 292 |
|
|
| 293 |
|
|
| 294 |
|
|
| 295 |
|
@param |
| 296 |
|
@param |
| 297 |
|
@return |
| 298 |
|
|
| |
|
| 87.5% |
Uncovered Elements: 2 (16) |
Complexity: 3 |
Complexity Density: 0.25 |
|
| 299 |
29759 |
protected String parametersAsQueryString(String resource, XWikiContext context)... |
| 300 |
|
{ |
| 301 |
29760 |
Map<String, Object> parameters = getParametersForResource(resource, context); |
| 302 |
29760 |
StringBuilder query = new StringBuilder(); |
| 303 |
29759 |
for (Entry<String, Object> parameter : parameters.entrySet()) { |
| 304 |
|
|
| 305 |
19631 |
if ("forceSkinAction".equals(parameter.getKey())) { |
| 306 |
12462 |
continue; |
| 307 |
|
} |
| 308 |
7169 |
query.append("&"); |
| 309 |
7171 |
query.append(sanitize(parameter.getKey())); |
| 310 |
7172 |
query.append("="); |
| 311 |
7172 |
query.append(sanitize(parameter.getValue().toString())); |
| 312 |
|
} |
| 313 |
|
|
| 314 |
29759 |
if ("false".equals(context.getRequest().getParameter("minify"))) { |
| 315 |
0 |
query.append("&minify=false"); |
| 316 |
|
} |
| 317 |
29759 |
return query.toString(); |
| 318 |
|
} |
| 319 |
|
|
| 320 |
|
|
| 321 |
|
|
| 322 |
|
|
| 323 |
|
|
| 324 |
|
@param |
| 325 |
|
@return |
| 326 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 2 |
Complexity Density: 0.5 |
|
| 327 |
48926 |
protected String sanitize(String value)... |
| 328 |
|
{ |
| 329 |
48926 |
String result = value; |
| 330 |
48927 |
try { |
| 331 |
48926 |
result = URLEncoder.encode(value, "UTF-8"); |
| 332 |
|
} catch (UnsupportedEncodingException ex) { |
| 333 |
|
|
| 334 |
|
|
| 335 |
|
} |
| 336 |
48928 |
return result; |
| 337 |
|
} |
| 338 |
|
|
| 339 |
|
|
| 340 |
|
@inheritDoc |
| 341 |
|
|
| 342 |
|
|
| 343 |
|
|
| 344 |
|
|
| 345 |
|
|
| 346 |
|
@see |
| 347 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 348 |
34459 |
@Override... |
| 349 |
|
public String endParsing(String content, XWikiContext context) |
| 350 |
|
{ |
| 351 |
|
|
| 352 |
|
|
| 353 |
34462 |
String hook = "<!-- " + this.getClass().getCanonicalName() + " -->"; |
| 354 |
34464 |
String result = content.replaceFirst(hook, getImportString(context)); |
| 355 |
34464 |
return result; |
| 356 |
|
} |
| 357 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 358 |
0 |
@Override... |
| 359 |
|
public UsedExtension getCacheResources(XWikiContext context) { |
| 360 |
0 |
return new CachedItem.UsedExtension(getPulledResources(context), |
| 361 |
|
new HashMap<String, Map<String, Object>>(getParametersMap(context))); |
| 362 |
|
} |
| 363 |
|
|
| |
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 364 |
0 |
@Override... |
| 365 |
|
public void restoreCacheResources(XWikiContext context, |
| 366 |
|
UsedExtension extension) { |
| 367 |
0 |
getPulledResources(context).addAll(extension.resources); |
| 368 |
0 |
getParametersMap(context).putAll(extension.parameters); |
| 369 |
|
} |
| 370 |
|
|
| 371 |
|
|
| 372 |
|
|
| 373 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
| 374 |
56 |
protected EntityReferenceSerializer<String> getDefaultEntityReferenceSerializer()... |
| 375 |
|
{ |
| 376 |
56 |
if (this.defaultEntityReferenceSerializer == null) { |
| 377 |
4 |
this.defaultEntityReferenceSerializer = Utils.getComponent(EntityReferenceSerializer.TYPE_STRING); |
| 378 |
|
} |
| 379 |
|
|
| 380 |
56 |
return this.defaultEntityReferenceSerializer; |
| 381 |
|
} |
| 382 |
|
|
| 383 |
|
|
| 384 |
|
|
| 385 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
| 386 |
17295 |
protected DocumentReferenceResolver<String> getCurrentDocumentReferenceResolver()... |
| 387 |
|
{ |
| 388 |
17295 |
if (this.currentDocumentReferenceResolver == null) { |
| 389 |
43 |
this.currentDocumentReferenceResolver = |
| 390 |
|
Utils.getComponent(DocumentReferenceResolver.TYPE_STRING, "current"); |
| 391 |
|
} |
| 392 |
|
|
| 393 |
17295 |
return this.currentDocumentReferenceResolver; |
| 394 |
|
} |
| 395 |
|
} |