use of com.xpn.xwiki.doc.AttachmentDiff 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;
}
use of com.xpn.xwiki.doc.AttachmentDiff in project xwiki-platform by xwiki.
the class AttachmentEventGeneratorListener method onDocumentUpdatedEvent.
/**
* @param originalDoc the previous version of the document
* @param doc the new version of the document
* @param context the XWiki context
*/
private void onDocumentUpdatedEvent(XWikiDocument originalDoc, XWikiDocument doc, XWikiContext context) {
ObservationManager observation = Utils.getComponent(ObservationManager.class);
String reference = this.defaultEntityReferenceSerializer.serialize(doc.getDocumentReference());
for (AttachmentDiff diff : doc.getAttachmentDiff(originalDoc, doc, context)) {
if (StringUtils.isEmpty(diff.getOrigVersion())) {
observation.notify(new AttachmentAddedEvent(reference, diff.getFileName()), doc, context);
} else if (StringUtils.isEmpty(diff.getNewVersion())) {
observation.notify(new AttachmentDeletedEvent(reference, diff.getFileName()), doc, context);
} else {
observation.notify(new AttachmentUpdatedEvent(reference, diff.getFileName()), doc, context);
}
}
}
use of com.xpn.xwiki.doc.AttachmentDiff in project xwiki-platform by xwiki.
the class DefaultWatchListEventHTMLDiffExtractor method getHTMLDiff.
@Override
public String getHTMLDiff(WatchListEvent event) throws WatchListException {
XWikiContext context = contextProvider.get();
StringBuffer result = new StringBuffer();
try {
DiffPluginApi diff = (DiffPluginApi) context.getWiki().getPluginApi("diff", context);
XWikiDocument d2 = context.getWiki().getDocument(event.getDocumentReference(), context);
if (event.getType().equals(WatchListEventType.CREATE)) {
d2 = context.getWiki().getDocument(d2, INITIAL_DOCUMENT_VERSION, context);
}
XWikiDocument d1 = context.getWiki().getDocument(d2, event.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, event.getFullName(), diff));
result.append(getObjectsHTMLDiff(classDiffs, true, event.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);
}
return result.toString();
} catch (Exception e) {
throw new WatchListException(String.format("Failed to compute HTML diff for event type [%s] on [%s]", event.getType(), event.getPrefixedFullName()), e);
}
}
Aggregations