use of com.xpn.xwiki.XWikiException in project xwiki-platform by xwiki.
the class DefaultWikiComponentBuilder method getDocumentReferences.
@Override
public List<DocumentReference> getDocumentReferences() {
List<DocumentReference> results = new ArrayList<DocumentReference>();
// Note that the query is made to work with Oracle which treats empty strings as null.
String query = ", BaseObject as obj, StringProperty as role where obj.className=? and obj.name=doc.fullName " + "and role.id.id=obj.id and role.id.name=? " + "and (role.value <> '' or (role.value is not null and '' is null))";
List<String> parameters = new ArrayList<String>();
parameters.add(COMPONENT_CLASS);
parameters.add(COMPONENT_ROLE_TYPE_FIELD);
try {
XWikiContext xcontext = xcontextProvider.get();
results.addAll(xcontext.getWiki().getStore().searchDocumentReferences(query, parameters, xcontext));
} catch (XWikiException e) {
this.logger.error("Failed to search for existing wiki components [{}]", e.getMessage());
}
return results;
}
use of com.xpn.xwiki.XWikiException 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;
}
use of com.xpn.xwiki.XWikiException in project xwiki-platform by xwiki.
the class DiffXarJob method diff.
private void diff(XWikiDocument document, ExtensionId extensionId) {
if (getRequest().isVerbose()) {
this.logger.info("Computing differences for document [{}]", document.getDocumentReferenceWithLocale());
}
// Use the extension id as the document version.
XWikiDocument previousDocument = document.duplicate(new DocumentVersionReference(document.getDocumentReference(), extensionId));
XWikiContext xcontext = this.xcontextProvider.get();
try {
XWikiDocument nextDocument = xcontext.getWiki().getDocument(document.getDocumentReferenceWithLocale(), xcontext);
if (nextDocument.isNew()) {
nextDocument = null;
}
maybeAddDocumentDiff(this.documentDiffBuilder.diff(previousDocument, nextDocument));
} catch (XWikiException e) {
this.logger.error("Failed to get document [{}] from the database.", document.getDocumentReference(), e);
}
}
use of com.xpn.xwiki.XWikiException in project xwiki-platform by xwiki.
the class WatchListEvent method getObjectsHTMLDiff.
/**
* @param objectDiffs List of object diff
* @param isXWikiClass is the diff to compute the diff for a xwiki class, the other possibility being a plain xwiki
* object
* @param documentFullName full name of the document the diff is computed for
* @param diff the diff plugin API
* @return The HTML diff
*/
private String getObjectsHTMLDiff(List<List<ObjectDiff>> objectDiffs, boolean isXWikiClass, String documentFullName, DiffPluginApi diff) {
StringBuffer result = new StringBuffer();
String propSeparator = ": ";
String prefix = (isXWikiClass) ? "class" : "object";
try {
for (List<ObjectDiff> oList : objectDiffs) {
if (oList.size() > 0) {
Div mainDiv = createDiffDiv(prefix + "Diff");
Span objectName = createDiffSpan(prefix + "ClassName");
if (isXWikiClass) {
objectName.addElement(getFullName());
} else {
objectName.addElement(oList.get(0).getClassName());
}
mainDiv.addElement(prefix + HTML_IMG_PLACEHOLDER_SUFFIX);
mainDiv.addElement(objectName);
for (ObjectDiff oDiff : oList) {
String propDiff = getPropertyHTMLDiff(oDiff, diff);
if (!StringUtils.isBlank(oDiff.getPropName()) && !StringUtils.isBlank(propDiff)) {
Div propDiv = createDiffDiv("propDiffContainer");
Span propNameSpan = createDiffSpan("propName");
propNameSpan.addElement(oDiff.getPropName() + propSeparator);
String shortPropType = StringUtils.removeEnd(oDiff.getPropType(), "Class").toLowerCase();
if (StringUtils.isBlank(shortPropType)) {
// When the diff shows a property that has been deleted, its type is not available.
shortPropType = HTML_IMG_METADATA_PREFIX;
}
propDiv.addElement(shortPropType + HTML_IMG_PLACEHOLDER_SUFFIX);
propDiv.addElement(propNameSpan);
Div propDiffDiv = createDiffDiv("propDiff");
propDiffDiv.addElement(propDiff);
propDiv.addElement(propDiffDiv);
mainDiv.addElement(propDiv);
}
}
result.append(mainDiv);
}
}
} catch (XWikiException e) {
// Catch the exception to be sure we won't send emails containing stacktraces to users.
e.printStackTrace();
}
return result.toString();
}
use of com.xpn.xwiki.XWikiException in project xwiki-platform by xwiki.
the class WatchListEvent method getHTMLDiff.
/**
* @return The diff, formatted in HTML, to display to the user when a document has been updated, or null if an error
* occurred while computing the diff
*/
public String getHTMLDiff() {
if (htmlDiff == null) {
try {
DiffPluginApi diff = (DiffPluginApi) context.getWiki().getPluginApi("diff", context);
StringBuffer result = new StringBuffer();
XWikiDocument d2 = context.getWiki().getDocument(getPrefixedFullName(), context);
if (getType().equals(WatchListEventType.CREATE)) {
d2 = context.getWiki().getDocument(d2, INITIAL_DOCUMENT_VERSION, context);
}
XWikiDocument d1 = context.getWiki().getDocument(d2, getPreviousVersion(), context);
List<AttachmentDiff> attachDiffs = d2.getAttachmentDiff(d1, d2, context);
List<List<ObjectDiff>> objectDiffs = d2.getObjectDiff(d1, d2, context);
List<List<ObjectDiff>> classDiffs = d2.getClassDiff(d1, d2, context);
List<MetaDataDiff> metaDiffs = d2.getMetaDataDiff(d1, d2, context);
if (!d1.getContent().equals(d2.getContent())) {
Div contentDiv = createDiffDiv("contentDiff");
String contentDiff = diff.getDifferencesAsHTML(d1.getContent(), d2.getContent(), false);
contentDiv.addElement(contentDiff);
result.append(contentDiv);
}
for (AttachmentDiff aDiff : attachDiffs) {
Div attachmentDiv = createDiffDiv("attachmentDiff");
attachmentDiv.addElement(HTML_IMG_ATTACHMENT_PREFIX + HTML_IMG_PLACEHOLDER_SUFFIX);
attachmentDiv.addElement(aDiff.toString());
result.append(attachmentDiv);
}
result.append(getObjectsHTMLDiff(objectDiffs, false, getFullName(), diff));
result.append(getObjectsHTMLDiff(classDiffs, true, getFullName(), diff));
for (MetaDataDiff mDiff : metaDiffs) {
Div metaDiv = createDiffDiv("metaDiff");
metaDiv.addElement(HTML_IMG_METADATA_PREFIX + HTML_IMG_PLACEHOLDER_SUFFIX);
metaDiv.addElement(mDiff.toString());
result.append(metaDiv);
}
htmlDiff = result.toString();
} catch (XWikiException e) {
// Catch the exception to be sure we won't send emails containing stacktraces to users.
e.printStackTrace();
}
}
return htmlDiff;
}
Aggregations