Search in sources :

Example 36 with ExtendedURL

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);
}
Also used : ArrayList(java.util.ArrayList) ExtendedURL(org.xwiki.url.ExtendedURL)

Example 37 with 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);
}
Also used : ExtendedURL(org.xwiki.url.ExtendedURL) WikiReference(org.xwiki.model.reference.WikiReference) ExtendedURL(org.xwiki.url.ExtendedURL) URL(java.net.URL)

Example 38 with ExtendedURL

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;
}
Also used : EntityResourceReference(org.xwiki.resource.entity.EntityResourceReference) ResourceType(org.xwiki.resource.ResourceType) ExtendedURL(org.xwiki.url.ExtendedURL) ExtendedURL(org.xwiki.url.ExtendedURL) URL(java.net.URL)

Example 39 with ExtendedURL

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());
}
Also used : HashMap(java.util.HashMap) List(java.util.List) ExtendedURL(org.xwiki.url.ExtendedURL) Test(org.junit.Test)

Example 40 with ExtendedURL

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());
}
Also used : ServletContext(javax.servlet.ServletContext) ServletEnvironment(org.xwiki.environment.internal.ServletEnvironment) ExtendedURL(org.xwiki.url.ExtendedURL) Test(org.junit.Test)

Aggregations

ExtendedURL (org.xwiki.url.ExtendedURL)46 Test (org.junit.Test)26 DefaultParameterizedType (org.xwiki.component.util.DefaultParameterizedType)13 ResourceType (org.xwiki.resource.ResourceType)10 URL (java.net.URL)9 WebJarsResourceReference (org.xwiki.webjars.internal.WebJarsResourceReference)8 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)7 VfsResourceReference (org.xwiki.vfs.VfsResourceReference)7 HashMap (java.util.HashMap)6 List (java.util.List)6 EntityResourceReference (org.xwiki.resource.entity.EntityResourceReference)6 ServletException (javax.servlet.ServletException)5 WikiDescriptorManager (org.xwiki.wiki.descriptor.WikiDescriptorManager)5 IOException (java.io.IOException)4 Type (java.lang.reflect.Type)3 ExtensionId (org.xwiki.extension.ExtensionId)3 InstalledExtension (org.xwiki.extension.InstalledExtension)3 InstalledExtensionRepository (org.xwiki.extension.repository.InstalledExtensionRepository)3 DocumentReference (org.xwiki.model.reference.DocumentReference)3 ResourceReference (org.xwiki.resource.ResourceReference)3