Search in sources :

Example 1 with CreateResourceReferenceException

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

the class RoutingFilter method constructExtendedURL.

private ExtendedURL constructExtendedURL(HttpServletRequest httpRequest) throws ServletException {
    ExtendedURL extendedURL;
    URL url = getRequestURL(httpRequest);
    try {
        extendedURL = new ExtendedURL(url, httpRequest.getContextPath());
    } catch (CreateResourceReferenceException e) {
        throw new ServletException(String.format("Invalid URL [%s]", url), e);
    }
    return extendedURL;
}
Also used : ServletException(javax.servlet.ServletException) ExtendedURL(org.xwiki.url.ExtendedURL) ExtendedURL(org.xwiki.url.ExtendedURL) URL(java.net.URL) CreateResourceReferenceException(org.xwiki.resource.CreateResourceReferenceException)

Example 2 with CreateResourceReferenceException

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

the class ExtendedURLTemporaryResourceReferenceResolver method resolve.

@Override
public TemporaryResourceReference resolve(ExtendedURL extendedURL, ResourceType resourceType, Map<String, Object> parameters) throws CreateResourceReferenceException, UnsupportedResourceReferenceException {
    TemporaryResourceReference reference;
    List<String> segments = extendedURL.getSegments();
    if (segments.size() < 3) {
        throw new CreateResourceReferenceException(String.format("Invalid temporary resource URL format [%s].", extendedURL.toString()));
    } else {
        // The first segment is the module id.
        String moduleId = segments.get(0);
        // The second segment is the serialized owning entity reference. This is used to check access rights.
        EntityReference owningEntityReference = resolveEntityReference(segments.get(1));
        // The other segments point to the resource path.
        List<String> resourcePath = segments.subList(2, segments.size());
        reference = new TemporaryResourceReference(moduleId, resourcePath, owningEntityReference);
        copyParameters(extendedURL, reference);
    }
    return reference;
}
Also used : TemporaryResourceReference(org.xwiki.resource.temporary.TemporaryResourceReference) EntityReference(org.xwiki.model.reference.EntityReference) CreateResourceReferenceException(org.xwiki.resource.CreateResourceReferenceException)

Example 3 with CreateResourceReferenceException

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

the class DefaultResourceReferenceResolver method resolve.

@Override
public ResourceReference resolve(ExtendedURL extendedURL, ResourceType type, Map<String, Object> parameters) throws CreateResourceReferenceException, UnsupportedResourceReferenceException {
    ResourceReferenceResolver resolver;
    // Step 1: Look for a URL-scheme-specific Resolver (a general one that is independent of the passed
    // Resource Type). This allows URL-scheme implementation to completely override handling of any
    // Resource Type if they wish.
    DefaultParameterizedType parameterizedType = new DefaultParameterizedType(null, ResourceReferenceResolver.class, ExtendedURL.class);
    String hint = this.configuration.getURLFormatId();
    if (this.componentManager.hasComponent(parameterizedType, hint)) {
        try {
            resolver = this.componentManager.getInstance(parameterizedType, hint);
        } catch (ComponentLookupException e) {
            throw new CreateResourceReferenceException(String.format("Failed to create Resource Reference for [%s].", extendedURL.getWrappedURL()), e);
        }
    } else {
        // Step 2: If not found, use the Generic Resolver, which tries to find a Resolver registered for the
        // specific Resource Type.
        resolver = this.genericResourceReferenceResolver;
    }
    return resolver.resolve(extendedURL, type, parameters);
}
Also used : ResourceReferenceResolver(org.xwiki.resource.ResourceReferenceResolver) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) CreateResourceReferenceException(org.xwiki.resource.CreateResourceReferenceException)

Example 4 with CreateResourceReferenceException

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

the class VfsResourceReferenceResolver method resolve.

@Override
public VfsResourceReference resolve(ExtendedURL extendedURL, ResourceType resourceType, Map<String, Object> parameters) throws CreateResourceReferenceException, UnsupportedResourceReferenceException {
    List<String> segments = extendedURL.getSegments();
    // First segment is the url-encoded VFS reference, defined as URI
    URI vfsUri;
    try {
        vfsUri = new URI(segments.get(0));
    } catch (URISyntaxException e) {
        throw new CreateResourceReferenceException(String.format("Invalid VFS URI [%s] for URL [%s]", segments.get(0), extendedURL));
    }
    // Other segments are the path to the archive resource
    List<String> vfsPathSegments = new ArrayList<>(segments);
    vfsPathSegments.remove(0);
    VfsResourceReference vfsReference = new VfsResourceReference(vfsUri, vfsPathSegments);
    copyParameters(extendedURL, vfsReference);
    return vfsReference;
}
Also used : ArrayList(java.util.ArrayList) VfsResourceReference(org.xwiki.vfs.VfsResourceReference) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) CreateResourceReferenceException(org.xwiki.resource.CreateResourceReferenceException)

Example 5 with CreateResourceReferenceException

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

the class EntityResourceReferenceResolver method resolve.

@Override
public EntityResourceReference resolve(ExtendedURL extendedURL, ResourceType resourceType, Map<String, Object> parameters) throws CreateResourceReferenceException, UnsupportedResourceReferenceException {
    EntityResourceReference entityURL;
    // UC1: <action>/<entity reference type>/<entity reference>
    // UC2: <action>/<entity reference> ==> type = page
    // UC3: <entity reference> ==> type = page, action = view
    List<String> pathSegments = extendedURL.getSegments();
    String action = ACTION_VIEW;
    EntityType entityType;
    String entityReferenceAsString;
    if (pathSegments.size() == 3) {
        action = pathSegments.get(0);
        entityType = computeEntityType(pathSegments.get(1));
        entityReferenceAsString = pathSegments.get(2);
    } else if (pathSegments.size() == 2) {
        action = pathSegments.get(0);
        entityType = computeDefaultEntityType(action);
        entityReferenceAsString = pathSegments.get(1);
    } else if (pathSegments.size() == 1) {
        entityType = computeDefaultEntityType(action);
        entityReferenceAsString = pathSegments.get(0);
    } else {
        throw new CreateResourceReferenceException(String.format("Invalid Entity URL [%s]", extendedURL.serialize()));
    }
    // Convert the string representation of the Entity reference into a proper EntityResourceReference.
    entityURL = new EntityResourceReference(this.defaultEntityReferenceResolver.resolve(entityReferenceAsString, entityType), EntityResourceAction.fromString(action));
    return entityURL;
}
Also used : EntityType(org.xwiki.model.EntityType) EntityResourceReference(org.xwiki.resource.entity.EntityResourceReference) CreateResourceReferenceException(org.xwiki.resource.CreateResourceReferenceException)

Aggregations

CreateResourceReferenceException (org.xwiki.resource.CreateResourceReferenceException)7 URL (java.net.URL)3 Test (org.junit.Test)2 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 ServletException (javax.servlet.ServletException)1 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)1 DefaultParameterizedType (org.xwiki.component.util.DefaultParameterizedType)1 EntityType (org.xwiki.model.EntityType)1 EntityReference (org.xwiki.model.reference.EntityReference)1 ResourceReferenceResolver (org.xwiki.resource.ResourceReferenceResolver)1 EntityResourceReference (org.xwiki.resource.entity.EntityResourceReference)1 TemporaryResourceReference (org.xwiki.resource.temporary.TemporaryResourceReference)1 ExtendedURL (org.xwiki.url.ExtendedURL)1 VfsResourceReference (org.xwiki.vfs.VfsResourceReference)1