diff --git a/src/main/java/org/outerj/daisy/diff/html/dom/ImageNode.java b/src/main/java/org/outerj/daisy/diff/html/dom/ImageNode.java index 5d2b907..9430bc3 100644 --- a/src/main/java/org/outerj/daisy/diff/html/dom/ImageNode.java +++ b/src/main/java/org/outerj/daisy/diff/html/dom/ImageNode.java @@ -42,7 +42,13 @@ public boolean isSameText(Object other) { } catch (ClassCastException e) { return false; } - return getText().equalsIgnoreCase(otherImageNode.getText()); + TagNode polarionRteLink = getEnclosingPolarionRteLink(this.getParent()); + TagNode anotherPolarionRteLink = otherImageNode.getParent(); + if (polarionRteLink != null && anotherPolarionRteLink != null && pairedLinks(polarionRteLink, anotherPolarionRteLink)) { + return true; + } else { + return getText().equalsIgnoreCase(otherImageNode.getText()); + } } public AttributesImpl getAttributes() { diff --git a/src/main/java/org/outerj/daisy/diff/html/dom/Node.java b/src/main/java/org/outerj/daisy/diff/html/dom/Node.java index 5559524..083a2ee 100644 --- a/src/main/java/org/outerj/daisy/diff/html/dom/Node.java +++ b/src/main/java/org/outerj/daisy/diff/html/dom/Node.java @@ -18,8 +18,10 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.Objects; import org.outerj.daisy.diff.html.dom.helper.LastCommonParentResult; +import org.xml.sax.Attributes; /** * Represents any element in the DOM tree of a HTML file. @@ -215,4 +217,43 @@ public void setWhiteAfter(boolean whiteAfter) { public abstract Node getRightMostChild(); + protected TagNode getEnclosingPolarionRteLink(TagNode node) { + if (node == null) { + return null; + } else if (isPolarionRteLink(node)) { + return node; + } else { + TagNode parent = node.getParent(); + if (parent != null && ("span".equals(parent.getQName()) || "a".equals(parent.getQName()))) { + return getEnclosingPolarionRteLink(parent); + } else { + return null; // If parent node is not span or anchor - stop navigating, because it's not a Polarion RTE link subtree + } + } + } + + protected boolean isPolarionRteLink(TagNode node) { + return "span".equals(node.getQName()) && "polarion-rte-link".equals(node.getAttributes().getValue("class")); + } + + protected boolean pairedLinks(TagNode linkA, TagNode linkB) { + return Objects.equals(getOptionId(linkA.getAttributes()), getOptionId(linkB.getAttributes())) + && ( + Objects.equals(getItemId(linkA.getAttributes()), getPairedItemId(linkB.getAttributes())) + || Objects.equals(getItemId(linkB.getAttributes()), getPairedItemId(linkA.getAttributes())) + ); + } + + protected String getItemId(Attributes attributes) { + return attributes.getValue("data-item-id"); + } + + protected String getPairedItemId(Attributes attributes) { + return attributes.getValue("data-paired-item-id"); + } + + protected String getOptionId(Attributes attributes) { + return attributes.getValue("data-option-id"); + } + } diff --git a/src/main/java/org/outerj/daisy/diff/html/dom/SeparatingNode.java b/src/main/java/org/outerj/daisy/diff/html/dom/SeparatingNode.java index 140f025..ac8047a 100644 --- a/src/main/java/org/outerj/daisy/diff/html/dom/SeparatingNode.java +++ b/src/main/java/org/outerj/daisy/diff/html/dom/SeparatingNode.java @@ -18,14 +18,16 @@ public SeparatingNode(TagNode parent) { @Override public boolean equals(Object other) { - // No other separator is equal to this one. This has the effect - // that text nodes separated by such a separator can never be - // treated as a text sequence by the RangeDifferencer/TextNodeComparator. - - if (other == this) { + TagNode polarionRteLink = getEnclosingPolarionRteLink(this.getParent()); + TagNode anotherPolarionRteLink = (other instanceof TextNode) ? getEnclosingPolarionRteLink(((TextNode) other).getParent()) : null; + if (polarionRteLink != null && anotherPolarionRteLink != null && pairedLinks(polarionRteLink, anotherPolarionRteLink)) { return true; + } else { + // No other separator is equal to this one. This has the effect + // that text nodes separated by such a separator can never be + // treated as a text sequence by the RangeDifferencer/TextNodeComparator. + return other == this; } - return false; } } diff --git a/src/main/java/org/outerj/daisy/diff/html/dom/TagNode.java b/src/main/java/org/outerj/daisy/diff/html/dom/TagNode.java index 7896ef7..92a13bd 100644 --- a/src/main/java/org/outerj/daisy/diff/html/dom/TagNode.java +++ b/src/main/java/org/outerj/daisy/diff/html/dom/TagNode.java @@ -230,7 +230,11 @@ protected boolean isSimilarTag(Node another) { boolean result = false; if (another instanceof TagNode) { TagNode otherNode = (TagNode) another; - if (this.getQName().equalsIgnoreCase(otherNode.getQName())) { + TagNode polarionRteLink = getEnclosingPolarionRteLink(this); + TagNode anotherPolarionRteLink = getEnclosingPolarionRteLink(otherNode); + if (polarionRteLink != null && anotherPolarionRteLink != null && pairedLinks(polarionRteLink, anotherPolarionRteLink)) { + return true; + } else if (this.getQName().equalsIgnoreCase(otherNode.getQName())) { result = hasSameAttributes(otherNode.getAttributes()); } } diff --git a/src/main/java/org/outerj/daisy/diff/html/dom/TextNode.java b/src/main/java/org/outerj/daisy/diff/html/dom/TextNode.java index 41483b6..a6e2b64 100644 --- a/src/main/java/org/outerj/daisy/diff/html/dom/TextNode.java +++ b/src/main/java/org/outerj/daisy/diff/html/dom/TextNode.java @@ -85,8 +85,15 @@ public boolean isSameText(Object other) { } catch (ClassCastException e) { return false; } - return getText().replace('\n', ' ').equals( - otherTextNode.getText().replace('\n', ' ')); + + TagNode polarionRteLink = getEnclosingPolarionRteLink(this.getParent()); + TagNode anotherPolarionRteLink = getEnclosingPolarionRteLink(otherTextNode.getParent()); + if (polarionRteLink != null && anotherPolarionRteLink != null && pairedLinks(polarionRteLink, anotherPolarionRteLink)) { + return true; + } else { + return getText().replace('\n', ' ').equals( + otherTextNode.getText().replace('\n', ' ')); + } } public void setModification(Modification m) {