use of org.xwiki.repository.UriBuilder in project xwiki-platform by xwiki.
the class ExtensionXHTMLLinkTypeRenderer method beginLinkExtraAttributes.
@Override
protected void beginLinkExtraAttributes(ResourceReference reference, Map<String, String> spanAttributes, Map<String, String> anchorAttributes) {
XWikiContext xcontext = this.xcontextProvider.get();
String prefix = xcontext.getWiki().getWebAppPath(xcontext);
if (prefix.isEmpty() || prefix.charAt(0) != '/') {
prefix = '/' + prefix;
}
if (prefix.charAt(prefix.length() - 1) != '/') {
prefix += '/';
}
// FIXME: need a way to get the rest URL prefix instead of hardcoding it here
prefix += "rest";
// Create an URI (because the API only produces URIs) with a stub context we will then remove since we actually
// want a relative HREF
UriBuilder builder = new UriBuilder("stubscheme:" + prefix, Resources.EXTENSION_VERSION_FILE);
ExtensionResourceReference extensionReference = (ExtensionResourceReference) reference;
if (extensionReference.getRepositoryId() != null) {
builder.queryParam(ExtensionResourceReference.PARAM_REPOSITORYID, extensionReference.getRepositoryId());
}
if (extensionReference.getRepositoryType() != null) {
builder.queryParam(ExtensionResourceReference.PARAM_REPOSITORYTYPE, extensionReference.getRepositoryType());
}
if (extensionReference.getRepositoryURI() != null) {
builder.queryParam(ExtensionResourceReference.PARAM_REPOSITORYURI, extensionReference.getRepositoryURI());
}
URI uri = builder.build(extensionReference.getExtensionId(), extensionReference.getExtensionVersion());
anchorAttributes.put(XHTMLLinkRenderer.HREF, uri.toString().substring("stubscheme://".length()));
}
Aggregations