Search in sources :

Example 56 with ComponentManager

use of org.xwiki.component.manager.ComponentManager in project xwiki-platform by xwiki.

the class CascadingVfsPermissionChecker method checkPermission.

@Override
public void checkPermission(VfsResourceReference resourceReference) throws VfsException {
    // Prevent using a VFS scheme that correspond to the hint of this component
    String scheme = resourceReference.getURI().getScheme();
    if (HINT.equals(scheme)) {
        throw new VfsException(String.format("[%s] is a reserved VFS URI scheme and cannot be used.", HINT));
    }
    // Look for a scheme-specific permission checker
    VfsPermissionChecker resolvedChecker;
    ComponentManager componentManager = this.componentManagerProvider.get();
    try {
        resolvedChecker = componentManager.getInstance(VfsPermissionChecker.class, scheme);
    } catch (ComponentLookupException e) {
        // Use the Generic permission checker
        try {
            resolvedChecker = componentManager.getInstance(VfsPermissionChecker.class);
        } catch (ComponentLookupException ee) {
            throw new VfsException(String.format("No VFS Permission Checked has been found in the system. " + "Refusing access to VFS URI scheme [%s]", scheme), ee);
        }
    }
    resolvedChecker.checkPermission(resourceReference);
}
Also used : VfsException(org.xwiki.vfs.VfsException) VfsPermissionChecker(org.xwiki.vfs.VfsPermissionChecker) ComponentManager(org.xwiki.component.manager.ComponentManager) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException)

Example 57 with ComponentManager

use of org.xwiki.component.manager.ComponentManager in project xwiki-platform by xwiki.

the class JobRootResourceReferenceHandler method handleChild.

private void handleChild(ParentResourceReference reference) throws ResourceReferenceHandlerException {
    if (StringUtils.isNotEmpty(reference.getChild())) {
        ComponentManager componentManager = this.componentManagerProvider.get();
        if (componentManager.hasComponent(JobResourceReferenceHandler.class, reference.getChild())) {
            JobResourceReferenceHandler child;
            try {
                child = componentManager.getInstance(JobResourceReferenceHandler.class, reference.getChild());
            } catch (ComponentLookupException e) {
                throw new ResourceReferenceHandlerException("Failed to initialize job resource handler with hint [" + reference.getChild() + "]");
            }
            child.handle(reference);
        } else {
            throw new ResourceReferenceHandlerException("Unknow job resource handler with hint [" + reference.getChild() + "]");
        }
    } else {
    // TODO: put some explanation about the various services provided by the job resource handler
    }
}
Also used : ResourceReferenceHandlerException(org.xwiki.resource.ResourceReferenceHandlerException) ComponentManager(org.xwiki.component.manager.ComponentManager) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException)

Example 58 with ComponentManager

use of org.xwiki.component.manager.ComponentManager in project xwiki-platform by xwiki.

the class DocumentTreeNode method initialize.

@Override
public void initialize() throws InitializationException {
    String[] nonLeafChildNodeTypes = new String[] { "translations", "attachments", "classProperties", "objects" };
    ComponentManager contextComponentManager = this.contextComponentManagerProvider.get();
    try {
        for (String nonLeafChildNodeType : nonLeafChildNodeTypes) {
            TreeNode treeNode = contextComponentManager.getInstance(TreeNode.class, nonLeafChildNodeType);
            this.nonLeafChildNodes.put(nonLeafChildNodeType, treeNode);
        }
    } catch (ComponentLookupException e) {
        throw new InitializationException("Failed to lookup the child components.", e);
    }
}
Also used : TreeNode(org.xwiki.tree.TreeNode) ComponentManager(org.xwiki.component.manager.ComponentManager) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) InitializationException(org.xwiki.component.phase.InitializationException)

Example 59 with ComponentManager

use of org.xwiki.component.manager.ComponentManager in project xwiki-platform by xwiki.

the class DefaultNotificationFilterManagerTest method setUp.

@Before
public void setUp() throws Exception {
    componentManager = mocker.registerMockComponent(ComponentManager.class);
    wikiDescriptorManager = mocker.registerMockComponent(WikiDescriptorManager.class);
    modelBridge = mocker.registerMockComponent(ModelBridge.class, "cached");
    testUser = new DocumentReference("wiki", "test", "user");
    testProvider = mock(NotificationFilterPreferenceProvider.class);
    when(componentManager.getInstanceList(NotificationFilterPreferenceProvider.class)).thenReturn(Collections.singletonList(testProvider));
    // Set a default comportment for the wikiDescriptorManager
    when(wikiDescriptorManager.getMainWikiId()).thenReturn("wiki");
    when(wikiDescriptorManager.getCurrentWikiId()).thenReturn("currentWikiId");
    when(wikiDescriptorManager.getAllIds()).thenReturn(Arrays.asList("wiki", "currentWikiId"));
}
Also used : WikiDescriptorManager(org.xwiki.wiki.descriptor.WikiDescriptorManager) NotificationFilterPreferenceProvider(org.xwiki.notifications.filters.NotificationFilterPreferenceProvider) ComponentManager(org.xwiki.component.manager.ComponentManager) DocumentReference(org.xwiki.model.reference.DocumentReference) Before(org.junit.Before)

Example 60 with ComponentManager

use of org.xwiki.component.manager.ComponentManager in project xwiki-platform by xwiki.

the class DefaultDocumentRevisionProvider method getRevision.

@Override
public XWikiDocument getRevision(DocumentReference reference, String revision) throws XWikiException {
    // Parse the version
    String revisionPrefix = null;
    if (revision != null) {
        int revisionPrefixIndex = revision.indexOf(':');
        if (revisionPrefixIndex > 0) {
            revisionPrefix = revision.substring(0, revisionPrefixIndex);
        }
    }
    String shortRevision;
    if (revisionPrefix != null) {
        shortRevision = revision.substring(revisionPrefix.length() + 1);
    } else {
        shortRevision = revision;
    }
    // Find the provider
    DocumentRevisionProvider provider = this.databaseDocumentRevisionProvider;
    if (revisionPrefix != null) {
        ComponentManager componentManager = this.componentManagerProvider.get();
        if (componentManager.hasComponent(DocumentRevisionProvider.class, revisionPrefix)) {
            try {
                provider = componentManager.getInstance(DocumentRevisionProvider.class, revisionPrefix);
            } catch (ComponentLookupException e) {
                throw new XWikiException("Failed to get revision provider for revision [" + revision + "]", e);
            }
        }
    }
    // Load the document revision
    return provider.getRevision(reference, shortRevision);
}
Also used : ComponentManager(org.xwiki.component.manager.ComponentManager) DocumentRevisionProvider(com.xpn.xwiki.doc.DocumentRevisionProvider) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) XWikiException(com.xpn.xwiki.XWikiException)

Aggregations

ComponentManager (org.xwiki.component.manager.ComponentManager)76 Test (org.junit.Test)34 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)23 DefaultParameterizedType (org.xwiki.component.util.DefaultParameterizedType)18 DocumentReference (org.xwiki.model.reference.DocumentReference)17 Provider (javax.inject.Provider)14 NamespacedComponentManager (org.xwiki.component.manager.NamespacedComponentManager)12 Before (org.junit.Before)11 DefaultComponentDescriptor (org.xwiki.component.descriptor.DefaultComponentDescriptor)11 XWikiContext (com.xpn.xwiki.XWikiContext)9 Expectations (org.jmock.Expectations)9 WikiReference (org.xwiki.model.reference.WikiReference)9 HashMap (java.util.HashMap)7 Execution (org.xwiki.context.Execution)7 SpaceReference (org.xwiki.model.reference.SpaceReference)7 XWiki (com.xpn.xwiki.XWiki)6 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)6 ArrayList (java.util.ArrayList)6 ExecutionContext (org.xwiki.context.ExecutionContext)6 MimeMessage (javax.mail.internet.MimeMessage)5