| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
package org.xwiki.url.internal.container; |
| 21 |
|
|
| 22 |
|
import java.util.ArrayList; |
| 23 |
|
import java.util.List; |
| 24 |
|
|
| 25 |
|
import javax.inject.Inject; |
| 26 |
|
import javax.inject.Named; |
| 27 |
|
import javax.inject.Singleton; |
| 28 |
|
|
| 29 |
|
import org.apache.commons.lang3.StringUtils; |
| 30 |
|
import org.xwiki.component.annotation.Component; |
| 31 |
|
import org.xwiki.configuration.ConfigurationSource; |
| 32 |
|
import org.xwiki.environment.Environment; |
| 33 |
|
import org.xwiki.environment.internal.ServletEnvironment; |
| 34 |
|
import org.xwiki.url.ExtendedURL; |
| 35 |
|
import org.xwiki.url.URLNormalizer; |
| 36 |
|
|
| 37 |
|
|
| 38 |
|
|
| 39 |
|
|
| 40 |
|
|
| 41 |
|
@version |
| 42 |
|
@since |
| 43 |
|
|
| 44 |
|
@Component |
| 45 |
|
@Named("contextpath") |
| 46 |
|
@Singleton |
| |
|
| 100% |
Uncovered Elements: 0 (28) |
Complexity: 8 |
Complexity Density: 0.5 |
|
| 47 |
|
public class ExtendedURLURLNormalizer implements URLNormalizer<ExtendedURL> |
| 48 |
|
{ |
| 49 |
|
private static final String URL_SEGMENT_DELIMITER = "/"; |
| 50 |
|
|
| 51 |
|
@Inject |
| 52 |
|
@Named("xwikicfg") |
| 53 |
|
private ConfigurationSource configurationSource; |
| 54 |
|
|
| 55 |
|
|
| 56 |
|
@Inject |
| 57 |
|
private Environment environment; |
| 58 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 3 |
Complexity Density: 0.38 |
|
| 59 |
25724 |
@Override... |
| 60 |
|
public ExtendedURL normalize(ExtendedURL partialURL) |
| 61 |
|
{ |
| 62 |
25723 |
String contextPath = StringUtils.strip(getContextPath(), URL_SEGMENT_DELIMITER); |
| 63 |
|
|
| 64 |
25724 |
if (contextPath == null) { |
| 65 |
1 |
throw new RuntimeException(String.format("Failed to normalize the URL [%s] since the " |
| 66 |
|
+ "application's Servlet context couldn't be computed.", partialURL)); |
| 67 |
|
} |
| 68 |
|
|
| 69 |
25721 |
List<String> segments = new ArrayList<>(); |
| 70 |
25721 |
if (StringUtils.isNotEmpty(contextPath)) { |
| 71 |
25720 |
segments.add(contextPath); |
| 72 |
|
} |
| 73 |
25721 |
segments.addAll(partialURL.getSegments()); |
| 74 |
|
|
| 75 |
25723 |
return new ExtendedURL(segments, partialURL.getParameters()); |
| 76 |
|
} |
| 77 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
| 78 |
25723 |
private String getContextPath()... |
| 79 |
|
{ |
| 80 |
25723 |
String contextPath = getContextPathFromConfiguration(); |
| 81 |
|
|
| 82 |
|
|
| 83 |
25724 |
if (contextPath == null) { |
| 84 |
25720 |
contextPath = getContextPathFromApplicationContext(); |
| 85 |
|
} |
| 86 |
|
|
| 87 |
25724 |
return contextPath; |
| 88 |
|
} |
| 89 |
|
|
| 90 |
|
|
| 91 |
|
|
| 92 |
|
|
| 93 |
|
|
| 94 |
|
@return |
| 95 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 96 |
25723 |
private String getContextPathFromConfiguration()... |
| 97 |
|
{ |
| 98 |
25724 |
return this.configurationSource.getProperty("xwiki.webapppath"); |
| 99 |
|
} |
| 100 |
|
|
| 101 |
|
|
| 102 |
|
|
| 103 |
|
|
| 104 |
|
@return |
| 105 |
|
|
| 106 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
| 107 |
25719 |
private String getContextPathFromApplicationContext()... |
| 108 |
|
{ |
| 109 |
25719 |
if (this.environment instanceof ServletEnvironment) { |
| 110 |
25719 |
return ((ServletEnvironment) this.environment).getServletContext().getContextPath(); |
| 111 |
|
} |
| 112 |
1 |
return null; |
| 113 |
|
} |
| 114 |
|
} |