Search in sources :

Example 6 with MandatoryDocumentInitializer

use of com.xpn.xwiki.doc.MandatoryDocumentInitializer 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

MandatoryDocumentInitializer (com.xpn.xwiki.doc.MandatoryDocumentInitializer)6 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)3 Test (org.junit.Test)2 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)2 DocumentReference (org.xwiki.model.reference.DocumentReference)2 LocalDocumentReference (org.xwiki.model.reference.LocalDocumentReference)2 XWikiAttachment (com.xpn.xwiki.doc.XWikiAttachment)1 ParseGroovyFromString (com.xpn.xwiki.internal.render.groovy.ParseGroovyFromString)1 BaseObject (com.xpn.xwiki.objects.BaseObject)1 BaseClass (com.xpn.xwiki.objects.classes.BaseClass)1 IncludeServletAsString (com.xpn.xwiki.web.includeservletasstring.IncludeServletAsString)1 Locale (java.util.Locale)1 Priority (javax.annotation.Priority)1 ComponentManager (org.xwiki.component.manager.ComponentManager)1 NamespacedComponentManager (org.xwiki.component.manager.NamespacedComponentManager)1 XarInstalledExtension (org.xwiki.extension.xar.internal.repository.XarInstalledExtension)1