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);
}
}
}
}
}
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;
}
Aggregations