Search in sources :

Example 1 with RelativeExtendedURL

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());
}
Also used : RelativeExtendedURL(org.xwiki.url.internal.RelativeExtendedURL) Test(org.junit.Test)

Example 2 with RelativeExtendedURL

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);
}
Also used : SerializeResourceReferenceException(org.xwiki.resource.SerializeResourceReferenceException) RelativeExtendedURL(org.xwiki.url.internal.RelativeExtendedURL) ArrayList(java.util.ArrayList) FilesystemExportContext(org.xwiki.url.filesystem.FilesystemExportContext) SerializeResourceReferenceException(org.xwiki.resource.SerializeResourceReferenceException) UnsupportedResourceReferenceException(org.xwiki.resource.UnsupportedResourceReferenceException)

Aggregations

RelativeExtendedURL (org.xwiki.url.internal.RelativeExtendedURL)2 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1 SerializeResourceReferenceException (org.xwiki.resource.SerializeResourceReferenceException)1 UnsupportedResourceReferenceException (org.xwiki.resource.UnsupportedResourceReferenceException)1 FilesystemExportContext (org.xwiki.url.filesystem.FilesystemExportContext)1