use of org.xwiki.extension.xar.job.diff.EntityUnifiedDiff in project xwiki-platform by xwiki.
the class AttachmentUnifiedDiffBuilder method addAttachmentDiff.
/**
* Computes the differences, in unified format, between two versions of an attachment and adds the result to the
* given {@link DocumentUnifiedDiff}.
*
* @param previousAttachment the previous version of the attachment
* @param nextAttachment the next version of the attachment
* @param documentDiff where to add the differences
*/
public void addAttachmentDiff(XWikiAttachment previousAttachment, XWikiAttachment nextAttachment, DocumentUnifiedDiff documentDiff) {
AttachmentReference previousReference = getAttachmentVersionReference(previousAttachment, documentDiff.getPreviousReference());
AttachmentReference nextReference = getAttachmentVersionReference(nextAttachment, documentDiff.getNextReference());
EntityUnifiedDiff<AttachmentReference> attachmentDiff = new EntityUnifiedDiff<>(previousReference, nextReference);
if ((previousAttachment == null || isSmallTextFile(previousAttachment)) && (nextAttachment == null || isSmallTextFile(nextAttachment))) {
// Compute content differences.
maybeAddDiff(attachmentDiff, CONTENT, getContentAsString(previousAttachment), getContentAsString(nextAttachment));
} else {
// The size difference is useful when the content difference is not shown.
maybeAddDiff(attachmentDiff, "size", previousAttachment == null ? null : previousAttachment.getLongSize(), nextAttachment == null ? null : nextAttachment.getLongSize());
if (attachmentDiff.isEmpty() && !contentEquals(previousAttachment, nextAttachment)) {
// If the files have the same size but the content is different then show an empty list.
attachmentDiff.put(CONTENT, Collections.<UnifiedDiffBlock<String, Character>>emptyList());
}
}
if (attachmentDiff.size() > 0) {
documentDiff.getAttachmentDiffs().add(attachmentDiff);
}
}
use of org.xwiki.extension.xar.job.diff.EntityUnifiedDiff in project xwiki-platform by xwiki.
the class DocumentUnifiedDiffBuilder method addObjectDiff.
private void addObjectDiff(BaseObject previousObject, BaseObject nextObject, DocumentUnifiedDiff documentDiff) {
ObjectReference previousReference = getObjectVersionReference(previousObject, documentDiff.getPreviousReference());
ObjectReference nextReference = getObjectVersionReference(nextObject, documentDiff.getNextReference());
EntityUnifiedDiff<ObjectReference> objectDiff = new EntityUnifiedDiff<>(previousReference, nextReference);
addObjectDiff(previousObject == null ? new BaseObject() : previousObject, nextObject == null ? new BaseObject() : nextObject, objectDiff);
if (objectDiff.size() > 0) {
documentDiff.getObjectDiffs().add(objectDiff);
}
}
use of org.xwiki.extension.xar.job.diff.EntityUnifiedDiff in project xwiki-platform by xwiki.
the class DocumentUnifiedDiffBuilder method addClassPropertyDiff.
private void addClassPropertyDiff(PropertyClass previousProperty, PropertyClass nextProperty, DocumentUnifiedDiff documentDiff) {
ClassPropertyReference previousReference = getClassPropertyVersionReference(previousProperty, documentDiff.getPreviousReference());
ClassPropertyReference nextReference = getClassPropertyVersionReference(nextProperty, documentDiff.getNextReference());
EntityUnifiedDiff<ClassPropertyReference> classPropertyDiff = new EntityUnifiedDiff<>(previousReference, nextReference);
// Catch a property type change.
maybeAddDiff(classPropertyDiff, "type", previousProperty == null ? null : previousProperty.getClassType(), nextProperty == null ? null : nextProperty.getClassType());
addObjectDiff(previousProperty == null ? new PropertyClass() : previousProperty, nextProperty == null ? new PropertyClass() : nextProperty, classPropertyDiff);
// The property name is already specified by the previous / next reference.
classPropertyDiff.remove("name");
// This meta property is not used (there's no UI to change it).
classPropertyDiff.remove("unmodifiable");
if (classPropertyDiff.size() > 0) {
documentDiff.getClassPropertyDiffs().add(classPropertyDiff);
}
}
Aggregations