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.xhtml; |
21 |
|
|
22 |
|
import java.net.URI; |
23 |
|
import java.util.Map; |
24 |
|
|
25 |
|
import javax.inject.Inject; |
26 |
|
import javax.inject.Named; |
27 |
|
import javax.inject.Provider; |
28 |
|
|
29 |
|
import org.xwiki.component.annotation.Component; |
30 |
|
import org.xwiki.component.annotation.InstantiationStrategy; |
31 |
|
import org.xwiki.component.descriptor.ComponentInstantiationStrategy; |
32 |
|
import org.xwiki.rendering.internal.renderer.xhtml.link.AbstractXHTMLLinkTypeRenderer; |
33 |
|
import org.xwiki.rendering.internal.renderer.xhtml.link.XHTMLLinkRenderer; |
34 |
|
import org.xwiki.rendering.listener.reference.ResourceReference; |
35 |
|
import org.xwiki.repository.Resources; |
36 |
|
import org.xwiki.repository.UriBuilder; |
37 |
|
import org.xwiki.repository.internal.reference.ExtensionResourceReference; |
38 |
|
|
39 |
|
import com.xpn.xwiki.XWikiContext; |
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
@version |
45 |
|
@since |
46 |
|
|
47 |
|
@Component |
48 |
|
@Named("extension") |
49 |
|
@InstantiationStrategy(ComponentInstantiationStrategy.PER_LOOKUP) |
|
|
| 71.4% |
Uncovered Elements: 8 (28) |
Complexity: 7 |
Complexity Density: 0.41 |
|
50 |
|
public class ExtensionXHTMLLinkTypeRenderer extends AbstractXHTMLLinkTypeRenderer |
51 |
|
{ |
52 |
|
|
53 |
|
@link |
54 |
|
|
55 |
|
@Inject |
56 |
|
private Provider<XWikiContext> xcontextProvider; |
57 |
|
|
|
|
| 70.4% |
Uncovered Elements: 8 (27) |
Complexity: 7 |
Complexity Density: 0.41 |
|
58 |
2 |
@Override... |
59 |
|
protected void beginLinkExtraAttributes(ResourceReference reference, Map<String, String> spanAttributes, |
60 |
|
Map<String, String> anchorAttributes) |
61 |
|
{ |
62 |
2 |
XWikiContext xcontext = this.xcontextProvider.get(); |
63 |
|
|
64 |
2 |
String prefix = xcontext.getWiki().getWebAppPath(xcontext); |
65 |
2 |
if (prefix.isEmpty() || prefix.charAt(0) != '/') { |
66 |
2 |
prefix = '/' + prefix; |
67 |
|
} |
68 |
2 |
if (prefix.charAt(prefix.length() - 1) != '/') { |
69 |
0 |
prefix += '/'; |
70 |
|
} |
71 |
|
|
72 |
2 |
prefix += "rest"; |
73 |
|
|
74 |
|
|
75 |
|
|
76 |
2 |
UriBuilder builder = new UriBuilder("stubscheme:" + prefix, Resources.EXTENSION_VERSION_FILE); |
77 |
|
|
78 |
2 |
ExtensionResourceReference extensionReference = (ExtensionResourceReference) reference; |
79 |
|
|
80 |
2 |
if (extensionReference.getRepositoryId() != null) { |
81 |
2 |
builder.queryParam(ExtensionResourceReference.PARAM_REPOSITORYID, extensionReference.getRepositoryId()); |
82 |
|
} |
83 |
2 |
if (extensionReference.getRepositoryType() != null) { |
84 |
0 |
builder.queryParam(ExtensionResourceReference.PARAM_REPOSITORYTYPE, extensionReference.getRepositoryType()); |
85 |
|
} |
86 |
2 |
if (extensionReference.getRepositoryURI() != null) { |
87 |
0 |
builder.queryParam(ExtensionResourceReference.PARAM_REPOSITORYURI, extensionReference.getRepositoryURI()); |
88 |
|
} |
89 |
|
|
90 |
2 |
URI uri = builder.build(extensionReference.getExtensionId(), extensionReference.getExtensionVersion()); |
91 |
|
|
92 |
2 |
anchorAttributes.put(XHTMLLinkRenderer.HREF, uri.toString().substring("stubscheme://".length())); |
93 |
|
} |
94 |
|
} |