public class DefaultComparisonFormatter extends Object implements ComparisonFormatter
Comparison
Object.Constructor and Description |
---|
DefaultComparisonFormatter() |
Modifier and Type | Method and Description |
---|---|
protected void |
appendAttribute(StringBuilder sb,
Attr aNode)
Formats a placeholder for an attribute for
getShortString(org.w3c.dom.Node, java.lang.String, org.xmlunit.diff.ComparisonType) . |
protected void |
appendComment(StringBuilder sb,
Comment aNode)
Formats a comment for
getShortString(org.w3c.dom.Node, java.lang.String, org.xmlunit.diff.ComparisonType) . |
protected void |
appendDocumentElementIndication(StringBuilder sb,
Document doc)
Appends a short indication of the document's root element like "<ElementName...
|
protected boolean |
appendDocumentType(StringBuilder sb,
DocumentType type)
Appends the XML DOCTYPE for
getShortString(org.w3c.dom.Node, java.lang.String, org.xmlunit.diff.ComparisonType) or appendFullDocumentHeader(java.lang.StringBuilder, org.w3c.dom.Document) if present. |
protected boolean |
appendDocumentXmlDeclaration(StringBuilder sb,
Document doc)
Appends the XML declaration for
getShortString(org.w3c.dom.Node, java.lang.String, org.xmlunit.diff.ComparisonType) or appendFullDocumentHeader(java.lang.StringBuilder, org.w3c.dom.Document) if it contains
non-default values. |
protected void |
appendElement(StringBuilder sb,
Element aNode)
Formats a placeholder for an element for
getShortString(org.w3c.dom.Node, java.lang.String, org.xmlunit.diff.ComparisonType) . |
protected void |
appendFullDocumentHeader(StringBuilder sb,
Document doc)
Appends the XML declaration and DOCTYPE if present as well as the document's root element for
getFullFormattedXml(org.w3c.dom.Node, org.xmlunit.diff.ComparisonType, boolean) . |
protected void |
appendProcessingInstruction(StringBuilder sb,
ProcessingInstruction instr)
Formats a processing instruction for
getShortString(org.w3c.dom.Node, java.lang.String, org.xmlunit.diff.ComparisonType) . |
protected void |
appendText(StringBuilder sb,
Text aNode)
Formats a text or CDATA node for
getShortString(org.w3c.dom.Node, java.lang.String, org.xmlunit.diff.ComparisonType) . |
protected void |
appendXPath(StringBuilder sb,
String xpath)
Appends the XPath information for
getShortString(org.w3c.dom.Node, java.lang.String, org.xmlunit.diff.ComparisonType) if present. |
protected Transformer |
createXmlTransformer(int numberOfBlanksToIndent)
Create a default Transformer to format a XML-Node to a String.
|
String |
getDescription(Comparison difference)
Return a short String of the Comparison including the XPath and the shorten value of the effected control and
test Node.
|
String |
getDetails(Comparison.Detail difference,
ComparisonType type,
boolean formatXml)
Return the xml node from
Comparison.Detail.getTarget() as formatted String. |
protected String |
getFormattedNodeXml(Node nodeToConvert,
boolean formatXml)
Formats a node with the help of an identity XML transformation.
|
protected String |
getFullFormattedXml(Node node,
ComparisonType type,
boolean formatXml)
Formats the node using a format suitable for the node type and comparison.
|
protected String |
getShortString(Node node,
String xpath,
ComparisonType type)
Return a String representation for
getShortString(org.w3c.dom.Node, java.lang.String, org.xmlunit.diff.ComparisonType) that describes the "thing" that has been compared so
users know how to locate it. |
protected Object |
getValue(Object value,
ComparisonType type)
May alter the display of a comparison value for
getShortString(org.w3c.dom.Node, java.lang.String, org.xmlunit.diff.ComparisonType) based on the comparison type. |
protected String |
nodeType(short type)
Provides a display text for the constant values of the
Node class that represent node types. |
public String getDescription(Comparison difference)
In general the String will look like "Expected X 'Y' but was 'Z' - comparing A to B" where A and B are the
result of invoking getShortString(org.w3c.dom.Node, java.lang.String, org.xmlunit.diff.ComparisonType)
on the target and XPath of the control and test details of the
comparison. A is the description of the comparison and B and C are the control and test values (passed through
getValue(java.lang.Object, org.xmlunit.diff.ComparisonType)
) respectively.
For missing attributes the string has a slightly different format.
getDescription
in interface ComparisonFormatter
difference
- the comparison to describeprotected Object getValue(Object value, ComparisonType type)
getShortString(org.w3c.dom.Node, java.lang.String, org.xmlunit.diff.ComparisonType)
based on the comparison type.
This implementation returns value
unless it is a comparison of node types in which case the numeric
value (one of the constants defined in the Node
class) is mapped to a more useful String.
value
- the value to displaytype
- the comparison typeprotected String getShortString(Node node, String xpath, ComparisonType type)
getShortString(org.w3c.dom.Node, java.lang.String, org.xmlunit.diff.ComparisonType)
that describes the "thing" that has been compared so
users know how to locate it.
Examples are "<bar ...> at /foo[1]/bar[1]" for a comparison of elements or "<!-- Comment Text --> at /foo[2]/comment()[1]" for a comment.
This implementation dispatches to several appendX
methods based on the comparison type or the type of
the node.
node
- the node to describexpath
- xpath of the node if applicabletype
- the comparison typeprotected void appendXPath(StringBuilder sb, String xpath)
getShortString(org.w3c.dom.Node, java.lang.String, org.xmlunit.diff.ComparisonType)
if present.sb
- the builder to append toxpath
- the xpath to append, if anyprotected boolean appendDocumentXmlDeclaration(StringBuilder sb, Document doc)
getShortString(org.w3c.dom.Node, java.lang.String, org.xmlunit.diff.ComparisonType)
or appendFullDocumentHeader(java.lang.StringBuilder, org.w3c.dom.Document)
if it contains
non-default values.sb
- the builder to append toprotected void appendDocumentElementIndication(StringBuilder sb, Document doc)
getShortString(org.w3c.dom.Node, java.lang.String, org.xmlunit.diff.ComparisonType)
.sb
- the builder to append todoc
- the XML document nodeprotected boolean appendDocumentType(StringBuilder sb, DocumentType type)
getShortString(org.w3c.dom.Node, java.lang.String, org.xmlunit.diff.ComparisonType)
or appendFullDocumentHeader(java.lang.StringBuilder, org.w3c.dom.Document)
if present.sb
- the builder to append totype
- the document typeprotected void appendProcessingInstruction(StringBuilder sb, ProcessingInstruction instr)
getShortString(org.w3c.dom.Node, java.lang.String, org.xmlunit.diff.ComparisonType)
.sb
- the builder to append toinstr
- the processing instructionprotected void appendComment(StringBuilder sb, Comment aNode)
getShortString(org.w3c.dom.Node, java.lang.String, org.xmlunit.diff.ComparisonType)
.sb
- the builder to append toaNode
- the commentprotected void appendText(StringBuilder sb, Text aNode)
getShortString(org.w3c.dom.Node, java.lang.String, org.xmlunit.diff.ComparisonType)
.sb
- the builder to append toaNode
- the text or CDATA nodeprotected void appendElement(StringBuilder sb, Element aNode)
getShortString(org.w3c.dom.Node, java.lang.String, org.xmlunit.diff.ComparisonType)
.sb
- the builder to append toaNode
- the elementprotected void appendAttribute(StringBuilder sb, Attr aNode)
getShortString(org.w3c.dom.Node, java.lang.String, org.xmlunit.diff.ComparisonType)
.sb
- the builder to append toaNode
- the attributepublic String getDetails(Comparison.Detail difference, ComparisonType type, boolean formatXml)
Comparison.Detail.getTarget()
as formatted String.
Delegates to getFullFormattedXml(org.w3c.dom.Node, org.xmlunit.diff.ComparisonType, boolean)
unless the Comparison.Detail
's target
is null.
getDetails
in interface ComparisonFormatter
details
- The Comparison.getControlDetails()
or Comparison.getTestDetails()
.type
- the implementation can return different details depending on the ComparisonType.formatXml
- set this to true if the Comparison was generated with DiffBuilder.ignoreWhitespace()
- this affects the indentation of the generated output.protected String getFullFormattedXml(Node node, ComparisonType type, boolean formatXml)
The implementation outputs the document prolog and start element for Document
and DocumentType
nodes and may elect to format the node's parent element rather than just the node depending on the node and
comparison type. It delegates to appendFullDocumentHeader(java.lang.StringBuilder, org.w3c.dom.Document)
or getFormattedNodeXml(org.w3c.dom.Node, boolean)
.
node
- the node to formattype
- the comparison typeformatXml
- true if the Comparison was generated with DiffBuilder.ignoreWhitespace()
- this affects the indentation of the generated outputprotected void appendFullDocumentHeader(StringBuilder sb, Document doc)
getFullFormattedXml(org.w3c.dom.Node, org.xmlunit.diff.ComparisonType, boolean)
.sb
- the builder to append todoc
- the document to formatprotected String getFormattedNodeXml(Node nodeToConvert, boolean formatXml)
nodeToConvert
- the node to formatformatXml
- true if the Comparison was generated with DiffBuilder.ignoreWhitespace()
- this affects the indentation of the generated outputprotected Transformer createXmlTransformer(int numberOfBlanksToIndent) throws TransformerConfigurationException
numberOfBlanksToIndent
- the number of spaces which is used for indent the XML-structureTransformerConfigurationException
Copyright © 2001–2017 XMLUnit. All rights reserved.