Search in sources :

Example 1 with WikiComponentBuilder

use of org.xwiki.component.wiki.WikiComponentBuilder in project xwiki-platform by xwiki.

the class DefaultWikiComponentManagerEventListener method registerAllDocumentComponents.

/**
 * Register all the wiki components that come from a document in the current wiki.
 */
private void registerAllDocumentComponents() {
    try {
        // Retrieve all components definitions and register them.
        this.wikiComponentProviders = this.componentManager.getInstanceList(WikiComponentBuilder.class);
        for (WikiComponentBuilder provider : this.wikiComponentProviders) {
            for (DocumentReference reference : provider.getDocumentReferences()) {
                try {
                    List<WikiComponent> components = provider.buildComponents(reference);
                    this.wikiComponentManagerEventListenerHelper.registerComponentList(components);
                } catch (WikiComponentException e) {
                    this.logger.warn("Failed to build the wiki component located in the document [{}]: {}", reference, ExceptionUtils.getRootCauseMessage(e));
                }
            }
        }
    } catch (ComponentLookupException e) {
        this.logger.warn(String.format("Unable to get a list of registered WikiComponentBuilder: %s", e));
    }
}
Also used : WikiComponentException(org.xwiki.component.wiki.WikiComponentException) WikiComponentBuilder(org.xwiki.component.wiki.WikiComponentBuilder) WikiComponent(org.xwiki.component.wiki.WikiComponent) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) DocumentReference(org.xwiki.model.reference.DocumentReference)

Example 2 with WikiComponentBuilder

use of org.xwiki.component.wiki.WikiComponentBuilder in project xwiki-platform by xwiki.

the class DefaultWikiComponentManagerEventListener method registerDocumentComponents.

/**
 * Registers the components linked to the given document. For that, we get a list of providers that can build a
 * component using this document, then the first available provider is selected in order to register a component.
 *
 * @param documentReference the document used to create the component
 */
private void registerDocumentComponents(DocumentReference documentReference) {
    // Unregister all wiki components registered under the given entity. We do this as otherwise we would need to
    // handle the specific cases of elements added, elements updated and elements deleted, etc.
    // Instead we unregister all wiki components and re-register them all.
    this.wikiComponentManagerEventListenerHelper.unregisterComponents(documentReference);
    // Re-register all wiki components in the passed document
    for (WikiComponentBuilder provider : this.wikiComponentProviders) {
        // Check whether the given document has a wiki component defined in it.
        if (provider.getDocumentReferences().contains(documentReference)) {
            try {
                List<WikiComponent> components = provider.buildComponents(documentReference);
                this.wikiComponentManagerEventListenerHelper.registerComponentList(components);
            } catch (WikiComponentException e) {
                this.logger.warn("Failed to create wiki component(s) for document [{}]: {}", documentReference, ExceptionUtils.getRootCauseMessage(e));
            }
            break;
        }
    }
}
Also used : WikiComponentException(org.xwiki.component.wiki.WikiComponentException) WikiComponentBuilder(org.xwiki.component.wiki.WikiComponentBuilder) WikiComponent(org.xwiki.component.wiki.WikiComponent)

Aggregations

WikiComponent (org.xwiki.component.wiki.WikiComponent)2 WikiComponentBuilder (org.xwiki.component.wiki.WikiComponentBuilder)2 WikiComponentException (org.xwiki.component.wiki.WikiComponentException)2 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)1 DocumentReference (org.xwiki.model.reference.DocumentReference)1