Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/polarion rte links #18

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
41 changes: 41 additions & 0 deletions src/main/java/org/outerj/daisy/diff/html/dom/Node.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

}
6 changes: 5 additions & 1 deletion src/main/java/org/outerj/daisy/diff/html/dom/TagNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Expand Down
11 changes: 9 additions & 2 deletions src/main/java/org/outerj/daisy/diff/html/dom/TextNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading