Search in sources :

Example 11 with DefaultParameterizedType

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

the class ResourceReferenceHandlerServlet method handleResourceReference.

private void handleResourceReference(ResourceReference resourceReference) throws ServletException {
    ResourceReferenceHandlerManager<?> resourceReferenceHandlerManager;
    try {
        Type role = new DefaultParameterizedType(null, ResourceReferenceHandlerManager.class, ResourceType.class);
        resourceReferenceHandlerManager = this.rootComponentManager.getInstance(role);
    } catch (ComponentLookupException e) {
        // Should not happen since a Resource Reference Handler should always exist on the system.
        throw new ServletException("Failed to locate a Resource Reference Handler Manager component", e);
    }
    try {
        resourceReferenceHandlerManager.handle(resourceReference);
    } catch (ResourceReferenceHandlerException e) {
        throw new ServletException(String.format("Failed to handle Resource Reference [%s]", resourceReference), e);
    }
}
Also used : ServletException(javax.servlet.ServletException) ResourceReferenceHandlerException(org.xwiki.resource.ResourceReferenceHandlerException) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) Type(java.lang.reflect.Type) ResourceType(org.xwiki.resource.ResourceType) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType)

Example 12 with DefaultParameterizedType

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

the class ResourceReferenceHandlerServlet method getResourceReferenceResolver.

private ResourceReferenceResolver<ExtendedURL> getResourceReferenceResolver() throws ServletException {
    ResourceReferenceResolver<ExtendedURL> urlResolver;
    try {
        Type role = new DefaultParameterizedType(null, ResourceReferenceResolver.class, ExtendedURL.class);
        urlResolver = this.rootComponentManager.getInstance(role);
    } catch (ComponentLookupException e) {
        // Should not happen since a URL provider should exist on the system.
        throw new ServletException("Failed to locate an ExtendedURL Resource Reference Resolver component", e);
    }
    return urlResolver;
}
Also used : ServletException(javax.servlet.ServletException) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) Type(java.lang.reflect.Type) ResourceType(org.xwiki.resource.ResourceType) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) ExtendedURL(org.xwiki.url.ExtendedURL) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType)

Example 13 with DefaultParameterizedType

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

the class DefaultEntityResourceActionListerTest method configure.

@Before
public void configure() throws Exception {
    Provider<ComponentManager> componentManagerProvider = this.mocker.registerMockComponent(new DefaultParameterizedType(null, Provider.class, ComponentManager.class), "context");
    when(componentManagerProvider.get()).thenReturn(this.mocker);
}
Also used : ComponentManager(org.xwiki.component.manager.ComponentManager) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) Provider(javax.inject.Provider) Before(org.junit.Before)

Example 14 with DefaultParameterizedType

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

the class SVGScriptServiceTest method setup.

@Before
public void setup() throws Exception {
    MockitoAnnotations.initMocks(this);
    this.internal = this.mocker.getInstance(SVGRasterizer.class);
    when(this.internal.rasterizeToTemporaryResource(SVG, 0, 0)).thenReturn(this.tref);
    when(this.internal.rasterizeToTemporaryResource(SVG, 100, 200)).thenReturn(this.tref);
    when(this.internal.rasterizeToTemporaryResource(SVG, 0, 0, this.dref)).thenReturn(this.tref);
    when(this.internal.rasterizeToTemporaryResource(SVG, 100, 200, this.dref)).thenReturn(this.tref);
    Type stype = new DefaultParameterizedType(null, ResourceReferenceSerializer.class, TemporaryResourceReference.class, ExtendedURL.class);
    this.serializer = this.mocker.getInstance(stype, "standard/tmp");
    when(this.serializer.serialize(this.tref)).thenReturn(this.eurl);
}
Also used : DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) Type(java.lang.reflect.Type) SVGRasterizer(org.xwiki.platform.svg.SVGRasterizer) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) Before(org.junit.Before)

Example 15 with DefaultParameterizedType

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

the class WikiUserManagerScriptServiceTest method setUp.

@Before
public void setUp() throws Exception {
    // Components mocks
    wikiUserManager = mocker.getInstance(WikiUserManager.class);
    wikiDescriptorManager = mocker.getInstance(WikiDescriptorManager.class);
    authorizationManager = mocker.getInstance(AuthorizationManager.class);
    xcontextProvider = mocker.registerMockComponent(XWikiContext.TYPE_PROVIDER);
    documentReferenceResolver = mocker.getInstance(new DefaultParameterizedType(null, DocumentReferenceResolver.class, String.class));
    execution = mocker.getInstance(Execution.class);
    // Frequent uses
    xcontext = mock(XWikiContext.class);
    when(xcontextProvider.get()).thenReturn(xcontext);
    when(wikiDescriptorManager.getMainWikiId()).thenReturn("mainWiki");
    when(wikiDescriptorManager.getCurrentWikiId()).thenReturn("subwiki");
    executionContext = new ExecutionContext();
    when(execution.getContext()).thenReturn(executionContext);
    currentDoc = mock(XWikiDocument.class);
    when(xcontext.getDoc()).thenReturn(currentDoc);
    userDocRef = new DocumentReference("mainWiki", "XWiki", "User");
    when(xcontext.getUserReference()).thenReturn(userDocRef);
    DocumentReference userReference = new DocumentReference("mainWiki", "XWiki", "User");
    when(documentReferenceResolver.resolve("mainWiki:XWiki.User")).thenReturn(userReference);
    DocumentReference otherUser = new DocumentReference("mainWiki", "XWiki", "OtherUser");
    when(documentReferenceResolver.resolve("mainWiki:XWiki.OtherUser")).thenReturn(otherUser);
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) Execution(org.xwiki.context.Execution) ExecutionContext(org.xwiki.context.ExecutionContext) WikiDescriptorManager(org.xwiki.wiki.descriptor.WikiDescriptorManager) XWikiContext(com.xpn.xwiki.XWikiContext) AuthorizationManager(org.xwiki.security.authorization.AuthorizationManager) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) DocumentReference(org.xwiki.model.reference.DocumentReference) WikiUserManager(org.xwiki.wiki.user.WikiUserManager) 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