use of org.xwiki.resource.ResourceType in project xwiki-platform by xwiki.
the class AbstractResourceReferenceResolver method findResourceResolver.
/**
* Find the right Resolver for the passed Resource type and call it.
*/
protected ResourceReferenceResolver<ExtendedURL> findResourceResolver(String hintPrefix, ResourceType type) throws UnsupportedResourceReferenceException {
ResourceReferenceResolver<ExtendedURL> resolver;
Type roleType = new DefaultParameterizedType(null, ResourceReferenceResolver.class, ExtendedURL.class);
String roleHint = computeResolverHint(hintPrefix, type.getId());
// Step 1: Look for a Resolver specific to the scheme and specific to the Resource Type
if (this.componentManager.hasComponent(roleType, roleHint)) {
try {
resolver = this.componentManager.getInstance(roleType, roleHint);
} catch (ComponentLookupException cle) {
// There's no Resolver registered for the passed Resource Type
throw new UnsupportedResourceReferenceException(String.format("Failed to lookup Resource Reference Resolver for hint [%s]", roleHint), cle);
}
} else {
// schemes
try {
resolver = this.componentManager.getInstance(roleType, type.getId());
} catch (ComponentLookupException cle) {
// There's no Resolver registered for the passed Resource Type
throw new UnsupportedResourceReferenceException(String.format("Failed to lookup Resource Reference Resolver for type [%s]", type), cle);
}
}
return resolver;
}
use of org.xwiki.resource.ResourceType in project xwiki-platform by xwiki.
the class MainResourceReferenceHandlerManagerTest method handleWithOrder.
@Test
public void handleWithOrder() throws Exception {
// First Handler component will lower priority
ResourceReferenceHandler testHandler = mock(ResourceReferenceHandler.class, "handler1");
when(testHandler.getSupportedResourceReferences()).thenReturn(Arrays.asList(new ResourceType("test")));
// Second Handler component will higher priority so that it's executed first
ResourceReferenceHandler beforeTestHandler = mock(ResourceReferenceHandler.class, "handler2");
when(beforeTestHandler.getSupportedResourceReferences()).thenReturn(Arrays.asList(new ResourceType("test")));
// We return 1 to mean that the second Handler has a higher priority than the first Handler
when(beforeTestHandler.compareTo(testHandler)).thenReturn(-1);
ComponentManager contextComponentManager = this.componentManager.getInstance(ComponentManager.class, "context");
when(contextComponentManager.<ResourceReferenceHandler>getInstanceList(new DefaultParameterizedType(null, ResourceReferenceHandler.class, ResourceType.class))).thenReturn(Arrays.asList(testHandler, beforeTestHandler));
ResourceReference reference = mock(ResourceReference.class);
when(reference.getType()).thenReturn(new ResourceType("test"));
this.componentManager.getComponentUnderTest().handle(reference);
// Verify that the second Action is called (since it has a higher priority).
verify(beforeTestHandler).handle(same(reference), any(ResourceReferenceHandlerChain.class));
}
Aggregations