use of org.xwiki.url.ExtendedURL in project xwiki-platform by xwiki.
the class AbstractVfsResourceReferenceSerializer method serialize.
@Override
public ExtendedURL serialize(VfsResourceReference resourceReference) throws SerializeResourceReferenceException, UnsupportedResourceReferenceException {
List<String> segments = new ArrayList<>();
// Add the resource type segment.
segments.add("vfs");
// Add the VFS URI part
segments.add(makeAbsolute(resourceReference.getURI()).toString());
// Add the VFS path
segments.addAll(resourceReference.getPathSegments());
// Add all optional parameters
ExtendedURL extendedURL = new ExtendedURL(segments, resourceReference.getParameters());
// Normalize the URL to add the Context Path since we want a full relative URL to be returned.
return this.extendedURLNormalizer.normalize(extendedURL);
}
use of org.xwiki.url.ExtendedURL in project xwiki-platform by xwiki.
the class DomainWikiReferenceExtractorTest method testAndAssert.
private void testAndAssert(String urlToTest, String expectedWikiId) throws Exception {
ExtendedURL url = new ExtendedURL(new URL(urlToTest), "xwiki");
// Remove the resource type (i.e. the first segment) since this is what is expected by the extractor
url.getSegments().remove(0);
WikiReference wikiReference = this.mocker.getComponentUnderTest().extract(url);
assertEquals(new WikiReference(expectedWikiId), wikiReference);
}
use of org.xwiki.url.ExtendedURL in project xwiki-platform by xwiki.
the class WikiEntityResourceReferenceResolverTest method testCreateResource.
private ResourceReference testCreateResource(String testURL, String expectedActionName, EntityReference expectedReference, EntityReference returnedReference, EntityType expectedEntityType) throws Exception {
when(this.entityReferenceResolver.resolve(expectedReference, expectedEntityType)).thenReturn(returnedReference);
ExtendedURL extendedURL = new ExtendedURL(new URL(testURL), null);
// Remove the resource type segment since this is what gets passed to specific Reference Resolvers.
extendedURL.getSegments().remove(0);
EntityResourceReference entityResource = this.resolver.resolve(extendedURL, new ResourceType("wiki"), Collections.<String, Object>emptyMap());
assertEquals(expectedActionName, entityResource.getAction().getActionName());
assertEquals(returnedReference, entityResource.getEntityReference());
return entityResource;
}
use of org.xwiki.url.ExtendedURL in project xwiki-platform by xwiki.
the class ContextAndActionURLNormalizerTest method normalizePreservesParameters.
@Test
public void normalizePreservesParameters() throws Exception {
when(this.servletContext.getContextPath()).thenReturn("/xwiki");
Map<String, List<String>> params = new HashMap<>();
params.put("age", Arrays.asList("32"));
params.put("colors", Arrays.asList("red", "blue"));
ExtendedURL extendedURL = new ExtendedURL(Arrays.asList("one", "two"), params);
assertSame(params, this.mocker.getComponentUnderTest().normalize(extendedURL).getParameters());
}
use of org.xwiki.url.ExtendedURL in project xwiki-platform by xwiki.
the class ExtendedURLURLNormalizerTest method normalizeWhenNoConfigurationPropertyButEnvironment.
@Test
public void normalizeWhenNoConfigurationPropertyButEnvironment() throws Exception {
ServletContext sc = mock(ServletContext.class);
ServletEnvironment environment = mock(ServletEnvironment.class);
this.mocker.registerComponent(Environment.class, environment);
when(environment.getServletContext()).thenReturn(sc);
when(sc.getContextPath()).thenReturn("/xwiki");
ExtendedURL extendedURL = new ExtendedURL(Arrays.asList("one", "two"));
assertEquals("/xwiki/one/two", this.mocker.getComponentUnderTest().normalize(extendedURL).serialize());
}
Aggregations