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;
}
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);
}
Aggregations