Search in sources :

Example 1 with EntityUnifiedDiff

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);
    }
}
Also used : AttachmentReference(org.xwiki.model.reference.AttachmentReference) EntityUnifiedDiff(org.xwiki.extension.xar.job.diff.EntityUnifiedDiff)

Example 2 with EntityUnifiedDiff

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);
    }
}
Also used : EntityUnifiedDiff(org.xwiki.extension.xar.job.diff.EntityUnifiedDiff) BaseObjectReference(com.xpn.xwiki.objects.BaseObjectReference) ObjectReference(org.xwiki.model.reference.ObjectReference) BaseObject(com.xpn.xwiki.objects.BaseObject)

Example 3 with EntityUnifiedDiff

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);
    }
}
Also used : EntityUnifiedDiff(org.xwiki.extension.xar.job.diff.EntityUnifiedDiff) ClassPropertyReference(org.xwiki.model.reference.ClassPropertyReference) PropertyClass(com.xpn.xwiki.objects.classes.PropertyClass)

Aggregations

EntityUnifiedDiff (org.xwiki.extension.xar.job.diff.EntityUnifiedDiff)3 BaseObject (com.xpn.xwiki.objects.BaseObject)1 BaseObjectReference (com.xpn.xwiki.objects.BaseObjectReference)1 PropertyClass (com.xpn.xwiki.objects.classes.PropertyClass)1 AttachmentReference (org.xwiki.model.reference.AttachmentReference)1 ClassPropertyReference (org.xwiki.model.reference.ClassPropertyReference)1 ObjectReference (org.xwiki.model.reference.ObjectReference)1