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.standard; |
21 |
|
|
22 |
|
import java.util.ArrayList; |
23 |
|
import java.util.Arrays; |
24 |
|
import java.util.Collections; |
25 |
|
import java.util.List; |
26 |
|
|
27 |
|
import javax.inject.Inject; |
28 |
|
import javax.inject.Named; |
29 |
|
import javax.inject.Singleton; |
30 |
|
|
31 |
|
import org.apache.commons.lang3.StringUtils; |
32 |
|
import org.xwiki.component.annotation.Component; |
33 |
|
import org.xwiki.component.phase.Initializable; |
34 |
|
import org.xwiki.configuration.ConfigurationSource; |
35 |
|
import org.xwiki.model.ModelContext; |
36 |
|
import org.xwiki.url.ExtendedURL; |
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
@version |
44 |
|
@since |
45 |
|
|
46 |
|
@Component |
47 |
|
@Named("contextpath+actionservletpath") |
48 |
|
@Singleton |
|
|
| 97.2% |
Uncovered Elements: 1 (36) |
Complexity: 9 |
Complexity Density: 0.41 |
|
49 |
|
public class ContextAndActionURLNormalizer extends org.xwiki.url.internal.container.ContextAndActionURLNormalizer |
50 |
|
implements Initializable |
51 |
|
{ |
52 |
|
|
53 |
|
private static final String URL_SEGMENT_DELIMITER = "/"; |
54 |
|
|
55 |
|
|
56 |
|
@Inject |
57 |
|
@Named("xwikicfg") |
58 |
|
private ConfigurationSource configurationSource; |
59 |
|
|
60 |
|
|
61 |
|
@Inject |
62 |
|
private StandardURLConfiguration urlConfiguration; |
63 |
|
|
64 |
|
@Inject |
65 |
|
private ModelContext context; |
66 |
|
|
67 |
|
|
68 |
|
private String virtualWikiServletMapping; |
69 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
70 |
9 |
@Override... |
71 |
|
public void initialize() |
72 |
|
{ |
73 |
9 |
super.initialize(); |
74 |
9 |
this.virtualWikiServletMapping = this.urlConfiguration.getWikiPathPrefix(); |
75 |
|
} |
76 |
|
|
|
|
| 94.4% |
Uncovered Elements: 1 (18) |
Complexity: 4 |
Complexity Density: 0.33 |
|
77 |
9 |
@Override... |
78 |
|
public ExtendedURL normalize(ExtendedURL partialURL) |
79 |
|
{ |
80 |
9 |
String contextPath = StringUtils.strip(getContextPath(), URL_SEGMENT_DELIMITER); |
81 |
9 |
if (contextPath == null) { |
82 |
1 |
throw new RuntimeException(String.format("Failed to normalize the URL [%s] since the " |
83 |
|
+ "application's Servlet context couldn't be computed.", partialURL)); |
84 |
|
} |
85 |
8 |
List<String> segments = new ArrayList<>(); |
86 |
8 |
if (StringUtils.isNotEmpty(contextPath)) { |
87 |
5 |
segments.add(contextPath); |
88 |
|
} |
89 |
|
|
90 |
8 |
List<String> servletPath = getActionAndWikiServletMapping(); |
91 |
8 |
for (String segment : servletPath) { |
92 |
9 |
if (StringUtils.isNotEmpty(segment)) { |
93 |
9 |
segments.add(segment); |
94 |
|
} |
95 |
|
} |
96 |
|
|
97 |
8 |
segments.addAll(partialURL.getSegments()); |
98 |
|
|
99 |
8 |
return new ExtendedURL(segments, partialURL.getParameters()); |
100 |
|
} |
101 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
102 |
9 |
@Override... |
103 |
|
protected String getContextPath() |
104 |
|
{ |
105 |
|
|
106 |
|
|
107 |
9 |
String contextPath = this.configurationSource.getProperty("xwiki.webapppath"); |
108 |
|
|
109 |
|
|
110 |
9 |
if (contextPath == null) { |
111 |
3 |
contextPath = super.getContextPath(); |
112 |
|
} |
113 |
|
|
114 |
9 |
return contextPath; |
115 |
|
} |
116 |
|
|
117 |
|
|
118 |
|
|
119 |
|
|
120 |
|
|
121 |
|
|
122 |
|
|
123 |
|
@return |
124 |
|
|
125 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
126 |
8 |
protected List<String> getActionAndWikiServletMapping()... |
127 |
|
{ |
128 |
8 |
String result = super.getActionServletMapping(); |
129 |
8 |
if (StringUtils.equals(this.virtualWikiServletMapping, result)) { |
130 |
|
|
131 |
1 |
return Arrays.asList(this.virtualWikiServletMapping, |
132 |
|
this.context.getCurrentEntityReference().getRoot().getName()); |
133 |
|
} |
134 |
|
|
135 |
7 |
return Collections.singletonList(result); |
136 |
|
} |
137 |
|
} |