use of org.xwiki.component.util.DefaultParameterizedType in project xwiki-platform by xwiki.
the class AbstractExtendedURLResourceTypeResolver method resolve.
protected ResourceType resolve(String hintPrefix, ExtendedURL extendedURL, Map<String, Object> parameters) throws CreateResourceTypeException {
ResourceType resourceType;
// Find the Resource Type, which is the first segment in the ExtendedURL.
//
// Note that we need to remove the type from the ExtendedURL instance since it's passed to the specific
// resolvers and they shouldn't be aware of where it was located since they need to be able to resolve the
// rest of the URL independently of the URL scheme, in case they wish to have a single URL syntax for all URL
// schemes.
//
// Examples:
// - scheme 1: /<type>/something
// - scheme 2: /something?type=<type>
//
// The specific resolver for type <type> needs to be passed an ExtendedURL independent of the type, in this
// case, "/something" for both examples.
//
// However since we also want this code to work when short URLs are enabled, we only remove the segment part
// if a Resource type has been identified (see below) and if not, we assume the URL is pointing to an Entity
// Resource.
List<String> segments = extendedURL.getSegments();
resourceType = this.defaultStringResourceTypeResolver.resolve(segments.get(0), Collections.<String, Object>emptyMap());
// Second, if not found, try to locate a URL Resolver registered for all URL schemes
if (this.componentManager.hasComponent(new DefaultParameterizedType(null, ResourceReferenceResolver.class, ExtendedURL.class), computeHint(hintPrefix, resourceType.getId()))) {
extendedURL.getSegments().remove(0);
} else if (this.componentManager.hasComponent(new DefaultParameterizedType(null, ResourceReferenceResolver.class, ExtendedURL.class), resourceType.getId())) {
extendedURL.getSegments().remove(0);
} else {
// No specific Resource Type Resolver has been found. In order to support short URLs (ie. without the
// "bin" or "wiki" part specified), we assume the URL is pointing to an Entity Resource Reference.
// Since the "wiki" type was not selected, we're assuming that the we'll use the "bin" entity resolver.
resourceType = EntityResourceReference.TYPE;
}
return resourceType;
}
use of org.xwiki.component.util.DefaultParameterizedType 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);
}
use of org.xwiki.component.util.DefaultParameterizedType 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);
}
use of org.xwiki.component.util.DefaultParameterizedType in project xwiki-platform by xwiki.
the class DefaultIconSetCacheTest method setUp.
@Before
public void setUp() throws Exception {
cacheManager = mocker.getInstance(CacheManager.class);
entityReferenceSerializer = mocker.getInstance(new DefaultParameterizedType(null, EntityReferenceSerializer.class, String.class));
cache = mock(Cache.class);
CacheFactory cacheFactory = mock(CacheFactory.class);
when(cacheManager.getCacheFactory()).thenReturn(cacheFactory);
CacheConfiguration configuration = new CacheConfiguration("iconset");
when(cacheFactory.<IconSet>newCache(eq(configuration))).thenReturn(cache);
}
use of org.xwiki.component.util.DefaultParameterizedType in project xwiki-platform by xwiki.
the class SerializedFilesMimeMessageFactoryTest method createMessageWhenNoExecution.
@Test
public void createMessageWhenNoExecution() throws Exception {
Provider<ComponentManager> componentManagerProvider = this.mocker.registerMockComponent(new DefaultParameterizedType(null, Provider.class, ComponentManager.class), "context");
when(componentManagerProvider.get()).thenReturn(this.mocker);
try {
this.mocker.getComponentUnderTest().createMessage("batchId", null);
fail("Should have thrown an exception");
} catch (MessagingException expected) {
assertEquals("Failed to find an Environment Component", expected.getMessage());
}
}
Aggregations