Search in sources :

Example 1 with XarExtensionPlan

use of org.xwiki.extension.xar.internal.handler.XarExtensionPlan in project xwiki-platform by xwiki.

the class DocumentsModifiedDuringDistributionListener method checkXARHandler.

private void checkXARHandler(Event event, XWikiDocument document, XWikiContext xcontext) {
    ExecutionContext context = this.execution.getContext();
    if (context != null) {
        XarExtensionPlan xarExtensionPlan = (XarExtensionPlan) context.getProperty(XarExtensionPlan.CONTEXTKEY_XARINSTALLPLAN);
        if (xarExtensionPlan != null) {
            Request request = this.jobContext.getCurrentJob().getRequest();
            // It's a job started by the Distribution Wizard
            if (StringUtils.equals(request.<String>getProperty("context.action"), "distribution")) {
                String distributionWiki = request.getProperty("context.wiki");
                if (distributionWiki != null) {
                    DocumentReference reference = document.getDocumentReferenceWithLocale();
                    DocumentStatus.Action action = toAction(event);
                    LocalExtension previousExtension = xarExtensionPlan.getPreviousXarExtension(reference);
                    LocalExtension nextExtension = xarExtensionPlan.getNextXarExtension(reference);
                    addDocument(distributionWiki, document, action, previousExtension, nextExtension);
                }
            }
        }
    }
}
Also used : ExecutionContext(org.xwiki.context.ExecutionContext) XarExtensionPlan(org.xwiki.extension.xar.internal.handler.XarExtensionPlan) Request(org.xwiki.job.Request) Action(org.xwiki.extension.distribution.internal.DocumentsModifiedDuringDistributionListener.DocumentStatus.Action) LocalExtension(org.xwiki.extension.LocalExtension) DocumentReference(org.xwiki.model.reference.DocumentReference)

Example 2 with XarExtensionPlan

use of org.xwiki.extension.xar.internal.handler.XarExtensionPlan in project xwiki-platform by xwiki.

the class Packager method importDocumentToWiki.

private XarEntryMergeResult importDocumentToWiki(String comment, WikiReference wikiReference, InputStream inputStream, PackageConfiguration configuration) throws XWikiException, XarException, IOException {
    XWikiContext xcontext = this.xcontextProvider.get();
    XWikiDocument nextDocument;
    try {
        nextDocument = getXWikiDocument(inputStream, wikiReference);
    } catch (Exception e) {
        this.logger.error("Failed to parse document", e);
        return null;
    }
    DocumentReference reference = nextDocument.getDocumentReferenceWithLocale();
    XWikiDocument currentDocument = xcontext.getWiki().getDocument(reference, xcontext);
    currentDocument.loadAttachmentsContentSafe(xcontext);
    XWikiDocument previousDocument;
    XarExtensionPlan xarExtensionPlan = configuration.getXarExtensionPlan();
    if (xarExtensionPlan != null) {
        previousDocument = xarExtensionPlan.getPreviousXWikiDocument(reference, this);
    } else {
        previousDocument = null;
    }
    if (configuration.isVerbose()) {
        this.logger.info(LOG_INSTALLDOCUMENT_BEGIN, "Installing document [{}]", nextDocument.getDocumentReferenceWithLocale());
    }
    try {
        XarEntryMergeResult entityMergeResult = this.importer.saveDocument(comment, previousDocument, currentDocument, nextDocument, configuration);
        if (configuration.isVerbose()) {
            this.logger.info(LOG_INSTALLDOCUMENT_SUCCESS_END, "Done installing document [{}]", nextDocument.getDocumentReferenceWithLocale());
        }
        return entityMergeResult;
    } catch (Exception e) {
        if (configuration.isVerbose()) {
            this.logger.error(LOG_INSTALLDOCUMENT_FAILURE_END, "Failed to install document [{}]", nextDocument.getDocumentReferenceWithLocale(), e);
        }
    }
    return null;
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) XarExtensionPlan(org.xwiki.extension.xar.internal.handler.XarExtensionPlan) XWikiContext(com.xpn.xwiki.XWikiContext) XWikiException(com.xpn.xwiki.XWikiException) WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) FilterException(org.xwiki.filter.FilterException) XarException(org.xwiki.xar.XarException) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) IOException(java.io.IOException) LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) DocumentReference(org.xwiki.model.reference.DocumentReference)

Aggregations

XarExtensionPlan (org.xwiki.extension.xar.internal.handler.XarExtensionPlan)2 DocumentReference (org.xwiki.model.reference.DocumentReference)2 XWikiContext (com.xpn.xwiki.XWikiContext)1 XWikiException (com.xpn.xwiki.XWikiException)1 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)1 IOException (java.io.IOException)1 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)1 ExecutionContext (org.xwiki.context.ExecutionContext)1 LocalExtension (org.xwiki.extension.LocalExtension)1 Action (org.xwiki.extension.distribution.internal.DocumentsModifiedDuringDistributionListener.DocumentStatus.Action)1 FilterException (org.xwiki.filter.FilterException)1 Request (org.xwiki.job.Request)1 LocalDocumentReference (org.xwiki.model.reference.LocalDocumentReference)1 WikiManagerException (org.xwiki.wiki.manager.WikiManagerException)1 XarException (org.xwiki.xar.XarException)1