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;
}
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);
}
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());
}
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());
}
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());
}
Aggregations