Search in sources :

Example 1 with ResourceTypeResolver

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

the class XWiki method initializeResourceFromURL.

private static EntityResourceReference initializeResourceFromURL(XWikiContext context) throws XWikiException {
    // Extract the Entity Resource from the URL
    // TODO: This code should be put in an ExecutionContextInitializer but we couldn't do yet since this code
    // requires that the XWiki object be initialized first (the line above). Thus we'll be able to to move it only
    // after the XWiki init is done also in an ExecutionContextInitializer (and with priorities).
    @SuppressWarnings("deprecation") EntityResourceReference entityResourceReference;
    URL url = context.getURL();
    try {
        ExtendedURL extendedURL = new ExtendedURL(url, context.getRequest().getContextPath());
        ResourceTypeResolver<ExtendedURL> typeResolver = Utils.getComponent(new DefaultParameterizedType(null, ResourceTypeResolver.class, ExtendedURL.class));
        ResourceType type = typeResolver.resolve(extendedURL, Collections.<String, Object>emptyMap());
        ResourceReferenceResolver<ExtendedURL> resourceResolver = Utils.getComponent(new DefaultParameterizedType(null, ResourceReferenceResolver.class, ExtendedURL.class));
        ResourceReference reference = resourceResolver.resolve(extendedURL, type, Collections.<String, Object>emptyMap());
        entityResourceReference = reference instanceof EntityResourceReference ? (EntityResourceReference) reference : null;
    } catch (Exception e) {
        throw new XWikiException(XWikiException.MODULE_XWIKI, XWikiException.ERROR_XWIKI_APP_URL_EXCEPTION, String.format("Failed to extract Entity Resource Reference from URL [%s]", url), e);
    }
    Utils.getComponent(Execution.class).getContext().setProperty(ResourceReferenceManager.RESOURCE_CONTEXT_PROPERTY, entityResourceReference);
    return entityResourceReference;
}
Also used : ResourceReferenceResolver(org.xwiki.resource.ResourceReferenceResolver) 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) WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) IOException(java.io.IOException) JobException(org.xwiki.job.JobException) ParseException(org.xwiki.rendering.parser.ParseException) QueryException(org.xwiki.query.QueryException) URIException(org.apache.commons.httpclient.URIException) InvocationTargetException(java.lang.reflect.InvocationTargetException) HibernateException(org.hibernate.HibernateException) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) NamingException(javax.naming.NamingException) FileNotFoundException(java.io.FileNotFoundException) MalformedURLException(java.net.MalformedURLException) ResourceTypeResolver(org.xwiki.resource.ResourceTypeResolver) ResourceReference(org.xwiki.resource.ResourceReference) EntityResourceReference(org.xwiki.resource.entity.EntityResourceReference) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType)

Example 2 with ResourceTypeResolver

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

the class DefaultStringResourceTypeResolver method resolve.

@Override
public ResourceType resolve(String type, Map<String, Object> parameters) throws CreateResourceTypeException {
    ResourceTypeResolver resolver;
    DefaultParameterizedType parameterizedType = new DefaultParameterizedType(null, ResourceTypeResolver.class, String.class);
    String hint = this.configuration.getURLFormatId();
    if (this.componentManager.hasComponent(parameterizedType, hint)) {
        try {
            resolver = this.componentManager.getInstance(parameterizedType, hint);
        } catch (ComponentLookupException e) {
            throw new CreateResourceTypeException(String.format("Failed to convert Resource Type from String [%s] to [%s]", type, ResourceType.class.getSimpleName()), e);
        }
    } else {
        // No specific String Resource Type Resolver for the Scheme URL, use the generic one!
        resolver = this.genericResourceTypeResolver;
    }
    return resolver.resolve(type, parameters);
}
Also used : ResourceTypeResolver(org.xwiki.resource.ResourceTypeResolver) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) ResourceType(org.xwiki.resource.ResourceType) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) CreateResourceTypeException(org.xwiki.resource.CreateResourceTypeException)

Aggregations

ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)2 DefaultParameterizedType (org.xwiki.component.util.DefaultParameterizedType)2 ResourceType (org.xwiki.resource.ResourceType)2 ResourceTypeResolver (org.xwiki.resource.ResourceTypeResolver)2 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 NamingException (javax.naming.NamingException)1 URIException (org.apache.commons.httpclient.URIException)1 HibernateException (org.hibernate.HibernateException)1 JobException (org.xwiki.job.JobException)1 QueryException (org.xwiki.query.QueryException)1 ParseException (org.xwiki.rendering.parser.ParseException)1 CreateResourceTypeException (org.xwiki.resource.CreateResourceTypeException)1 ResourceReference (org.xwiki.resource.ResourceReference)1 ResourceReferenceResolver (org.xwiki.resource.ResourceReferenceResolver)1 EntityResourceReference (org.xwiki.resource.entity.EntityResourceReference)1 ExtendedURL (org.xwiki.url.ExtendedURL)1