use of org.xwiki.url.internal.RelativeExtendedURL in project xwiki-platform by xwiki.
the class RelativeExtendedURLTest method serialize.
@Test
public void serialize() {
RelativeExtendedURL url = new RelativeExtendedURL(Arrays.asList("a", "b"));
assertEquals("a/b", url.serialize());
}
use of org.xwiki.url.internal.RelativeExtendedURL in project xwiki-platform by xwiki.
the class FilesystemResourceReferenceSerializer method serialize.
@Override
public ExtendedURL serialize(WebJarsResourceReference reference) throws SerializeResourceReferenceException, UnsupportedResourceReferenceException {
// Copy the resource from the webjar to the filesystem
FilesystemExportContext exportContext = this.exportContextProvider.get();
try {
FilesystemResourceReferenceCopier copier = new FilesystemResourceReferenceCopier();
copier.copyResourceFromJAR(WEBJARS_RESOURCE_PREFIX, reference.getResourceName(), WEBJAR_PATH, exportContext);
// filesystem.
if (reference.getResourceName().toLowerCase().endsWith("css")) {
copier.processCSS(WEBJARS_RESOURCE_PREFIX, reference.getResourceName(), WEBJAR_PATH, exportContext);
}
} catch (Exception e) {
throw new SerializeResourceReferenceException(String.format("Failed to extract and copy WebJAR resource [%s]", reference.getResourceName()), e);
}
List<String> pathSegments = new ArrayList<>();
// Adjust path depending on where the current doc is stored
if (exportContext.getCSSParentLevel() == 0) {
for (int i = 0; i < exportContext.getDocParentLevel(); i++) {
pathSegments.add(PARENT);
}
} else {
// Adjust path for links inside CSS files (since they need to be relative to the CSS file they're in).
for (int i = 0; i < exportContext.getCSSParentLevel(); i++) {
pathSegments.add(PARENT);
}
}
pathSegments.add(WEBJAR_PATH);
for (String resourceSegment : StringUtils.split(reference.getResourceName(), '/')) {
pathSegments.add(resourceSegment);
}
return new RelativeExtendedURL(pathSegments);
}
Aggregations