Search in sources :

Example 6 with ResourceType

use of org.xwiki.resource.ResourceType in project xwiki-platform by xwiki.

the class XWikiRequestProcessor method processPath.

@Override
protected String processPath(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws IOException {
    String url = httpServletRequest.getRequestURL().toString();
    try {
        ExtendedURL extendedURL = new ExtendedURL(new URL(url), httpServletRequest.getContextPath());
        ResourceType type = this.typeResolver.resolve(extendedURL, Collections.<String, Object>emptyMap());
        EntityResourceReference entityResourceReference = (EntityResourceReference) this.resolver.resolve(extendedURL, type, Collections.<String, Object>emptyMap());
        return "/" + entityResourceReference.getAction().getActionName() + "/";
    } catch (Exception e) {
        throw new IOException(String.format("Failed to extract the Entity Action from URL [%s]", url), e);
    }
}
Also used : EntityResourceReference(org.xwiki.resource.entity.EntityResourceReference) ResourceType(org.xwiki.resource.ResourceType) IOException(java.io.IOException) ExtendedURL(org.xwiki.url.ExtendedURL) ExtendedURL(org.xwiki.url.ExtendedURL) URL(java.net.URL) ServletException(javax.servlet.ServletException) IOException(java.io.IOException)

Example 7 with ResourceType

use of org.xwiki.resource.ResourceType in project xwiki-platform by xwiki.

the class IntegrationTest method assertURL.

private void assertURL(String url, ResourceType expectedType, ResourceReference expectedReference) throws Exception {
    ExtendedURL extendedURL = new ExtendedURL(new URL(url), "xwiki");
    ResourceType resourceType = this.resourceTypeResolver.resolve(extendedURL, Collections.<String, Object>emptyMap());
    assertEquals(expectedType.getId(), resourceType.getId());
    ResourceReference reference = this.resourceReferenceResolver.resolve(extendedURL, resourceType, Collections.<String, Object>emptyMap());
    assertEquals(expectedReference, reference);
}
Also used : ResourceType(org.xwiki.resource.ResourceType) ResourcesResourceReference(org.xwiki.resource.resources.ResourcesResourceReference) SkinsResourceReference(org.xwiki.resource.skins.SkinsResourceReference) ResourceReference(org.xwiki.resource.ResourceReference) EntityResourceReference(org.xwiki.resource.entity.EntityResourceReference) ExtendedURL(org.xwiki.url.ExtendedURL) ExtendedURL(org.xwiki.url.ExtendedURL) URL(java.net.URL)

Example 8 with ResourceType

use of org.xwiki.resource.ResourceType in project xwiki-platform by xwiki.

the class IntegrationTest method extractResourceReference.

@Test
public void extractResourceReference() throws Exception {
    // Entity Resource References
    assertURL("http://localhost:8080/xwiki/bin/view/space/page", EntityResourceReference.TYPE, new EntityResourceReference(new DocumentReference("xwiki", "space", "page"), EntityResourceAction.VIEW));
    assertURL("http://localhost:8080/xwiki/wiki/mywiki/view/space/page", new ResourceType("wiki"), new EntityResourceReference(new DocumentReference("mywiki", "space", "page"), EntityResourceAction.VIEW));
    // Resources Resource References
    assertURL("http://localhost:8080/xwiki/resources/js/prototype/prototype.js", ResourcesResourceReference.TYPE, new ResourcesResourceReference());
    // Skins Resource References
    assertURL("http://localhost:8080/xwiki/skins/flamingo/logo.png", SkinsResourceReference.TYPE, new SkinsResourceReference());
}
Also used : ResourcesResourceReference(org.xwiki.resource.resources.ResourcesResourceReference) SkinsResourceReference(org.xwiki.resource.skins.SkinsResourceReference) EntityResourceReference(org.xwiki.resource.entity.EntityResourceReference) ResourceType(org.xwiki.resource.ResourceType) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 9 with ResourceType

use of org.xwiki.resource.ResourceType in project xwiki-platform by xwiki.

the class BinEntityResourceReferenceResolverTest 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("bin"), 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 10 with ResourceType

use of org.xwiki.resource.ResourceType 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)

Aggregations

ResourceType (org.xwiki.resource.ResourceType)12 ExtendedURL (org.xwiki.url.ExtendedURL)9 EntityResourceReference (org.xwiki.resource.entity.EntityResourceReference)6 URL (java.net.URL)5 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)5 DefaultParameterizedType (org.xwiki.component.util.DefaultParameterizedType)5 IOException (java.io.IOException)4 ServletException (javax.servlet.ServletException)3 ResourceReference (org.xwiki.resource.ResourceReference)3 MalformedURLException (java.net.MalformedURLException)2 Test (org.junit.Test)2 ResourceReferenceResolver (org.xwiki.resource.ResourceReferenceResolver)2 ResourceTypeResolver (org.xwiki.resource.ResourceTypeResolver)2 ResourcesResourceReference (org.xwiki.resource.resources.ResourcesResourceReference)2 SkinsResourceReference (org.xwiki.resource.skins.SkinsResourceReference)2 FileNotFoundException (java.io.FileNotFoundException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Type (java.lang.reflect.Type)1 NamingException (javax.naming.NamingException)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1