1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.repository.internal.reference; |
21 |
|
|
22 |
|
import java.io.UnsupportedEncodingException; |
23 |
|
import java.net.URI; |
24 |
|
import java.net.URISyntaxException; |
25 |
|
import java.net.URLDecoder; |
26 |
|
import java.net.URLEncoder; |
27 |
|
|
28 |
|
import org.apache.commons.lang3.StringUtils; |
29 |
|
import org.xwiki.rendering.listener.reference.ResourceReference; |
30 |
|
import org.xwiki.rendering.listener.reference.ResourceType; |
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
@version |
36 |
|
|
|
|
| 61.5% |
Uncovered Elements: 25 (65) |
Complexity: 21 |
Complexity Density: 0.51 |
|
37 |
|
public class ExtensionResourceReference extends ResourceReference |
38 |
|
{ |
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
public static final ResourceType TYPE = new ResourceType("extension"); |
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
public static final String PARAM_REPOSITORYID = "rid"; |
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
public static final String PARAM_REPOSITORYTYPE = "rtype"; |
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
public static final String PARAM_REPOSITORYURI = "ruri"; |
58 |
|
|
59 |
|
|
60 |
|
|
61 |
|
|
62 |
|
private static final String URLENCODING = "UTF-8"; |
63 |
|
|
64 |
|
|
65 |
|
@see |
66 |
|
|
67 |
|
private String extensionId; |
68 |
|
|
69 |
|
|
70 |
|
@see |
71 |
|
|
72 |
|
private String extensionVersion; |
73 |
|
|
74 |
|
|
75 |
|
@see |
76 |
|
|
77 |
|
private String repositoryId; |
78 |
|
|
79 |
|
|
80 |
|
@see |
81 |
|
|
82 |
|
private String repositoryType; |
83 |
|
|
84 |
|
|
85 |
|
@see |
86 |
|
|
87 |
|
private URI repositoryURI; |
88 |
|
|
89 |
|
|
90 |
|
@param |
91 |
|
@param |
92 |
|
@param |
93 |
|
|
|
|
| 83.3% |
Uncovered Elements: 1 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
94 |
6 |
public ExtensionResourceReference(String id, String version, String repositoryId)... |
95 |
|
{ |
96 |
6 |
super(encode(id) + '/' + encode(version) |
97 |
6 |
+ (repositoryId != null ? '?' + PARAM_REPOSITORYID + '=' + encode(repositoryId) : ""), TYPE); |
98 |
|
|
99 |
6 |
this.extensionId = id; |
100 |
6 |
this.extensionVersion = version; |
101 |
|
|
102 |
6 |
this.repositoryId = repositoryId; |
103 |
|
} |
104 |
|
|
105 |
|
|
106 |
|
@param |
107 |
|
@param |
108 |
|
@param |
109 |
|
@param |
110 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 3 |
Complexity Density: 0.6 |
|
111 |
0 |
public ExtensionResourceReference(String id, String version, String repositoryType, URI repositoryURI)... |
112 |
|
{ |
113 |
0 |
super(encode(id) |
114 |
|
+ '/' |
115 |
|
+ encode(version) |
116 |
0 |
+ (repositoryType != null && repositoryURI != null ? '?' + PARAM_REPOSITORYTYPE + '=' |
117 |
|
+ encode(repositoryType) + '&' + PARAM_REPOSITORYURI + '=' + encode(repositoryURI.toString()) : ""), |
118 |
|
TYPE); |
119 |
|
|
120 |
0 |
this.extensionId = id; |
121 |
0 |
this.extensionVersion = version; |
122 |
|
|
123 |
0 |
this.repositoryType = repositoryType; |
124 |
0 |
this.repositoryURI = repositoryURI; |
125 |
|
} |
126 |
|
|
127 |
|
|
128 |
|
@param |
129 |
|
|
|
|
| 54.8% |
Uncovered Elements: 14 (31) |
Complexity: 7 |
Complexity Density: 0.33 |
|
130 |
8 |
public ExtensionResourceReference(String reference)... |
131 |
|
{ |
132 |
8 |
super(reference, TYPE); |
133 |
|
|
134 |
|
|
135 |
8 |
int queryStringIndex = reference.indexOf('?'); |
136 |
|
|
137 |
8 |
if (queryStringIndex != -1) { |
138 |
8 |
String[] parameters = StringUtils.split(reference.substring(queryStringIndex + 1), '&'); |
139 |
8 |
for (String parameter : parameters) { |
140 |
8 |
int equalIndex = parameter.indexOf('='); |
141 |
|
|
142 |
8 |
String parameterName = parameter.substring(0, equalIndex); |
143 |
8 |
String parameterValue = parameter.substring(equalIndex + 1); |
144 |
|
|
145 |
8 |
if (PARAM_REPOSITORYID.equals(parameterName)) { |
146 |
8 |
this.repositoryId = parameterValue; |
147 |
0 |
} else if (PARAM_REPOSITORYTYPE.equals(parameterName)) { |
148 |
0 |
this.repositoryType = parameterValue; |
149 |
0 |
} else if (PARAM_REPOSITORYURI.equals(parameterName)) { |
150 |
0 |
try { |
151 |
0 |
this.repositoryURI = new URI(parameterValue); |
152 |
|
} catch (URISyntaxException e) { |
153 |
|
|
154 |
|
} |
155 |
|
} |
156 |
|
} |
157 |
|
} else { |
158 |
0 |
queryStringIndex = reference.length(); |
159 |
|
} |
160 |
|
|
161 |
|
|
162 |
8 |
int index = reference.indexOf('/'); |
163 |
|
|
164 |
8 |
if (index == -1) { |
165 |
0 |
this.extensionId = decode(reference.substring(0, queryStringIndex)); |
166 |
|
} else { |
167 |
8 |
this.extensionId = decode(reference.substring(0, index)); |
168 |
8 |
this.extensionVersion = decode(reference.substring(index + 1, queryStringIndex)); |
169 |
|
} |
170 |
|
} |
171 |
|
|
172 |
|
|
173 |
|
@param |
174 |
|
@return |
175 |
|
|
|
|
| 66.7% |
Uncovered Elements: 1 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
|
176 |
18 |
private static String encode(String str)... |
177 |
|
{ |
178 |
18 |
try { |
179 |
18 |
return URLEncoder.encode(str, URLENCODING); |
180 |
|
} catch (UnsupportedEncodingException e) { |
181 |
|
|
182 |
0 |
throw new RuntimeException("UTF-8 encoding is not supported"); |
183 |
|
} |
184 |
|
} |
185 |
|
|
186 |
|
|
187 |
|
@param |
188 |
|
@return |
189 |
|
|
|
|
| 66.7% |
Uncovered Elements: 1 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
|
190 |
16 |
private static String decode(String str)... |
191 |
|
{ |
192 |
16 |
try { |
193 |
16 |
return URLDecoder.decode(str, URLENCODING); |
194 |
|
} catch (UnsupportedEncodingException e) { |
195 |
|
|
196 |
0 |
throw new RuntimeException("UTF-8 dencoding is not supported"); |
197 |
|
} |
198 |
|
} |
199 |
|
|
200 |
|
|
201 |
|
@return |
202 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
203 |
5 |
public String getExtensionId()... |
204 |
|
{ |
205 |
5 |
return this.extensionId; |
206 |
|
} |
207 |
|
|
208 |
|
|
209 |
|
@return |
210 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
211 |
5 |
public String getExtensionVersion()... |
212 |
|
{ |
213 |
5 |
return this.extensionVersion; |
214 |
|
} |
215 |
|
|
216 |
|
|
217 |
|
@return |
218 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
219 |
10 |
public String getRepositoryId()... |
220 |
|
{ |
221 |
10 |
return this.repositoryId; |
222 |
|
} |
223 |
|
|
224 |
|
|
225 |
|
@return |
226 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
227 |
2 |
public String getRepositoryType()... |
228 |
|
{ |
229 |
2 |
return this.repositoryType; |
230 |
|
} |
231 |
|
|
232 |
|
|
233 |
|
@return |
234 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
235 |
2 |
public URI getRepositoryURI()... |
236 |
|
{ |
237 |
2 |
return this.repositoryURI; |
238 |
|
} |
239 |
|
} |