Search in sources :

Example 11 with VfsResourceReference

use of org.xwiki.vfs.VfsResourceReference in project xwiki-platform by xwiki.

the class VfsResourceReferenceSerializer method serialize.

@Override
public ExtendedURL serialize(VfsResourceReference resourceReference) throws SerializeResourceReferenceException, UnsupportedResourceReferenceException {
    ExtendedURL extendedURL;
    // We need to ensure that the URI contains absolute references since the VFS handler that will handle
    // the generated URL won't have any base reference to resolve any relative refeence.
    // 
    // Look for a scheme-specific serializer to convert from a relative URI into an absolute URI and if not found
    // then don't perform any transformation of the URI.
    URI uri = resourceReference.getURI();
    try {
        ResourceReferenceSerializer<VfsResourceReference, ExtendedURL> schemeSpecificSerializer = this.componentManagerProvider.get().getInstance(TYPE, uri.getScheme());
        extendedURL = schemeSpecificSerializer.serialize(resourceReference);
    } catch (ComponentLookupException e) {
        extendedURL = super.serialize(resourceReference);
    }
    return extendedURL;
}
Also used : VfsResourceReference(org.xwiki.vfs.VfsResourceReference) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) ExtendedURL(org.xwiki.url.ExtendedURL) URI(java.net.URI)

Example 12 with VfsResourceReference

use of org.xwiki.vfs.VfsResourceReference in project xwiki-platform by xwiki.

the class VfsResourceReferenceResolverTest method resolve.

@Test
public void resolve() throws Exception {
    ExtendedURL extendedURL = new ExtendedURL(Arrays.asList("attach:wiki:space.page@attachment", "path1", "path2", "test.txt"), Collections.singletonMap("key", Arrays.asList("value")));
    VfsResourceReference reference = this.mocker.getComponentUnderTest().resolve(extendedURL, VfsResourceReference.TYPE, Collections.<String, Object>emptyMap());
    VfsResourceReference expected = new VfsResourceReference(URI.create("attach:wiki:space.page@attachment"), "path1/path2/test.txt");
    expected.addParameter("key", "value");
    assertEquals(expected, reference);
}
Also used : VfsResourceReference(org.xwiki.vfs.VfsResourceReference) ExtendedURL(org.xwiki.url.ExtendedURL) Test(org.junit.Test)

Example 13 with VfsResourceReference

use of org.xwiki.vfs.VfsResourceReference in project xwiki-platform by xwiki.

the class VfsResourceReferenceSerializerTest method serializeWhenSpecificSchemeSerializer.

@Test
public void serializeWhenSpecificSchemeSerializer() throws Exception {
    VfsResourceReference reference = new VfsResourceReference(URI.create("attach:attachment"), "path1/path2/test.txt");
    ExtendedURL extendedURL = new ExtendedURL(Arrays.asList("vfs", "attach:wiki:space.page@attachment", "path1", "path2", "test.txt"));
    ResourceReferenceSerializer<VfsResourceReference, ExtendedURL> serializer = this.mocker.registerMockComponent(new DefaultParameterizedType(null, ResourceReferenceSerializer.class, VfsResourceReference.class, ExtendedURL.class), "attach");
    when(serializer.serialize(reference)).thenReturn(extendedURL);
    assertEquals("/vfs/attach%3Awiki%3Aspace.page%40attachment/path1/path2/test.txt", this.mocker.getComponentUnderTest().serialize(reference).toString());
}
Also used : ResourceReferenceSerializer(org.xwiki.resource.ResourceReferenceSerializer) VfsResourceReference(org.xwiki.vfs.VfsResourceReference) ExtendedURL(org.xwiki.url.ExtendedURL) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) Test(org.junit.Test)

Example 14 with VfsResourceReference

use of org.xwiki.vfs.VfsResourceReference in project xwiki-platform by xwiki.

the class VfsResourceReferenceTest method equality.

@Test
public void equality() {
    VfsResourceReference reference1 = new VfsResourceReference(URI.create("scheme:specific"), "a/b");
    reference1.addParameter("key", "value");
    VfsResourceReference reference2 = new VfsResourceReference(URI.create("scheme:specific"), "a/b");
    assertNotEquals(reference1, reference2);
    reference2.addParameter("key", "value");
    assertEquals(reference1, reference2);
    assertEquals(reference1.hashCode(), reference2.hashCode());
}
Also used : VfsResourceReference(org.xwiki.vfs.VfsResourceReference) Test(org.junit.Test)

Example 15 with VfsResourceReference

use of org.xwiki.vfs.VfsResourceReference in project xwiki-platform by xwiki.

the class VfsResourceReferenceTest method stringValue.

@Test
public void stringValue() {
    VfsResourceReference reference = new VfsResourceReference(URI.create("scheme:specific"), "a/b");
    reference.addParameter("key", "value");
    assertEquals("uri = [scheme:specific], path = [a/b], parameters = [[key] = [[value]]]", reference.toString());
}
Also used : VfsResourceReference(org.xwiki.vfs.VfsResourceReference) Test(org.junit.Test)

Aggregations

VfsResourceReference (org.xwiki.vfs.VfsResourceReference)26 Test (org.junit.Test)19 URI (java.net.URI)11 DefaultParameterizedType (org.xwiki.component.util.DefaultParameterizedType)10 ResourceReferenceSerializer (org.xwiki.resource.ResourceReferenceSerializer)8 ExtendedURL (org.xwiki.url.ExtendedURL)7 TPath (net.java.truevfs.access.TPath)6 VfsException (org.xwiki.vfs.VfsException)6 Path (java.nio.file.Path)5 DocumentReference (org.xwiki.model.reference.DocumentReference)3 ConversionException (org.xwiki.properties.converter.ConversionException)3 SerializeResourceReferenceException (org.xwiki.resource.SerializeResourceReferenceException)3 ContextualAuthorizationManager (org.xwiki.security.authorization.ContextualAuthorizationManager)3 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)2 AttachmentReference (org.xwiki.model.reference.AttachmentReference)2 AuthorizationManager (org.xwiki.security.authorization.AuthorizationManager)2 URLNormalizer (org.xwiki.url.URLNormalizer)2 VfsManager (org.xwiki.vfs.VfsManager)2 XWiki (com.xpn.xwiki.XWiki)1 XWikiContext (com.xpn.xwiki.XWikiContext)1