1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.rest.script; |
21 |
|
|
22 |
|
import java.net.URL; |
23 |
|
|
24 |
|
import javax.inject.Inject; |
25 |
|
import javax.inject.Named; |
26 |
|
import javax.inject.Singleton; |
27 |
|
|
28 |
|
import org.xwiki.component.annotation.Component; |
29 |
|
import org.xwiki.context.Execution; |
30 |
|
import org.xwiki.model.EntityType; |
31 |
|
import org.xwiki.model.reference.EntityReference; |
32 |
|
import org.xwiki.rest.XWikiRestException; |
33 |
|
import org.xwiki.rest.url.RestURLGenerator; |
34 |
|
import org.xwiki.script.service.ScriptService; |
35 |
|
import org.xwiki.wiki.descriptor.WikiDescriptorManager; |
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
@version |
41 |
|
@since |
42 |
|
|
43 |
|
@Component |
44 |
|
@Named("rest") |
45 |
|
@Singleton |
|
|
| 52.9% |
Uncovered Elements: 8 (17) |
Complexity: 8 |
Complexity Density: 0.73 |
|
46 |
|
public class RESTScriptService implements ScriptService |
47 |
|
{ |
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
private static final String ERROR_KEY = "scriptservice.rest.error"; |
52 |
|
|
53 |
|
@Inject |
54 |
|
private RestURLGenerator restURLGenerator; |
55 |
|
|
56 |
|
@Inject |
57 |
|
private Execution execution; |
58 |
|
|
59 |
|
@Inject |
60 |
|
private WikiDescriptorManager wikis; |
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
|
65 |
|
|
66 |
|
|
67 |
|
@param |
68 |
|
@return |
69 |
|
@since |
70 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
71 |
1083 |
public String url(EntityReference reference)... |
72 |
|
{ |
73 |
1083 |
return url(reference, false); |
74 |
|
} |
75 |
|
|
76 |
|
|
77 |
|
|
78 |
|
|
79 |
|
|
80 |
|
|
81 |
|
|
82 |
|
@param |
83 |
|
@param |
84 |
|
@return |
85 |
|
@since |
86 |
|
|
|
|
| 60% |
Uncovered Elements: 4 (10) |
Complexity: 5 |
Complexity Density: 0.62 |
|
87 |
1083 |
public String url(EntityReference reference, boolean external)... |
88 |
|
{ |
89 |
1083 |
EntityReference wikiReference = reference.extractReference(EntityType.WIKI); |
90 |
|
|
91 |
1083 |
try { |
92 |
1083 |
URL externalURL = this.restURLGenerator.getURL(reference); |
93 |
|
|
94 |
|
|
95 |
1083 |
if (external || (wikiReference != null && !wikiReference.getName().equals(this.wikis.getCurrentWikiId()))) { |
96 |
0 |
return externalURL.toExternalForm(); |
97 |
|
} |
98 |
|
|
99 |
1083 |
return externalURL.getPath(); |
100 |
|
} catch (XWikiRestException e) { |
101 |
0 |
setLastError(e); |
102 |
0 |
return null; |
103 |
|
} |
104 |
|
} |
105 |
|
|
106 |
|
|
107 |
|
|
108 |
|
|
109 |
|
@return |
110 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
111 |
0 |
public XWikiRestException getLastError()... |
112 |
|
{ |
113 |
0 |
return (XWikiRestException) this.execution.getContext().getProperty(ERROR_KEY); |
114 |
|
} |
115 |
|
|
116 |
|
|
117 |
|
@link |
118 |
|
|
119 |
|
@param |
120 |
|
@see |
121 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
122 |
0 |
private void setLastError(XWikiRestException e)... |
123 |
|
{ |
124 |
0 |
this.execution.getContext().setProperty(ERROR_KEY, e); |
125 |
|
} |
126 |
|
} |