public class Diff extends java.lang.Object implements DifferenceListener, ComparisonController
appendMessage
or toString
methods. NB: When comparing documents, the
comparison is halted as soon as the status (identical / similar / different)
is known with certainty. For a list of all differences between the documents
an instance of the DetailedDiff class
can be used
instead.Modifier and Type | Field and Description |
---|---|
private boolean |
compared |
private org.w3c.dom.Document |
controlDoc |
private DifferenceEngineContract |
differenceEngine |
private DifferenceListener |
differenceListenerDelegate |
private ElementQualifier |
elementQualifierDelegate |
private boolean |
haltComparison |
private boolean |
identical |
private MatchTracker |
matchTrackerDelegate |
private java.lang.StringBuilder |
messages |
private boolean |
similar |
private org.w3c.dom.Document |
testDoc |
RETURN_ACCEPT_DIFFERENCE, RETURN_IGNORE_DIFFERENCE_NODES_IDENTICAL, RETURN_IGNORE_DIFFERENCE_NODES_SIMILAR, RETURN_UPGRADE_DIFFERENCE_NODES_DIFFERENT
Modifier | Constructor and Description |
---|---|
protected |
Diff(Diff prototype)
Construct a Diff from a prototypical instance.
|
|
Diff(org.w3c.dom.Document controlDoc,
org.w3c.dom.Document testDoc)
Construct a Diff that compares the XML in two Documents
|
|
Diff(org.w3c.dom.Document controlDoc,
org.w3c.dom.Document testDoc,
DifferenceEngineContract comparator)
Construct a Diff that compares the XML in two Documents using a specific
DifferenceEngine
|
|
Diff(org.w3c.dom.Document controlDoc,
org.w3c.dom.Document testDoc,
DifferenceEngineContract comparator,
ElementQualifier elementQualifier)
Construct a Diff that compares the XML in two Documents using a specific
DifferenceEngine and ElementQualifier
|
|
Diff(javax.xml.transform.dom.DOMSource control,
javax.xml.transform.dom.DOMSource test)
Construct a Diff that compares the XML in two JAXP DOMSources
|
|
Diff(org.xml.sax.InputSource control,
org.xml.sax.InputSource test)
Construct a Diff that compares the XML read from two JAXP InputSources
|
|
Diff(java.io.Reader control,
java.io.Reader test)
Construct a Diff that compares the XML read from two Readers
|
|
Diff(java.lang.String control,
java.lang.String test)
Construct a Diff that compares the XML in two Strings
|
|
Diff(java.lang.String control,
Transform testTransform)
Construct a Diff that compares the XML in a control Document against the
result of a transformation
|
Modifier and Type | Method and Description |
---|---|
private void |
appendDifference(java.lang.StringBuilder appendTo,
Difference difference)
Append a meaningful message to the buffer of messages
|
java.lang.StringBuffer |
appendMessage(java.lang.StringBuffer toAppendTo)
Append the message from the result of this Diff instance to a specified
StringBuffer
|
protected void |
compare()
Top of the recursive comparison execution tree
|
int |
differenceFound(Difference difference)
DifferenceListener implementation.
|
int |
evaluate(Difference difference) |
private org.w3c.dom.Document |
getCommentlessDocument(org.w3c.dom.Document orig)
Removes all comment nodes if
comments are ignored . |
private DifferenceEngineContract |
getDifferenceEngine()
Lazily initializes the difference engine if it hasn't been set
via a constructor.
|
private org.w3c.dom.Document |
getManipulatedDocument(org.w3c.dom.Document orig)
Manipulates the given document according to the setting in the
XMLUnit class.
|
private org.w3c.dom.Document |
getNormalizedDocument(org.w3c.dom.Document orig) |
private org.w3c.dom.Document |
getWhitespaceManipulatedDocument(org.w3c.dom.Document originalDoc)
If
whitespace is ignored in
differences then manipulate the content to strip the redundant
whitespace |
boolean |
haltComparison(Difference afterDifference)
ComparisonController implementation.
|
boolean |
identical()
Return the result of a comparison.
|
void |
overrideDifferenceListener(DifferenceListener delegate)
Override the
DifferenceListener used to determine how
to handle differences that are found. |
void |
overrideElementQualifier(ElementQualifier delegate)
Override the
ElementQualifier used to determine which
control and test nodes are comparable for this difference comparison. |
void |
overrideMatchTracker(MatchTracker delegate)
Override the
MatchTracker used to track
successfully matched nodes. |
boolean |
similar()
Return the result of a comparison.
|
void |
skippedComparison(org.w3c.dom.Node control,
org.w3c.dom.Node test)
DifferenceListener implementation.
|
private static org.w3c.dom.Document |
toDocument(javax.xml.transform.dom.DOMSource d) |
java.lang.String |
toString()
Get the result of this Diff instance as a String
|
private boolean |
usesUnknownElementQualifier() |
private final org.w3c.dom.Document controlDoc
private final org.w3c.dom.Document testDoc
private boolean similar
private boolean identical
private boolean compared
private boolean haltComparison
private java.lang.StringBuilder messages
private DifferenceEngineContract differenceEngine
private DifferenceListener differenceListenerDelegate
private ElementQualifier elementQualifierDelegate
private MatchTracker matchTrackerDelegate
public Diff(java.lang.String control, java.lang.String test) throws org.xml.sax.SAXException, java.io.IOException
org.xml.sax.SAXException
java.io.IOException
public Diff(java.io.Reader control, java.io.Reader test) throws org.xml.sax.SAXException, java.io.IOException
org.xml.sax.SAXException
java.io.IOException
public Diff(org.w3c.dom.Document controlDoc, org.w3c.dom.Document testDoc)
public Diff(java.lang.String control, Transform testTransform) throws java.io.IOException, javax.xml.transform.TransformerException, org.xml.sax.SAXException
java.io.IOException
javax.xml.transform.TransformerException
org.xml.sax.SAXException
public Diff(org.xml.sax.InputSource control, org.xml.sax.InputSource test) throws org.xml.sax.SAXException, java.io.IOException
org.xml.sax.SAXException
java.io.IOException
public Diff(javax.xml.transform.dom.DOMSource control, javax.xml.transform.dom.DOMSource test)
public Diff(org.w3c.dom.Document controlDoc, org.w3c.dom.Document testDoc, DifferenceEngineContract comparator)
public Diff(org.w3c.dom.Document controlDoc, org.w3c.dom.Document testDoc, DifferenceEngineContract comparator, ElementQualifier elementQualifier)
protected Diff(Diff prototype)
prototype
- a prototypical instanceprivate org.w3c.dom.Document getWhitespaceManipulatedDocument(org.w3c.dom.Document originalDoc)
whitespace is ignored
in
differences then manipulate the content to strip the redundant
whitespaceoriginalDoc
- a document making up one half of this differenceprivate org.w3c.dom.Document getManipulatedDocument(org.w3c.dom.Document orig)
This may involve:
orig
- a document making up one half of this differenceprivate org.w3c.dom.Document getCommentlessDocument(org.w3c.dom.Document orig)
comments are ignored
.orig
- a document making up one half of this differenceprivate org.w3c.dom.Document getNormalizedDocument(org.w3c.dom.Document orig)
protected final void compare()
public boolean similar()
public boolean identical()
private void appendDifference(java.lang.StringBuilder appendTo, Difference difference)
appendTo
- the messages bufferdifference
- public int differenceFound(Difference difference)
overrideDifferenceListener
method has been called then the interpretation of the difference
will be delegated.differenceFound
in interface DifferenceListener
difference
- public int evaluate(Difference difference)
public void skippedComparison(org.w3c.dom.Node control, org.w3c.dom.Node test)
overrideDifferenceListener
method has been called then the call will be delegated
otherwise a message is printed to System.err
.skippedComparison
in interface DifferenceListener
control
- test
- DifferenceEngine
public boolean haltComparison(Difference afterDifference)
haltComparison
in interface ComparisonController
afterDifference
- Difference.isRecoverable()
public java.lang.StringBuffer appendMessage(java.lang.StringBuffer toAppendTo)
toAppendTo
- public java.lang.String toString()
Note: This method will perform the comparison and cache the result if it hasn't been performed already. Any configuration changes made after calling this method will be ignored.
toString
in class java.lang.Object
public void overrideDifferenceListener(DifferenceListener delegate)
DifferenceListener
used to determine how
to handle differences that are found.delegate
- the DifferenceListener instance to delegate handling to.public void overrideElementQualifier(ElementQualifier delegate)
ElementQualifier
used to determine which
control and test nodes are comparable for this difference comparison.delegate
- the ElementQualifier instance to delegate to.public void overrideMatchTracker(MatchTracker delegate)
MatchTracker
used to track
successfully matched nodes.delegate
- the MatchTracker instance to delegate handling to.private DifferenceEngineContract getDifferenceEngine()
private boolean usesUnknownElementQualifier()
private static org.w3c.dom.Document toDocument(javax.xml.transform.dom.DOMSource d)