| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
package com.xpn.xwiki.web; |
| 21 |
|
|
| 22 |
|
import java.net.MalformedURLException; |
| 23 |
|
import java.net.URI; |
| 24 |
|
import java.net.URISyntaxException; |
| 25 |
|
import java.net.URL; |
| 26 |
|
import java.net.URLEncoder; |
| 27 |
|
import java.util.Collections; |
| 28 |
|
import java.util.List; |
| 29 |
|
|
| 30 |
|
import org.apache.commons.lang3.StringUtils; |
| 31 |
|
import org.apache.commons.lang3.exception.ExceptionUtils; |
| 32 |
|
import org.slf4j.Logger; |
| 33 |
|
import org.slf4j.LoggerFactory; |
| 34 |
|
import org.xwiki.model.EntityType; |
| 35 |
|
import org.xwiki.model.reference.DocumentReference; |
| 36 |
|
import org.xwiki.model.reference.EntityReference; |
| 37 |
|
import org.xwiki.model.reference.EntityReferenceResolver; |
| 38 |
|
import org.xwiki.model.reference.EntityReferenceSerializer; |
| 39 |
|
import org.xwiki.resource.internal.entity.EntityResourceActionLister; |
| 40 |
|
|
| 41 |
|
import com.xpn.xwiki.XWiki; |
| 42 |
|
import com.xpn.xwiki.XWikiContext; |
| 43 |
|
import com.xpn.xwiki.XWikiException; |
| 44 |
|
import com.xpn.xwiki.doc.DeletedAttachment; |
| 45 |
|
import com.xpn.xwiki.doc.XWikiAttachment; |
| 46 |
|
import com.xpn.xwiki.doc.XWikiDocument; |
| 47 |
|
|
| |
|
| 79.2% |
Uncovered Elements: 66 (317) |
Complexity: 102 |
Complexity Density: 0.49 |
|
| 48 |
|
public class XWikiServletURLFactory extends XWikiDefaultURLFactory |
| 49 |
|
{ |
| 50 |
|
private static final Logger LOGGER = LoggerFactory.getLogger(XWikiServletURLFactory.class); |
| 51 |
|
|
| 52 |
|
private EntityReferenceResolver<String> relativeEntityReferenceResolver = |
| 53 |
|
Utils.getComponent(EntityReferenceResolver.TYPE_STRING, "relative"); |
| 54 |
|
|
| 55 |
|
private EntityResourceActionLister actionLister = Utils.getComponent(EntityResourceActionLister.class); |
| 56 |
|
|
| 57 |
|
|
| 58 |
|
|
| 59 |
|
|
| 60 |
|
|
| 61 |
|
protected URL serverURL; |
| 62 |
|
|
| 63 |
|
protected String contextPath; |
| 64 |
|
|
| |
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 65 |
11643 |
public XWikiServletURLFactory()... |
| 66 |
|
{ |
| 67 |
|
} |
| 68 |
|
|
| 69 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 70 |
36 |
public XWikiServletURLFactory(URL serverURL, String contextPath, String actionPath)... |
| 71 |
|
{ |
| 72 |
36 |
this.serverURL = serverURL; |
| 73 |
36 |
this.contextPath = contextPath; |
| 74 |
|
} |
| 75 |
|
|
| 76 |
|
|
| 77 |
|
|
| 78 |
|
@link |
| 79 |
|
|
| 80 |
|
|
| 81 |
|
@param |
| 82 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 83 |
8 |
public XWikiServletURLFactory(XWikiContext context)... |
| 84 |
|
{ |
| 85 |
8 |
init(context); |
| 86 |
|
} |
| 87 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
|
| 88 |
11652 |
@Override... |
| 89 |
|
public void init(XWikiContext context) |
| 90 |
|
{ |
| 91 |
11656 |
this.contextPath = context.getWiki().getWebAppPath(context); |
| 92 |
11643 |
try { |
| 93 |
11652 |
this.serverURL = new URL(getProtocol(context) + "://" + getHost(context)); |
| 94 |
|
} catch (MalformedURLException e) { |
| 95 |
|
|
| 96 |
|
} |
| 97 |
|
} |
| 98 |
|
|
| 99 |
|
|
| 100 |
|
|
| 101 |
|
|
| 102 |
|
@return |
| 103 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 104 |
0 |
public String getContextPath()... |
| 105 |
|
{ |
| 106 |
0 |
return this.contextPath; |
| 107 |
|
} |
| 108 |
|
|
| 109 |
|
|
| 110 |
|
@param |
| 111 |
|
@return |
| 112 |
|
|
| 113 |
|
|
| 114 |
|
|
| |
|
| 90% |
Uncovered Elements: 1 (10) |
Complexity: 4 |
Complexity Density: 0.67 |
|
| 115 |
11621 |
private String getProtocol(XWikiContext context)... |
| 116 |
|
{ |
| 117 |
|
|
| 118 |
11641 |
String protocol = context.getURL().getProtocol(); |
| 119 |
11644 |
if (context.getRequest() != null) { |
| 120 |
11637 |
protocol = context.getRequest().getScheme(); |
| 121 |
11640 |
if ("http".equalsIgnoreCase(protocol) && context.getRequest().isSecure()) { |
| 122 |
|
|
| 123 |
|
|
| 124 |
4 |
protocol = "https"; |
| 125 |
|
} |
| 126 |
|
} |
| 127 |
|
|
| 128 |
11635 |
return context.getWiki().Param("xwiki.url.protocol", protocol); |
| 129 |
|
} |
| 130 |
|
|
| 131 |
|
|
| 132 |
|
@param |
| 133 |
|
@return |
| 134 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (14) |
Complexity: 5 |
Complexity Density: 0.62 |
|
| 135 |
11647 |
private String getHost(XWikiContext context)... |
| 136 |
|
{ |
| 137 |
11658 |
URL url = context.getURL(); |
| 138 |
|
|
| 139 |
|
|
| 140 |
11656 |
String proxyHost = StringUtils.substringBefore(context.getRequest().getHeader("x-forwarded-host"), ","); |
| 141 |
11652 |
if (!StringUtils.isEmpty(proxyHost)) { |
| 142 |
6 |
return proxyHost; |
| 143 |
|
} |
| 144 |
|
|
| 145 |
|
|
| 146 |
11636 |
final URL homeParam = getXWikiHomeParameter(context); |
| 147 |
11650 |
if (homeParam != null && context.isMainWiki()) { |
| 148 |
2 |
url = homeParam; |
| 149 |
|
} |
| 150 |
|
|
| 151 |
11628 |
return url.getHost() + (url.getPort() < 0 ? "" : (":" + url.getPort())); |
| 152 |
|
} |
| 153 |
|
|
| 154 |
|
@return |
| |
|
| 87.5% |
Uncovered Elements: 1 (8) |
Complexity: 3 |
Complexity Density: 0.5 |
|
| 155 |
11684 |
private static URL getXWikiHomeParameter(final XWikiContext context)... |
| 156 |
|
{ |
| 157 |
11689 |
final String surl = getXWikiHomeParameterAsString(context); |
| 158 |
11716 |
if (!StringUtils.isEmpty(surl)) { |
| 159 |
6 |
try { |
| 160 |
6 |
return normalizeURL(surl, context); |
| 161 |
|
} catch (MalformedURLException e) { |
| 162 |
0 |
LOGGER.warn("Could not create URL from xwiki.cfg xwiki.home parameter: " + surl |
| 163 |
|
+ " Ignoring parameter."); |
| 164 |
|
} |
| 165 |
|
} |
| 166 |
11707 |
return null; |
| 167 |
|
} |
| 168 |
|
|
| 169 |
|
@return |
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 170 |
11683 |
private static String getXWikiHomeParameterAsString(final XWikiContext context)... |
| 171 |
|
{ |
| 172 |
11693 |
return context.getWiki().Param("xwiki.home", null); |
| 173 |
|
} |
| 174 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 175 |
41929 |
@Override... |
| 176 |
|
public URL getServerURL(XWikiContext context) throws MalformedURLException |
| 177 |
|
{ |
| 178 |
41925 |
return getServerURL(context.getWikiId(), context); |
| 179 |
|
} |
| 180 |
|
|
| 181 |
|
|
| 182 |
|
|
| 183 |
|
|
| 184 |
|
|
| 185 |
|
|
| 186 |
|
@param |
| 187 |
|
|
| 188 |
|
@param |
| 189 |
|
|
| 190 |
|
@return |
| 191 |
|
|
| 192 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (16) |
Complexity: 6 |
Complexity Density: 0.75 |
|
| 193 |
139890 |
public URL getServerURL(String wikiId, XWikiContext context) throws MalformedURLException... |
| 194 |
|
{ |
| 195 |
139889 |
if (wikiId == null || wikiId.equals(context.getOriginalWikiId())) { |
| 196 |
|
|
| 197 |
|
|
| 198 |
130283 |
return this.serverURL; |
| 199 |
|
} |
| 200 |
|
|
| 201 |
9602 |
if (context.isMainWiki(wikiId)) { |
| 202 |
|
|
| 203 |
|
|
| 204 |
62 |
final URL homeParam = getXWikiHomeParameter(context); |
| 205 |
62 |
if (homeParam != null) { |
| 206 |
2 |
return homeParam; |
| 207 |
|
} |
| 208 |
|
} |
| 209 |
|
|
| 210 |
9600 |
URL url = context.getWiki().getServerURL(wikiId, context); |
| 211 |
9600 |
return url == null ? this.serverURL : url; |
| 212 |
|
} |
| 213 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 214 |
0 |
@Override... |
| 215 |
|
public URL createURL(String spaces, String name, String action, boolean redirect, XWikiContext context) |
| 216 |
|
{ |
| 217 |
0 |
return createURL(spaces, name, action, context); |
| 218 |
|
} |
| 219 |
|
|
| |
|
| 72.7% |
Uncovered Elements: 9 (33) |
Complexity: 8 |
Complexity Density: 0.35 |
|
| 220 |
93239 |
@Override... |
| 221 |
|
public URL createURL(String spaces, String name, String action, String querystring, String anchor, String xwikidb, |
| 222 |
|
XWikiContext context) |
| 223 |
|
{ |
| 224 |
|
|
| 225 |
93233 |
if (("view".equals(action)) && (context.getLinksAction() != null)) { |
| 226 |
0 |
action = context.getLinksAction(); |
| 227 |
|
} |
| 228 |
93235 |
if (context.getLinksQueryString() != null) { |
| 229 |
0 |
if (querystring == null) { |
| 230 |
0 |
querystring = context.getLinksQueryString(); |
| 231 |
|
} else { |
| 232 |
0 |
querystring = querystring + "&" + context.getLinksQueryString(); |
| 233 |
|
} |
| 234 |
|
} |
| 235 |
|
|
| 236 |
93237 |
StringBuilder path = new StringBuilder(this.contextPath); |
| 237 |
93237 |
addServletPath(path, xwikidb, context); |
| 238 |
|
|
| 239 |
|
|
| 240 |
93235 |
EntityReference spaceReference = this.relativeEntityReferenceResolver.resolve(spaces, EntityType.SPACE); |
| 241 |
|
|
| 242 |
|
|
| 243 |
93237 |
addAction(path, spaceReference, action, context); |
| 244 |
93238 |
addSpaces(path, spaceReference, action, context); |
| 245 |
93238 |
addName(path, name, action, context); |
| 246 |
|
|
| 247 |
93239 |
if (!StringUtils.isEmpty(querystring)) { |
| 248 |
37117 |
path.append("?"); |
| 249 |
37117 |
path.append(StringUtils.removeEnd(StringUtils.removeEnd(querystring, "&"), "&")); |
| 250 |
|
} |
| 251 |
|
|
| 252 |
93236 |
if (!StringUtils.isEmpty(anchor)) { |
| 253 |
24 |
path.append("#"); |
| 254 |
24 |
path.append(encodeWithinQuery(anchor, context)); |
| 255 |
|
} |
| 256 |
|
|
| 257 |
93238 |
URL result; |
| 258 |
93237 |
try { |
| 259 |
93234 |
result = normalizeURL(new URL(getServerURL(xwikidb, context), path.toString()), context); |
| 260 |
|
} catch (MalformedURLException e) { |
| 261 |
|
|
| 262 |
0 |
result = null; |
| 263 |
|
} |
| 264 |
|
|
| 265 |
93237 |
return result; |
| 266 |
|
} |
| 267 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
| 268 |
111222 |
private void addServletPath(StringBuilder path, String xwikidb, XWikiContext context)... |
| 269 |
|
{ |
| 270 |
111224 |
if (xwikidb == null) { |
| 271 |
2 |
xwikidb = context.getWikiId(); |
| 272 |
|
} |
| 273 |
|
|
| 274 |
111220 |
path.append(context.getWiki().getServletPath(xwikidb, context)); |
| 275 |
|
} |
| 276 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 7 |
Complexity Density: 2.33 |
|
| 277 |
111215 |
private void addAction(StringBuilder path, EntityReference spaceReference, String action, XWikiContext context)... |
| 278 |
|
{ |
| 279 |
111216 |
boolean showViewAction = context.getWiki().showViewAction(context); |
| 280 |
|
|
| 281 |
|
|
| 282 |
|
|
| 283 |
|
|
| 284 |
111221 |
if ((!"view".equals(action) || (showViewAction)) |
| 285 |
|
|| (!showViewAction && spaceReference != null && "view".equals(action) |
| 286 |
|
&& this.actionLister.listActions().contains( |
| 287 |
|
spaceReference.extractFirstReference(EntityType.SPACE).getName()))) |
| 288 |
|
{ |
| 289 |
111218 |
path.append(action).append("/"); |
| 290 |
|
} |
| 291 |
|
} |
| 292 |
|
|
| 293 |
|
|
| 294 |
|
|
| 295 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 296 |
97965 |
private void addSpaces(StringBuilder path, EntityReference spaceReference, String action, XWikiContext context)... |
| 297 |
|
{ |
| 298 |
97963 |
for (EntityReference reference : spaceReference.getReversedReferenceChain()) { |
| 299 |
107986 |
appendSpacePathSegment(path, reference, context); |
| 300 |
|
} |
| 301 |
|
} |
| 302 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 303 |
107978 |
private void appendSpacePathSegment(StringBuilder path, EntityReference spaceReference, XWikiContext context)... |
| 304 |
|
{ |
| 305 |
107981 |
path.append(encodeWithinPath(spaceReference.getName(), context)).append('/'); |
| 306 |
|
} |
| 307 |
|
|
| 308 |
|
|
| 309 |
|
|
| 310 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 4 |
Complexity Density: 1.33 |
|
| 311 |
97960 |
private void addName(StringBuilder path, String name, String action, XWikiContext context)... |
| 312 |
|
{ |
| 313 |
97956 |
XWiki xwiki = context.getWiki(); |
| 314 |
97968 |
if ((xwiki.useDefaultAction(context)) |
| 315 |
|
|| (!name.equals(xwiki.getDefaultPage(context)) || (!"view".equals(action)))) { |
| 316 |
70056 |
path.append(encodeWithinPath(name, context)); |
| 317 |
|
} |
| 318 |
|
} |
| 319 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 320 |
398 |
protected void addFileName(StringBuilder path, String fileName, XWikiContext context)... |
| 321 |
|
{ |
| 322 |
398 |
addFileName(path, fileName, true, context); |
| 323 |
|
} |
| 324 |
|
|
| |
|
| 77.8% |
Uncovered Elements: 2 (9) |
Complexity: 3 |
Complexity Density: 0.43 |
|
| 325 |
36967 |
protected void addFileName(StringBuilder path, String fileName, boolean encode, XWikiContext context)... |
| 326 |
|
{ |
| 327 |
36964 |
path.append("/"); |
| 328 |
36965 |
if (encode) { |
| 329 |
|
|
| 330 |
398 |
path.append(encodeWithinPath(fileName, context).replace("+", "%20")); |
| 331 |
|
} else { |
| 332 |
36568 |
try { |
| 333 |
|
|
| 334 |
36568 |
path.append(new URI(null, null, fileName, null)); |
| 335 |
|
} catch (URISyntaxException e) { |
| 336 |
0 |
LOGGER.debug("Failed to encode the file path [{}]. Root cause: [{}]", fileName, |
| 337 |
|
ExceptionUtils.getRootCauseMessage(e)); |
| 338 |
|
|
| 339 |
0 |
path.append(fileName); |
| 340 |
|
} |
| 341 |
|
} |
| 342 |
|
} |
| 343 |
|
|
| 344 |
|
|
| 345 |
|
|
| 346 |
|
|
| 347 |
|
|
| 348 |
|
|
| 349 |
|
|
| 350 |
|
|
| 351 |
|
|
| 352 |
|
|
| 353 |
|
|
| 354 |
|
|
| 355 |
|
|
| 356 |
|
|
| 357 |
|
|
| 358 |
|
@param |
| 359 |
|
@param@link |
| 360 |
|
@return |
| 361 |
|
|
| |
|
| 83.3% |
Uncovered Elements: 1 (6) |
Complexity: 2 |
Complexity Density: 0.33 |
|
| 362 |
178461 |
private String encodeWithinPath(String name, XWikiContext context)... |
| 363 |
|
{ |
| 364 |
|
|
| 365 |
|
|
| 366 |
|
|
| 367 |
|
|
| 368 |
|
|
| 369 |
|
|
| 370 |
|
|
| 371 |
|
|
| 372 |
|
|
| 373 |
|
|
| 374 |
178463 |
String encodedName; |
| 375 |
178458 |
try { |
| 376 |
178459 |
encodedName = URLEncoder.encode(name, "UTF-8"); |
| 377 |
|
} catch (Exception e) { |
| 378 |
|
|
| 379 |
0 |
throw new RuntimeException("Missing charset [UTF-8]", e); |
| 380 |
|
} |
| 381 |
|
|
| 382 |
|
|
| 383 |
178458 |
encodedName = encodedName.replaceAll("\\+", "%20"); |
| 384 |
|
|
| 385 |
178463 |
return encodedName; |
| 386 |
|
} |
| 387 |
|
|
| 388 |
|
|
| 389 |
|
@link |
| 390 |
|
|
| 391 |
|
|
| 392 |
|
|
| 393 |
|
@param |
| 394 |
|
@param@link |
| 395 |
|
@return |
| 396 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 397 |
24 |
private String encodeWithinQuery(String name, XWikiContext context)... |
| 398 |
|
{ |
| 399 |
|
|
| 400 |
|
|
| 401 |
|
|
| 402 |
|
|
| 403 |
|
|
| 404 |
|
|
| 405 |
|
|
| 406 |
|
|
| 407 |
|
|
| 408 |
|
|
| 409 |
24 |
return encodeWithinPath(name, context); |
| 410 |
|
} |
| 411 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 412 |
692 |
@Override... |
| 413 |
|
public URL createExternalURL(String spaces, String name, String action, String querystring, String anchor, |
| 414 |
|
String xwikidb, XWikiContext context) |
| 415 |
|
{ |
| 416 |
692 |
return this.createURL(spaces, name, action, querystring, anchor, xwikidb, context); |
| 417 |
|
} |
| 418 |
|
|
| |
|
| 85.7% |
Uncovered Elements: 1 (7) |
Complexity: 2 |
Complexity Density: 0.29 |
|
| 419 |
1267 |
@Override... |
| 420 |
|
public URL createSkinURL(String filename, String skin, XWikiContext context) |
| 421 |
|
{ |
| 422 |
1266 |
StringBuilder path = new StringBuilder(this.contextPath); |
| 423 |
1267 |
path.append("skins/"); |
| 424 |
1266 |
path.append(skin); |
| 425 |
1267 |
addFileName(path, filename, false, context); |
| 426 |
1266 |
try { |
| 427 |
1267 |
return normalizeURL(new URL(getServerURL(context), path.toString()), context); |
| 428 |
|
} catch (MalformedURLException e) { |
| 429 |
|
|
| 430 |
0 |
return null; |
| 431 |
|
} |
| 432 |
|
} |
| 433 |
|
|
| |
|
| 90% |
Uncovered Elements: 1 (10) |
Complexity: 2 |
Complexity Density: 0.2 |
|
| 434 |
4328 |
@Override... |
| 435 |
|
public URL createSkinURL(String filename, String spaces, String name, String xwikidb, XWikiContext context) |
| 436 |
|
{ |
| 437 |
4326 |
StringBuilder path = new StringBuilder(this.contextPath); |
| 438 |
4326 |
addServletPath(path, xwikidb, context); |
| 439 |
|
|
| 440 |
|
|
| 441 |
4328 |
EntityReference spaceReference = this.relativeEntityReferenceResolver.resolve(spaces, EntityType.SPACE); |
| 442 |
|
|
| 443 |
4328 |
addAction(path, null, "skin", context); |
| 444 |
4331 |
addSpaces(path, spaceReference, "skin", context); |
| 445 |
4328 |
addName(path, name, "skin", context); |
| 446 |
4331 |
addFileName(path, filename, false, context); |
| 447 |
4331 |
try { |
| 448 |
4330 |
return normalizeURL(new URL(getServerURL(xwikidb, context), path.toString()), context); |
| 449 |
|
} catch (MalformedURLException e) { |
| 450 |
|
|
| 451 |
0 |
return null; |
| 452 |
|
} |
| 453 |
|
} |
| 454 |
|
|
| |
|
| 90.9% |
Uncovered Elements: 1 (11) |
Complexity: 3 |
Complexity Density: 0.33 |
|
| 455 |
30973 |
@Override... |
| 456 |
|
public URL createResourceURL(String filename, boolean forceSkinAction, XWikiContext context) |
| 457 |
|
{ |
| 458 |
30973 |
StringBuilder path = new StringBuilder(this.contextPath); |
| 459 |
30973 |
if (forceSkinAction) { |
| 460 |
13257 |
addServletPath(path, context.getWikiId(), context); |
| 461 |
13254 |
addAction(path, null, "skin", context); |
| 462 |
|
} |
| 463 |
30971 |
path.append("resources"); |
| 464 |
30971 |
addFileName(path, filename, false, context); |
| 465 |
30971 |
try { |
| 466 |
30972 |
return normalizeURL(new URL(getServerURL(context), path.toString()), context); |
| 467 |
|
} catch (MalformedURLException e) { |
| 468 |
|
|
| 469 |
0 |
return null; |
| 470 |
|
} |
| 471 |
|
} |
| 472 |
|
|
| |
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.33 |
|
| 473 |
0 |
public URL createTemplateURL(String fileName, XWikiContext context)... |
| 474 |
|
{ |
| 475 |
0 |
StringBuilder path = new StringBuilder(this.contextPath); |
| 476 |
0 |
path.append("templates"); |
| 477 |
0 |
addFileName(path, fileName, false, context); |
| 478 |
0 |
try { |
| 479 |
0 |
return normalizeURL(new URL(getServerURL(context), path.toString()), context); |
| 480 |
|
} catch (MalformedURLException e) { |
| 481 |
|
|
| 482 |
0 |
return null; |
| 483 |
|
} |
| 484 |
|
} |
| 485 |
|
|
| |
|
| 74.2% |
Uncovered Elements: 8 (31) |
Complexity: 10 |
Complexity Density: 0.43 |
|
| 486 |
394 |
@Override... |
| 487 |
|
public URL createAttachmentURL(String filename, String spaces, String name, String action, String querystring, |
| 488 |
|
String xwikidb, XWikiContext context) |
| 489 |
|
{ |
| 490 |
394 |
if ((context != null) && "viewrev".equals(context.getAction()) && context.get("rev") != null |
| 491 |
|
&& isContextDoc(xwikidb, spaces, name, context)) { |
| 492 |
1 |
try { |
| 493 |
1 |
String docRevision = context.get("rev").toString(); |
| 494 |
1 |
XWikiAttachment attachment = |
| 495 |
|
findAttachmentForDocRevision(context.getDoc(), docRevision, filename, context); |
| 496 |
1 |
if (attachment == null) { |
| 497 |
1 |
action = "viewattachrev"; |
| 498 |
|
} else { |
| 499 |
0 |
long arbId = findDeletedAttachmentForDocRevision(context.getDoc(), docRevision, filename, context); |
| 500 |
0 |
return createAttachmentRevisionURL(filename, spaces, name, attachment.getVersion(), arbId, |
| 501 |
|
querystring, xwikidb, context); |
| 502 |
|
} |
| 503 |
|
} catch (XWikiException e) { |
| 504 |
0 |
if (LOGGER.isErrorEnabled()) { |
| 505 |
0 |
LOGGER.error("Exception while trying to get attachment version !", e); |
| 506 |
|
} |
| 507 |
|
} |
| 508 |
|
} |
| 509 |
|
|
| 510 |
394 |
StringBuilder path = new StringBuilder(this.contextPath); |
| 511 |
394 |
addServletPath(path, xwikidb, context); |
| 512 |
|
|
| 513 |
|
|
| 514 |
394 |
EntityReference spaceReference = this.relativeEntityReferenceResolver.resolve(spaces, EntityType.SPACE); |
| 515 |
|
|
| 516 |
394 |
addAction(path, spaceReference, action, context); |
| 517 |
394 |
addSpaces(path, spaceReference, action, context); |
| 518 |
394 |
addName(path, name, action, context); |
| 519 |
394 |
addFileName(path, filename, context); |
| 520 |
|
|
| 521 |
394 |
if (!StringUtils.isEmpty(querystring)) { |
| 522 |
75 |
path.append("?"); |
| 523 |
75 |
path.append(StringUtils.removeEnd(StringUtils.removeEnd(querystring, "&"), "&")); |
| 524 |
|
} |
| 525 |
|
|
| 526 |
394 |
try { |
| 527 |
394 |
return normalizeURL(new URL(getServerURL(xwikidb, context), path.toString()), context); |
| 528 |
|
} catch (Exception e) { |
| 529 |
0 |
return null; |
| 530 |
|
} |
| 531 |
|
} |
| 532 |
|
|
| 533 |
|
|
| 534 |
|
|
| 535 |
|
|
| 536 |
|
|
| 537 |
|
@param |
| 538 |
|
@param |
| 539 |
|
@param |
| 540 |
|
@param |
| 541 |
|
@return |
| 542 |
|
|
| 543 |
|
|
| |
|
| 71.4% |
Uncovered Elements: 2 (7) |
Complexity: 3 |
Complexity Density: 0.6 |
|
| 544 |
2 |
protected boolean isContextDoc(String wiki, String spaces, String name, XWikiContext context)... |
| 545 |
|
{ |
| 546 |
2 |
if (context == null || context.getDoc() == null) { |
| 547 |
0 |
return false; |
| 548 |
|
} |
| 549 |
|
|
| 550 |
|
|
| 551 |
|
|
| 552 |
2 |
EntityReferenceSerializer<String> serializer = |
| 553 |
|
Utils.getComponent(EntityReferenceSerializer.TYPE_STRING, "local"); |
| 554 |
2 |
DocumentReference currentDocumentReference = context.getDoc().getDocumentReference(); |
| 555 |
2 |
return serializer.serialize(currentDocumentReference.getLastSpaceReference()).equals(spaces) |
| 556 |
|
&& currentDocumentReference.getName().equals(name) |
| 557 |
|
&& (wiki == null || currentDocumentReference.getWikiReference().getName().equals(wiki)); |
| 558 |
|
} |
| 559 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 560 |
4 |
@Override... |
| 561 |
|
public URL createAttachmentRevisionURL(String filename, String spaces, String name, String revision, |
| 562 |
|
String querystring, String xwikidb, XWikiContext context) |
| 563 |
|
{ |
| 564 |
4 |
return createAttachmentRevisionURL(filename, spaces, name, revision, -1, querystring, xwikidb, context); |
| 565 |
|
} |
| 566 |
|
|
| |
|
| 77.3% |
Uncovered Elements: 5 (22) |
Complexity: 4 |
Complexity Density: 0.22 |
|
| 567 |
4 |
public URL createAttachmentRevisionURL(String filename, String spaces, String name, String revision,... |
| 568 |
|
long recycleId, String querystring, String xwikidb, XWikiContext context) |
| 569 |
|
{ |
| 570 |
4 |
String action = "downloadrev"; |
| 571 |
4 |
StringBuilder path = new StringBuilder(this.contextPath); |
| 572 |
4 |
addServletPath(path, xwikidb, context); |
| 573 |
|
|
| 574 |
|
|
| 575 |
4 |
EntityReference spaceReference = this.relativeEntityReferenceResolver.resolve(spaces, EntityType.SPACE); |
| 576 |
|
|
| 577 |
4 |
addAction(path, spaceReference, action, context); |
| 578 |
4 |
addSpaces(path, spaceReference, action, context); |
| 579 |
4 |
addName(path, name, action, context); |
| 580 |
4 |
addFileName(path, filename, context); |
| 581 |
|
|
| 582 |
4 |
String qstring = "rev=" + revision; |
| 583 |
4 |
if (recycleId >= 0) { |
| 584 |
0 |
qstring += "&rid=" + recycleId; |
| 585 |
|
} |
| 586 |
4 |
if (!StringUtils.isEmpty(querystring)) { |
| 587 |
0 |
qstring += "&" + querystring; |
| 588 |
|
} |
| 589 |
4 |
path.append("?"); |
| 590 |
4 |
path.append(StringUtils.removeEnd(StringUtils.removeEnd(qstring, "&"), "&")); |
| 591 |
|
|
| 592 |
4 |
try { |
| 593 |
4 |
return normalizeURL(new URL(getServerURL(xwikidb, context), path.toString()), context); |
| 594 |
|
} catch (MalformedURLException e) { |
| 595 |
|
|
| 596 |
0 |
return null; |
| 597 |
|
} |
| 598 |
|
} |
| 599 |
|
|
| 600 |
|
|
| 601 |
|
|
| 602 |
|
|
| 603 |
|
|
| 604 |
|
|
| 605 |
|
|
| 606 |
|
|
| 607 |
|
|
| 608 |
|
|
| 609 |
|
|
| 610 |
|
|
| 611 |
|
|
| 612 |
|
|
| 613 |
|
|
| 614 |
|
|
| 615 |
|
|
| 616 |
|
|
| 617 |
|
|
| 618 |
|
|
| 619 |
|
|
| 620 |
|
|
| 621 |
|
@param |
| 622 |
|
@return |
| 623 |
|
@see |
| 624 |
|
|
| |
|
| 91.7% |
Uncovered Elements: 2 (24) |
Complexity: 6 |
Complexity Density: 0.38 |
|
| 625 |
137148 |
@Override... |
| 626 |
|
public String getURL(URL url, XWikiContext context) |
| 627 |
|
{ |
| 628 |
137146 |
String relativeURL = ""; |
| 629 |
|
|
| 630 |
137144 |
try { |
| 631 |
137140 |
if (url != null) { |
| 632 |
137143 |
String surl = url.toString(); |
| 633 |
|
|
| 634 |
137141 |
if (!surl.startsWith(this.serverURL.toString())) { |
| 635 |
|
|
| 636 |
4 |
relativeURL = surl; |
| 637 |
|
} else { |
| 638 |
|
|
| 639 |
137141 |
StringBuilder relativeURLBuilder = new StringBuilder(url.getPath()); |
| 640 |
137136 |
String querystring = url.getQuery(); |
| 641 |
137135 |
if (!StringUtils.isEmpty(querystring)) { |
| 642 |
44060 |
relativeURLBuilder.append("?").append( |
| 643 |
|
StringUtils.removeEnd(StringUtils.removeEnd(querystring, "&"), "&")); |
| 644 |
|
} |
| 645 |
|
|
| 646 |
137134 |
String anchor = url.getRef(); |
| 647 |
137132 |
if (!StringUtils.isEmpty(anchor)) { |
| 648 |
702 |
relativeURLBuilder.append("#").append(anchor); |
| 649 |
|
} |
| 650 |
|
|
| 651 |
137138 |
relativeURL = relativeURLBuilder.toString(); |
| 652 |
|
} |
| 653 |
|
} |
| 654 |
|
} catch (Exception e) { |
| 655 |
0 |
LOGGER.error("Failed to create URL", e); |
| 656 |
|
} |
| 657 |
|
|
| 658 |
137140 |
return StringUtils.defaultIfEmpty(relativeURL, "/"); |
| 659 |
|
} |
| 660 |
|
|
| |
|
| 66.7% |
Uncovered Elements: 2 (6) |
Complexity: 2 |
Complexity Density: 0.33 |
|
| 661 |
8606 |
@Override... |
| 662 |
|
public URL getRequestURL(XWikiContext context) |
| 663 |
|
{ |
| 664 |
8606 |
final URL url = super.getRequestURL(context); |
| 665 |
|
|
| 666 |
8604 |
try { |
| 667 |
8603 |
final URL servurl = getServerURL(context); |
| 668 |
|
|
| 669 |
8605 |
return normalizeURL(new URL(servurl.getProtocol(), servurl.getHost(), servurl.getPort(), url.getFile()), |
| 670 |
|
context); |
| 671 |
|
} catch (MalformedURLException e) { |
| 672 |
|
|
| 673 |
0 |
LOGGER.error("Failed to create request URL", e); |
| 674 |
|
} |
| 675 |
|
|
| 676 |
0 |
return url; |
| 677 |
|
} |
| 678 |
|
|
| |
|
| 85.7% |
Uncovered Elements: 1 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
| 679 |
1 |
public XWikiAttachment findAttachmentForDocRevision(XWikiDocument doc, String docRevision, String filename,... |
| 680 |
|
XWikiContext context) throws XWikiException |
| 681 |
|
{ |
| 682 |
1 |
XWikiAttachment attachment = null; |
| 683 |
1 |
XWikiDocument rdoc = context.getWiki().getDocument(doc, docRevision, context); |
| 684 |
1 |
if (filename != null) { |
| 685 |
1 |
attachment = rdoc.getAttachment(filename); |
| 686 |
|
} |
| 687 |
|
|
| 688 |
1 |
return attachment; |
| 689 |
|
} |
| 690 |
|
|
| |
|
| 0% |
Uncovered Elements: 17 (17) |
Complexity: 5 |
Complexity Density: 0.45 |
|
| 691 |
0 |
public long findDeletedAttachmentForDocRevision(XWikiDocument doc, String docRevision, String filename,... |
| 692 |
|
XWikiContext context) throws XWikiException |
| 693 |
|
{ |
| 694 |
0 |
XWikiAttachment attachment = null; |
| 695 |
0 |
XWikiDocument rdoc = context.getWiki().getDocument(doc, docRevision, context); |
| 696 |
0 |
if (context.getWiki().hasAttachmentRecycleBin(context) && filename != null) { |
| 697 |
0 |
attachment = rdoc.getAttachment(filename); |
| 698 |
0 |
if (attachment != null) { |
| 699 |
0 |
List<DeletedAttachment> deleted = |
| 700 |
|
context.getWiki().getAttachmentRecycleBinStore() |
| 701 |
|
.getAllDeletedAttachments(attachment, context, true); |
| 702 |
0 |
Collections.reverse(deleted); |
| 703 |
0 |
for (DeletedAttachment entry : deleted) { |
| 704 |
0 |
if (entry.getDate().after(rdoc.getDate())) { |
| 705 |
0 |
return entry.getId(); |
| 706 |
|
} |
| 707 |
|
} |
| 708 |
|
} |
| 709 |
|
} |
| 710 |
|
|
| 711 |
0 |
return -1; |
| 712 |
|
} |
| 713 |
|
|
| 714 |
|
|
| 715 |
|
|
| 716 |
|
|
| 717 |
|
|
| 718 |
|
|
| 719 |
|
|
| 720 |
|
|
| 721 |
|
|
| 722 |
|
|
| 723 |
|
|
| 724 |
|
|
| 725 |
|
|
| 726 |
|
|
| 727 |
|
|
| 728 |
|
|
| 729 |
|
|
| 730 |
|
|
| 731 |
|
@param |
| 732 |
|
@param |
| 733 |
|
@return |
| 734 |
|
@throws |
| 735 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 736 |
138806 |
protected static URL normalizeURL(URL url, XWikiContext context) throws MalformedURLException... |
| 737 |
|
{ |
| 738 |
138799 |
return normalizeURL(url.toExternalForm(), context); |
| 739 |
|
} |
| 740 |
|
|
| 741 |
|
|
| 742 |
|
|
| 743 |
|
|
| 744 |
|
|
| 745 |
|
|
| 746 |
|
|
| 747 |
|
|
| 748 |
|
|
| 749 |
|
|
| 750 |
|
|
| 751 |
|
|
| 752 |
|
|
| 753 |
|
|
| 754 |
|
|
| 755 |
|
|
| 756 |
|
|
| 757 |
|
|
| 758 |
|
@param |
| 759 |
|
@param |
| 760 |
|
@return |
| 761 |
|
@throws |
| 762 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 763 |
138810 |
protected static URL normalizeURL(String url, XWikiContext context) throws MalformedURLException... |
| 764 |
|
{ |
| 765 |
|
|
| 766 |
|
|
| 767 |
138807 |
String encodedURLAsString = context.getResponse().encodeURL(url); |
| 768 |
|
|
| 769 |
|
|
| 770 |
138807 |
encodedURLAsString = encodedURLAsString.replaceAll(";jsessionid=.*?(?=\\?|$)", ""); |
| 771 |
|
|
| 772 |
138808 |
return new URL(encodedURLAsString); |
| 773 |
|
} |
| 774 |
|
} |