Search in sources :

Example 96 with DefaultParameterizedType

use of org.xwiki.component.util.DefaultParameterizedType 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;
}
Also used : DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) Type(java.lang.reflect.Type) ResourceType(org.xwiki.resource.ResourceType) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) UnsupportedResourceReferenceException(org.xwiki.resource.UnsupportedResourceReferenceException) ExtendedURL(org.xwiki.url.ExtendedURL) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType)

Example 97 with DefaultParameterizedType

use of org.xwiki.component.util.DefaultParameterizedType in project xwiki-platform by xwiki.

the class DefaultResourceReferenceSerializer method serialize.

@Override
public ExtendedURL serialize(ResourceReference resource) throws SerializeResourceReferenceException, UnsupportedResourceReferenceException {
    ResourceReferenceSerializer<ResourceReference, ExtendedURL> serializer;
    ParameterizedType type = new DefaultParameterizedType(null, ResourceReferenceSerializer.class, ResourceReference.class, ExtendedURL.class);
    try {
        serializer = this.componentManager.getInstance(type, this.urlContextManager.getURLFormatId());
    } catch (ComponentLookupException e) {
        throw new UnsupportedResourceReferenceException(String.format("Invalid URL format id [%s]. Cannot serialize Resource Reference [%s].", this.urlContextManager.getURLFormatId(), resource), e);
    }
    return serializer.serialize(resource);
}
Also used : DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) ParameterizedType(java.lang.reflect.ParameterizedType) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) ResourceReference(org.xwiki.resource.ResourceReference) UnsupportedResourceReferenceException(org.xwiki.resource.UnsupportedResourceReferenceException) ExtendedURL(org.xwiki.url.ExtendedURL) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType)

Example 98 with DefaultParameterizedType

use of org.xwiki.component.util.DefaultParameterizedType in project xwiki-platform by xwiki.

the class ComponentScriptServiceTest method configure.

@Before
public void configure() throws Exception {
    this.dab = this.mocker.getInstance(DocumentAccessBridge.class);
    this.contextComponentManager = this.mocker.registerMockComponent(ComponentManager.class, "context");
    Provider<ComponentManager> contextComponentManagerProvider = this.mocker.registerMockComponent(new DefaultParameterizedType(null, Provider.class, ComponentManager.class), "context");
    when(contextComponentManagerProvider.get()).thenReturn(this.contextComponentManager);
    this.contextrootComponentManager = this.mocker.registerMockComponent(ComponentManager.class, "context/root");
    Provider<ComponentManager> contextrootComponentManagerProvider = this.mocker.registerMockComponent(new DefaultParameterizedType(null, Provider.class, ComponentManager.class), "context/root");
    when(contextrootComponentManagerProvider.get()).thenReturn(this.contextrootComponentManager);
    this.rootComponentManager = this.mocker.registerMockComponent(ComponentManager.class, "root");
    this.componentManagerManager = this.mocker.getInstance(ComponentManagerManager.class);
    when(this.componentManagerManager.getComponentManager(null, false)).thenReturn(this.rootComponentManager);
    this.execution = this.mocker.getInstance(Execution.class);
}
Also used : ComponentManagerManager(org.xwiki.component.internal.multi.ComponentManagerManager) Execution(org.xwiki.context.Execution) DocumentAccessBridge(org.xwiki.bridge.DocumentAccessBridge) ComponentManager(org.xwiki.component.manager.ComponentManager) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) Provider(javax.inject.Provider) ContextComponentManagerProvider(org.xwiki.component.internal.ContextComponentManagerProvider) Before(org.junit.Before)

Example 99 with DefaultParameterizedType

use of org.xwiki.component.util.DefaultParameterizedType in project xwiki-platform by xwiki.

the class DefaultTranslationBundleContextTest method before.

@Before
public void before() throws Exception {
    this.mockExecutionContext = new ExecutionContext();
    Execution mockExecution = this.mocker.getInstance(Execution.class);
    when(mockExecution.getContext()).thenReturn(mockExecutionContext);
    this.mockModelContext = this.mocker.getInstance(ModelContext.class);
    when(this.mockModelContext.getCurrentEntityReference()).thenReturn(new WikiReference("currentWiki"));
    this.mockContextComponentManagerProvider = this.mocker.registerMockComponent(new DefaultParameterizedType(null, Provider.class, ComponentManager.class), "context");
}
Also used : ModelContext(org.xwiki.model.ModelContext) ExecutionContext(org.xwiki.context.ExecutionContext) Execution(org.xwiki.context.Execution) WikiReference(org.xwiki.model.reference.WikiReference) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) Before(org.junit.Before)

Example 100 with DefaultParameterizedType

use of org.xwiki.component.util.DefaultParameterizedType in project xwiki-platform by xwiki.

the class LocalizationScriptServiceTest method setUp.

@Before
public void setUp() throws Exception {
    componentManager = mock(ComponentManager.class);
    Provider<ComponentManager> componentManagerProvider = mocker.registerMockComponent(new DefaultParameterizedType(null, Provider.class, ComponentManager.class), "context");
    when(componentManagerProvider.get()).thenReturn(componentManager);
    renderer = mock(BlockRenderer.class, Syntax.PLAIN_1_0.toIdString());
    when(componentManager.getInstance(BlockRenderer.class, Syntax.PLAIN_1_0.toIdString())).thenReturn(renderer);
    localizationContext = mocker.getInstance(LocalizationContext.class);
    localizationManager = mocker.getInstance(LocalizationManager.class);
    localizationScriptService = (LocalizationScriptService) mocker.getComponentUnderTest();
    translation = mock(Translation.class);
    doAnswer(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            WikiPrinter printer = (WikiPrinter) invocation.getArguments()[1];
            printer.print("print result");
            return null;
        }
    }).when(renderer).render(eq(new WordBlock("message")), any(WikiPrinter.class));
    when(translation.render(Locale.ROOT, ArrayUtils.EMPTY_OBJECT_ARRAY)).thenReturn(new WordBlock("message"));
    when(localizationManager.getTranslation("key", Locale.ROOT)).thenReturn(translation);
    when(localizationContext.getCurrentLocale()).thenReturn(Locale.ROOT);
    environment = mocker.getInstance(Environment.class);
}
Also used : Translation(org.xwiki.localization.Translation) LocalizationContext(org.xwiki.localization.LocalizationContext) WordBlock(org.xwiki.rendering.block.WordBlock) WikiPrinter(org.xwiki.rendering.renderer.printer.WikiPrinter) Provider(javax.inject.Provider) BlockRenderer(org.xwiki.rendering.renderer.BlockRenderer) LocalizationManager(org.xwiki.localization.LocalizationManager) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ComponentManager(org.xwiki.component.manager.ComponentManager) Environment(org.xwiki.environment.Environment) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) Before(org.junit.Before)

Aggregations

DefaultParameterizedType (org.xwiki.component.util.DefaultParameterizedType)104 Test (org.junit.Test)44 Before (org.junit.Before)32 Provider (javax.inject.Provider)27 DocumentReference (org.xwiki.model.reference.DocumentReference)24 XWikiContext (com.xpn.xwiki.XWikiContext)19 ComponentManager (org.xwiki.component.manager.ComponentManager)19 ExecutionContext (org.xwiki.context.ExecutionContext)17 ExtendedURL (org.xwiki.url.ExtendedURL)15 Execution (org.xwiki.context.Execution)14 HashMap (java.util.HashMap)13 DocumentAccessBridge (org.xwiki.bridge.DocumentAccessBridge)13 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)12 ResourceReferenceSerializer (org.xwiki.resource.ResourceReferenceSerializer)10 VfsResourceReference (org.xwiki.vfs.VfsResourceReference)10 Properties (java.util.Properties)9 MimeBodyPartFactory (org.xwiki.mail.MimeBodyPartFactory)9 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)8 XWiki (com.xpn.xwiki.XWiki)7 File (java.io.File)7