use of org.xwiki.resource.ResourceReferenceResolver 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.ResourceReferenceResolver in project xwiki-platform by xwiki.
the class StandardExtendedURLResourceTypeResolver method registerEntityResourceReferenceResolver.
private void registerEntityResourceReferenceResolver(String registrationHint, Class<? extends ResourceReferenceResolver<ExtendedURL>> registrationImplementation, String wikiExtractorHint) throws InitializationException {
DefaultComponentDescriptor<ResourceReferenceResolver<ExtendedURL>> resolverDescriptor = new DefaultComponentDescriptor<>();
resolverDescriptor.setImplementation(registrationImplementation);
resolverDescriptor.setInstantiationStrategy(ComponentInstantiationStrategy.SINGLETON);
String hint = computeHint(registrationHint);
resolverDescriptor.setRoleHint(hint);
resolverDescriptor.setRoleType(new DefaultParameterizedType(null, ResourceReferenceResolver.class, ExtendedURL.class));
// Register dependencies
DefaultComponentDependency<WikiReferenceExtractor> wikiReferenceExtractorDependency = new DefaultComponentDependency<>();
wikiReferenceExtractorDependency.setRoleType(WikiReferenceExtractor.class);
wikiReferenceExtractorDependency.setRoleHint(wikiExtractorHint);
wikiReferenceExtractorDependency.setName("wikiExtractor");
resolverDescriptor.addComponentDependency(wikiReferenceExtractorDependency);
DefaultComponentDependency<EntityReferenceResolver<EntityReference>> entityReferenceResolverDependency = new DefaultComponentDependency<>();
entityReferenceResolverDependency.setRoleType(new DefaultParameterizedType(null, EntityReferenceResolver.class, EntityReference.class));
entityReferenceResolverDependency.setName("defaultReferenceEntityReferenceResolver");
resolverDescriptor.addComponentDependency(entityReferenceResolverDependency);
DefaultComponentDependency<StandardURLConfiguration> standardURLConfigurationDependency = new DefaultComponentDependency<>();
standardURLConfigurationDependency.setRoleType(StandardURLConfiguration.class);
standardURLConfigurationDependency.setName("configuration");
resolverDescriptor.addComponentDependency(standardURLConfigurationDependency);
DefaultComponentDependency<EntityResourceActionLister> entityResourceActionListerDependency = new DefaultComponentDependency<>();
entityResourceActionListerDependency.setRoleType(EntityResourceActionLister.class);
entityResourceActionListerDependency.setName("entityResourceActionLister");
resolverDescriptor.addComponentDependency(entityResourceActionListerDependency);
try {
this.rootComponentManager.registerComponent(resolverDescriptor);
} catch (ComponentRepositoryException e) {
throw new InitializationException(String.format("Failed to dynamically register Resource Reference Resolver for hint [%s]", hint), e);
}
}
use of org.xwiki.resource.ResourceReferenceResolver 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);
}
Aggregations