use of com.xpn.xwiki.XWikiContext in project xwiki-platform by xwiki.
the class DefaultWikiComponentBuilderEventListener method installOrUpdateComponentRequirementXClass.
/**
* Verify that the {@link #DEPENDENCY_CLASS} exists and is up-to-date (act if not).
*
* @throws XWikiException on failure
*/
private void installOrUpdateComponentRequirementXClass() throws XWikiException {
XWikiContext xcontext = getXWikiContext();
XWikiDocument doc = xcontext.getWiki().getDocument(DEPENDENCY_CLASS_REFERENCE, xcontext);
BaseClass bclass = doc.getXClass();
bclass.setDocumentReference(doc.getDocumentReference());
boolean needsUpdate = false;
needsUpdate |= this.initializeXClassDocumentMetadata(doc, "Wiki Component Dependency XWiki Class");
needsUpdate |= bclass.addTextField(COMPONENT_ROLE_TYPE_FIELD, "Dependency Role Type", 30);
needsUpdate |= bclass.addTextField(COMPONENT_ROLE_HINT_FIELD, "Dependency Role Hint", 30);
needsUpdate |= bclass.addTextField(DEPENDENCY_BINDING_NAME_FIELD, "Binding name", 30);
if (needsUpdate) {
this.update(doc);
}
}
use of com.xpn.xwiki.XWikiContext in project xwiki-platform by xwiki.
the class DefaultWikiComponentBuilderEventListener method update.
/**
* Utility method for updating a wiki macro class definition document.
*
* @param doc xwiki document containing the wiki macro class.
* @throws XWikiException if an error occurs while saving the document.
*/
private void update(XWikiDocument doc) throws XWikiException {
XWikiContext xcontext = getXWikiContext();
xcontext.getWiki().saveDocument(doc, xcontext);
}
use of com.xpn.xwiki.XWikiContext in project xwiki-platform by xwiki.
the class AbstractExtensionScriptService method getCallerDocument.
protected XWikiDocument getCallerDocument() {
XWikiContext xcontext = this.xcontextProvider.get();
XWikiDocument sdoc = (XWikiDocument) xcontext.get("sdoc");
if (sdoc == null) {
sdoc = xcontext.getDoc();
}
return sdoc;
}
use of com.xpn.xwiki.XWikiContext in project xwiki-platform by xwiki.
the class Packager method reset.
/**
* @since 9.3RC1
*/
public void reset(DocumentReference reference, DocumentReference authorReference) throws IOException, XarException, XWikiException, XarExtensionExtension {
Collection<XarInstalledExtension> installedExtensions = getXarInstalledExtensionRepository().getXarInstalledExtensions(reference);
if (!installedExtensions.isEmpty()) {
XarInstalledExtension extension = installedExtensions.iterator().next();
// Remove the version if any since it does not make sense in a XAR
DocumentReference documentReference = cleanDocumentReference(reference);
XWikiDocument document = getXWikiDocument(documentReference, extension);
if (document != null) {
XWikiContext xcontext = this.xcontextProvider.get();
// Get database document
XWikiDocument databaseDocument = xcontext.getWiki().getDocument(documentReference, xcontext);
// Override data of database document with extension document
databaseDocument.apply(document, true);
// Make sure new version will have the right author
databaseDocument.setAuthorReference(authorReference);
databaseDocument.setContentAuthorReference(authorReference);
// Force generating new version
databaseDocument.setMetaDataDirty(true);
databaseDocument.setContentDirty(true);
// Save
xcontext.getWiki().saveDocument(databaseDocument, "Reset document from extension [" + extension + "]", xcontext);
} else {
throw new XarExtensionExtension("Can't find any document with reference [" + documentReference + "] in extension [" + extension.getId() + "]");
}
} else {
throw new XarExtensionExtension("Can't find any installed extension associated with the document reference [" + reference + "]");
}
}
use of com.xpn.xwiki.XWikiContext 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