Search in sources :

Example 1 with NamespacedComponentManager

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

the class ContextComponentManagerTest method testCreateDocumentComponentManager.

@Test
public void testCreateDocumentComponentManager() throws Exception {
    ComponentManagerManager manager = getComponentManager().getInstance(ComponentManagerManager.class);
    NamespacedComponentManager componentManager = (NamespacedComponentManager) manager.getComponentManager("document:wiki1:space1.space2.document1", true);
    assertNotNull(componentManager);
    assertEquals("document:wiki1:space1.space2.document1", componentManager.getNamespace());
    assertEquals("space:wiki1:space1.space2", ((NamespacedComponentManager) componentManager.getParent()).getNamespace());
    assertEquals("space:wiki1:space1", ((NamespacedComponentManager) componentManager.getParent().getParent()).getNamespace());
    assertEquals("wiki:wiki1", ((NamespacedComponentManager) componentManager.getParent().getParent().getParent()).getNamespace());
}
Also used : ComponentManagerManager(org.xwiki.component.internal.multi.ComponentManagerManager) NamespacedComponentManager(org.xwiki.component.manager.NamespacedComponentManager) Test(org.junit.Test)

Example 2 with NamespacedComponentManager

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

the class XWiki method onMandatoryDocumentInitializerAdded.

private void onMandatoryDocumentInitializerAdded(ComponentDescriptorAddedEvent event, ComponentManager componentManager) {
    String namespace;
    if (componentManager instanceof NamespacedComponentManager) {
        namespace = ((NamespacedComponentManager) componentManager).getNamespace();
    } else {
        namespace = null;
    }
    MandatoryDocumentInitializer initializer;
    try {
        initializer = componentManager.getInstance(MandatoryDocumentInitializer.class, event.getRoleHint());
        XWikiContext context = getXWikiContext();
        if (namespace == null) {
            // Initialize in main wiki
            initializeMandatoryDocument(context.getMainXWiki(), initializer, context);
            // Initialize in already initialized sub wikis (will be initialized in others when they are initialized)
            for (String wiki : this.initializedWikis.keySet()) {
                initializeMandatoryDocument(wiki, initializer, context);
            }
        } else if (namespace.startsWith("wiki:")) {
            // Initialize in the wiki where the extension is installed
            initializeMandatoryDocument(namespace.substring("wiki:".length()), initializer, context);
        }
    } catch (ComponentLookupException e) {
        LOGGER.error("Failed to lookup mandatory document initializer", e);
    }
}
Also used : MandatoryDocumentInitializer(com.xpn.xwiki.doc.MandatoryDocumentInitializer) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) ParseGroovyFromString(com.xpn.xwiki.internal.render.groovy.ParseGroovyFromString) IncludeServletAsString(com.xpn.xwiki.web.includeservletasstring.IncludeServletAsString) NamespacedComponentManager(org.xwiki.component.manager.NamespacedComponentManager)

Aggregations

NamespacedComponentManager (org.xwiki.component.manager.NamespacedComponentManager)2 MandatoryDocumentInitializer (com.xpn.xwiki.doc.MandatoryDocumentInitializer)1 ParseGroovyFromString (com.xpn.xwiki.internal.render.groovy.ParseGroovyFromString)1 IncludeServletAsString (com.xpn.xwiki.web.includeservletasstring.IncludeServletAsString)1 Test (org.junit.Test)1 ComponentManagerManager (org.xwiki.component.internal.multi.ComponentManagerManager)1 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)1