1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
package org.devacfr.maven.skins.reflow; |
20 |
|
|
21 |
|
import java.net.URI; |
22 |
|
|
23 |
|
import javax.annotation.Nonnull; |
24 |
|
import javax.annotation.Nullable; |
25 |
|
|
26 |
|
import org.apache.maven.doxia.site.inheritance.URIPathDescriptor; |
27 |
|
import org.apache.velocity.tools.config.DefaultKey; |
28 |
|
|
29 |
|
import com.google.common.base.Strings; |
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
@author |
35 |
|
@since |
36 |
|
|
37 |
|
|
38 |
|
@SuppressWarnings({ "checkstyle:finalclass", "checkstyle:hideutilityclassconstructor" }) |
39 |
|
@DefaultKey("uriTool") |
|
|
| 100% |
Uncovered Elements: 0 (23) |
Complexity: 9 |
Complexity Density: 0,69 |
|
40 |
|
public class URITool { |
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
@param |
53 |
|
|
54 |
|
@param |
55 |
|
|
56 |
|
@return |
57 |
|
@since |
58 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 4 |
Complexity Density: 0,67 |
|
59 |
107 |
@Nullable public static String relativizeLink(@Nullable final String baseDirUri, @Nullable final String link) {... |
60 |
|
|
61 |
|
|
62 |
|
|
63 |
107 |
if (link == null || baseDirUri == null) { |
64 |
1 |
return link; |
65 |
|
} |
66 |
106 |
try { |
67 |
106 |
final URIPathDescriptor path = new URIPathDescriptor(baseDirUri, link); |
68 |
105 |
return normalisedBaseUrl(path.relativizeLink().toString()); |
69 |
|
} catch (final IllegalArgumentException e) { |
70 |
1 |
return link; |
71 |
|
} |
72 |
|
} |
73 |
|
|
74 |
|
|
75 |
|
|
76 |
|
|
77 |
|
@param |
78 |
|
|
79 |
|
@return |
80 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
81 |
201 |
@Nonnull... |
82 |
|
public static URI toURI(@Nonnull final String uri) { |
83 |
201 |
return URI.create(uri); |
84 |
|
} |
85 |
|
|
86 |
|
|
87 |
|
@param |
88 |
|
|
89 |
|
|
90 |
|
|
91 |
|
@param |
92 |
|
|
93 |
|
@return@link |
94 |
|
|
95 |
|
@see |
96 |
|
@see |
97 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
98 |
2 |
public static URLRebaser createURLRebaser(@Nullable final String parentBaseUrl,... |
99 |
|
@Nullable final String childBaseUrl) { |
100 |
2 |
return new URLRebaser(parentBaseUrl, childBaseUrl); |
101 |
|
} |
102 |
|
|
103 |
|
|
104 |
|
|
105 |
|
|
106 |
|
@param |
107 |
|
|
108 |
|
@return |
109 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 3 |
Complexity Density: 0,6 |
|
110 |
106 |
@Nullable public static String normalisedBaseUrl(@Nullable final String baseUrl) {... |
111 |
106 |
if (Strings.isNullOrEmpty(baseUrl)) { |
112 |
1 |
return baseUrl; |
113 |
|
} |
114 |
105 |
if (baseUrl.endsWith("/")) { |
115 |
31 |
return baseUrl.substring(0, baseUrl.length() - 1); |
116 |
|
} |
117 |
|
|
118 |
74 |
return baseUrl; |
119 |
|
} |
120 |
|
|
121 |
|
|
122 |
|
|
123 |
|
|
124 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (18) |
Complexity: 7 |
Complexity Density: 0,7 |
|
125 |
|
public static class URLRebaser { |
126 |
|
|
127 |
|
|
128 |
|
private final String oldPath; |
129 |
|
|
130 |
|
|
131 |
|
private final String newPath; |
132 |
|
|
133 |
|
|
134 |
|
|
135 |
|
|
136 |
|
@param |
137 |
|
|
138 |
|
|
139 |
|
|
140 |
|
@param |
141 |
|
|
142 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
143 |
4 |
protected URLRebaser(@Nullable final String oldPath, @Nullable final String newPath) {... |
144 |
4 |
this.oldPath = oldPath; |
145 |
4 |
this.newPath = newPath; |
146 |
|
} |
147 |
|
|
148 |
|
|
149 |
|
|
150 |
|
|
151 |
|
@return |
152 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
153 |
2 |
@Nullable public String getNewPath() {... |
154 |
2 |
return this.newPath; |
155 |
|
} |
156 |
|
|
157 |
|
|
158 |
|
|
159 |
|
|
160 |
|
@return |
161 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
162 |
6 |
@Nullable public String getOldPath() {... |
163 |
6 |
return this.oldPath; |
164 |
|
} |
165 |
|
|
166 |
|
|
167 |
|
|
168 |
|
|
169 |
|
|
170 |
|
@param |
171 |
|
|
172 |
|
@return@link |
173 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 4 |
Complexity Density: 0,67 |
|
174 |
4 |
public String rebaseLink(@Nullable final String link) {... |
175 |
4 |
if (link == null || getOldPath() == null) { |
176 |
1 |
return link; |
177 |
|
} |
178 |
|
|
179 |
3 |
if (link.contains("${project.")) { |
180 |
1 |
throw new IllegalArgumentException("site.xml late interpolation ${project.*} expression found" |
181 |
|
+ " in link: '" + link + "'. Use early interpolation ${this.*}"); |
182 |
|
} |
183 |
|
|
184 |
2 |
final URIPathDescriptor oldPath = new URIPathDescriptor(getOldPath(), link); |
185 |
|
|
186 |
2 |
return oldPath.rebaseLink(getNewPath()).toString(); |
187 |
|
} |
188 |
|
} |
189 |
|
} |