![]() |
![]() |
xmlunit-1.216:55:09.429 INFO jd.cli.Main - Decompiling xmlunit-1.2.jar package org.custommonkey.xmlunit; import org.w3c.dom.Attr; import org.w3c.dom.CDATASection; import org.w3c.dom.Comment; import org.w3c.dom.DocumentType; import org.w3c.dom.Element; import org.w3c.dom.Entity; import org.w3c.dom.EntityReference; import org.w3c.dom.Node; import org.w3c.dom.Notation; import org.w3c.dom.ProcessingInstruction; import org.w3c.dom.Text; public abstract class AbstractNodeTester implements NodeTester { public void testNode(Node aNode, NodeTest forTest) throws NodeTestException { switch (aNode.getNodeType()) { case 2: testAttribute((Attr)aNode); break; case 4: testCDATASection((CDATASection)aNode); break; case 8: testComment((Comment)aNode); break; case 10: testDocumentType((DocumentType)aNode); break; case 1: testElement((Element)aNode); break; case 6: testEntity((Entity)aNode); break; case 5: testEntityReference((EntityReference)aNode); break; case 12: testNotation((Notation)aNode); break; case 7: testProcessingInstruction((ProcessingInstruction)aNode); break; case 3: testText((Text)aNode); break; case 9: case 11: default: throw new NodeTestException("No delegate method for Node type", aNode); } } public void testAttribute(Attr attribute) throws NodeTestException { unhandled(attribute); } public void testCDATASection(CDATASection cdata) throws NodeTestException { unhandled(cdata); } public void testComment(Comment comment) throws NodeTestException { unhandled(comment); } public void testDocumentType(DocumentType doctype) throws NodeTestException { unhandled(doctype); } public void testElement(Element element) throws NodeTestException { unhandled(element); } public void testEntity(Entity entity) throws NodeTestException { unhandled(entity); } public void testEntityReference(EntityReference reference) throws NodeTestException { unhandled(reference); } public void testNotation(Notation notation) throws NodeTestException { unhandled(notation); } public void testProcessingInstruction(ProcessingInstruction instr) throws NodeTestException { unhandled(instr); } public void testText(Text text) throws NodeTestException { unhandled(text); } private void unhandled(Node aNode) throws NodeTestException { throw new NodeTestException("Test fails by default in AbstractNodeTester", aNode); } public void noMoreNodes(NodeTest forTest) throws NodeTestException {} } /* Location: * Qualified Name: org.custommonkey.xmlunit.AbstractNodeTester * Java Class Version: 1.3 (47.0) * JD-Core Version: 0.7.1 */ package org.custommonkey.xmlunit; public abstract interface ComparisonController { public abstract boolean haltComparison(Difference paramDifference); } /* Location: * Qualified Name: org.custommonkey.xmlunit.ComparisonController * Java Class Version: 1.3 (47.0) * JD-Core Version: 0.7.1 */ package org.custommonkey.xmlunit; /** * @deprecated */ public class CountingNodeTester extends org.custommonkey.xmlunit.examples.CountingNodeTester { public CountingNodeTester(int expectedNumNodes) { super(expectedNumNodes); } } /* Location: * Qualified Name: org.custommonkey.xmlunit.CountingNodeTester * Java Class Version: 1.3 (47.0) * JD-Core Version: 0.7.1 */ package org.custommonkey.xmlunit; import java.util.ArrayList; import java.util.List; public class DetailedDiff extends Diff { private final List allDifferences; public DetailedDiff(Diff prototype) { super(prototype); allDifferences = new ArrayList(); } public int differenceFound(Difference difference) { int returnValue = super.differenceFound(difference); switch (returnValue) { case 1: return returnValue; case 0: break; case 2: difference.setRecoverable(true); break; case 3: difference.setRecoverable(false); break; default: throw new IllegalArgumentException(returnValue + " is not a defined " + " DifferenceListener" + ".RETURN_... value"); } allDifferences.add(difference); return returnValue; } public boolean haltComparison(Difference afterDifference) { return false; } public List getAllDifferences() { compare(); return allDifferences; } } /* Location: * Qualified Name: org.custommonkey.xmlunit.DetailedDiff * Java Class Version: 1.3 (47.0) * JD-Core Version: 0.7.1 */ package org.custommonkey.xmlunit; import java.io.IOException; import java.io.PrintStream; import java.io.Reader; import java.io.StringReader; import javax.xml.transform.TransformerException; import javax.xml.transform.dom.DOMSource; import org.custommonkey.xmlunit.exceptions.XMLUnitRuntimeException; import org.w3c.dom.Document; import org.w3c.dom.Node; import org.xml.sax.InputSource; import org.xml.sax.SAXException; public class Diff implements DifferenceListener, ComparisonController { private final Document controlDoc; private final Document testDoc; private boolean similar = true; private boolean identical = true; private boolean compared = false; private boolean haltComparison = false; private StringBuffer messages; private DifferenceEngine differenceEngine; private DifferenceListener differenceListenerDelegate; private ElementQualifier elementQualifierDelegate; private MatchTracker matchTrackerDelegate; public Diff(String control, String test) throws SAXException, IOException { this(new StringReader(control), new StringReader(test)); } public Diff(Reader control, Reader test) throws SAXException, IOException { this(XMLUnit.buildDocument(XMLUnit.newControlParser(), control), XMLUnit.buildDocument(XMLUnit.newTestParser(), test)); } public Diff(Document controlDoc, Document testDoc) { this(controlDoc, testDoc, (DifferenceEngine)null); } public Diff(String control, Transform testTransform) throws IOException, TransformerException, SAXException { this(XMLUnit.buildControlDocument(control), testTransform.getResultDocument()); } public Diff(InputSource control, InputSource test) throws SAXException, IOException { this(XMLUnit.buildDocument(XMLUnit.newControlParser(), control), XMLUnit.buildDocument(XMLUnit.newTestParser(), test)); } public Diff(DOMSource control, DOMSource test) { this(control.getNode().getOwnerDocument(), test.getNode().getOwnerDocument()); } public Diff(Document controlDoc, Document testDoc, DifferenceEngine comparator) { this(controlDoc, testDoc, comparator, new ElementNameQualifier()); } public Diff(Document controlDoc, Document testDoc, DifferenceEngine comparator, ElementQualifier elementQualifier) { this.controlDoc = getManipulatedDocument(controlDoc); this.testDoc = getManipulatedDocument(testDoc); elementQualifierDelegate = elementQualifier; differenceEngine = comparator; messages = new StringBuffer(); } protected Diff(Diff prototype) { this(controlDoc, testDoc, differenceEngine, elementQualifierDelegate); differenceListenerDelegate = differenceListenerDelegate; } private Document getWhitespaceManipulatedDocument(Document originalDoc) { return XMLUnit.getIgnoreWhitespace() ? XMLUnit.getWhitespaceStrippedDocument(originalDoc) : originalDoc; } private Document getManipulatedDocument(Document orig) { return getNormalizedDocument(getCommentlessDocument(getWhitespaceManipulatedDocument(orig))); } private Document getCommentlessDocument(Document orig) { if (!XMLUnit.getIgnoreComments()) { return orig; } try { Transform commentStripper = XMLUnit.getStripCommentsTransform(orig); return commentStripper.getResultDocument(); } catch (TransformerException e) { throw new XMLUnitRuntimeException(e.getMessage(), e.getCause()); } } private Document getNormalizedDocument(Document orig) { if (!XMLUnit.getNormalize()) { return orig; } Document d = (Document)orig.cloneNode(true); d.normalize(); return d; } protected final void compare() { if (compared) { return; } getDifferenceEngine().compare(controlDoc, testDoc, this, elementQualifierDelegate); compared = true; } public boolean similar() { compare(); return similar; } public boolean identical() { compare(); return identical; } private void appendDifference(StringBuffer appendTo, Difference difference) { appendTo.append(' ').append(difference).append('\n'); } public int differenceFound(Difference difference) { int returnValue = 0; if (differenceListenerDelegate != null) { returnValue = differenceListenerDelegate.differenceFound(difference); } switch (returnValue) { case 1: return returnValue; case 2: identical = false; haltComparison = false; break; case 0: identical = false; if (difference.isRecoverable()) { haltComparison = false; } else { similar = false; haltComparison = true; } break; case 3: identical = (similar = 0); haltComparison = true; break; default: throw new IllegalArgumentException(returnValue + " is not a defined DifferenceListener.RETURN_... value"); } if (haltComparison) { messages.append("\n[different]"); } else { messages.append("\n[not identical]"); } appendDifference(messages, difference); return returnValue; } public void skippedComparison(Node control, Node test) { if (differenceListenerDelegate != null) { differenceListenerDelegate.skippedComparison(control, test); } else { System.err.println("DifferenceListener.skippedComparison: unhandled control node type=" + control + ", unhandled test node type=" + test); } } public boolean haltComparison(Difference afterDifference) { return haltComparison; } public StringBuffer appendMessage(StringBuffer toAppendTo) { compare(); if (messages.length() == 0) { messages.append("[identical]"); } return toAppendTo.append(messages.toString()); } public String toString() { StringBuffer buf = new StringBuffer(getClass().getName()); appendMessage(buf); return buf.toString(); } public void overrideDifferenceListener(DifferenceListener delegate) { differenceListenerDelegate = delegate; } public void overrideElementQualifier(ElementQualifier delegate) { elementQualifierDelegate = delegate; } public void overrideMatchTracker(MatchTracker delegate) { matchTrackerDelegate = delegate; if (differenceEngine != null) { differenceEngine.setMatchTracker(delegate); } } private DifferenceEngine getDifferenceEngine() { return differenceEngine == null ? new DifferenceEngine(this, matchTrackerDelegate) : differenceEngine; } } /* Location: * Qualified Name: org.custommonkey.xmlunit.Diff * Java Class Version: 1.3 (47.0) * JD-Core Version: 0.7.1 */ package org.custommonkey.xmlunit; public class Difference { private final int id; private final String description; private boolean recoverable; private NodeDetail controlNodeDetail = null; private NodeDetail testNodeDetail = null; protected Difference(int id, String description) { this(id, description, false); } protected Difference(int id, String description, boolean recoverable) { this.id = id; this.description = description; this.recoverable = recoverable; } protected Difference(Difference prototype, NodeDetail controlNodeDetail, NodeDetail testNodeDetail) { this(prototype.getId(), prototype.getDescription(), prototype.isRecoverable()); } public int getId() { return id; } public String getDescription() { return description; } public boolean isRecoverable() { return recoverable; } protected void setRecoverable(boolean overrideValue) { recoverable = overrideValue; } public NodeDetail getControlNodeDetail() { return controlNodeDetail; } public NodeDetail getTestNodeDetail() { return testNodeDetail; } public boolean equals(Object other) { if (other == null) { return false; } if ((other instanceof Difference)) { Difference otherDifference = (Difference)other; return id == otherDifference.getId(); } return false; } public int hashCode() { return id; } public String toString() { StringBuffer buf = new StringBuffer(); if ((controlNodeDetail == null) || (testNodeDetail == null)) { appendBasicRepresentation(buf); } else { appendDetailedRepresentation(buf); } return buf.toString(); } private void appendBasicRepresentation(StringBuffer buf) { buf.append("Difference (#").append(id).append(") ").append(description); } private void appendDetailedRepresentation(StringBuffer buf) { buf.append("Expected ").append(getDescription()).append(" '").append(controlNodeDetail.getValue()).append("' but was '").append(testNodeDetail.getValue()).append("' - comparing "); NodeDescriptor.appendNodeDetail(buf, controlNodeDetail); buf.append(" to "); NodeDescriptor.appendNodeDetail(buf, testNodeDetail); } } /* Location: * Qualified Name: org.custommonkey.xmlunit.Difference * Java Class Version: 1.3 (47.0) * JD-Core Version: 0.7.1 */ package org.custommonkey.xmlunit; public abstract interface DifferenceConstants { public static final int ATTR_VALUE_EXPLICITLY_SPECIFIED_ID = 1; public static final int ATTR_NAME_NOT_FOUND_ID = 2; public static final int ATTR_VALUE_ID = 3; public static final int ATTR_SEQUENCE_ID = 4; public static final int CDATA_VALUE_ID = 5; public static final int COMMENT_VALUE_ID = 6; public static final int DOCTYPE_NAME_ID = 7; public static final int DOCTYPE_PUBLIC_ID_ID = 8; public static final int DOCTYPE_SYSTEM_ID_ID = 9; public static final int ELEMENT_TAG_NAME_ID = 10; public static final int ELEMENT_NUM_ATTRIBUTES_ID = 11; public static final int PROCESSING_INSTRUCTION_TARGET_ID = 12; public static final int PROCESSING_INSTRUCTION_DATA_ID = 13; public static final int TEXT_VALUE_ID = 14; public static final int NAMESPACE_PREFIX_ID = 15; public static final int NAMESPACE_URI_ID = 16; public static final int NODE_TYPE_ID = 17; public static final int HAS_CHILD_NODES_ID = 18; public static final int CHILD_NODELIST_LENGTH_ID = 19; public static final int CHILD_NODELIST_SEQUENCE_ID = 20; public static final int HAS_DOCTYPE_DECLARATION_ID = 21; public static final int CHILD_NODE_NOT_FOUND_ID = 22; public static final int SCHEMA_LOCATION_ID = 23; public static final int NO_NAMESPACE_SCHEMA_LOCATION_ID = 24; public static final Difference ATTR_VALUE_EXPLICITLY_SPECIFIED = new Difference(1, "attribute value explicitly specified", true); public static final Difference ATTR_NAME_NOT_FOUND = new Difference(2, "attribute name"); public static final Difference ATTR_VALUE = new Difference(3, "attribute value"); public static final Difference ATTR_SEQUENCE = new Difference(4, "sequence of attributes", true); public static final Difference CDATA_VALUE = new Difference(5, "CDATA section value"); public static final Difference COMMENT_VALUE = new Difference(6, "comment value"); public static final Difference DOCTYPE_NAME = new Difference(7, "doctype name"); public static final Difference DOCTYPE_PUBLIC_ID = new Difference(8, "doctype public identifier"); public static final Difference DOCTYPE_SYSTEM_ID = new Difference(9, "doctype system identifier", true); public static final Difference ELEMENT_TAG_NAME = new Difference(10, "element tag name"); public static final Difference ELEMENT_NUM_ATTRIBUTES = new Difference(11, "number of element attributes"); public static final Difference PROCESSING_INSTRUCTION_TARGET = new Difference(12, "processing instruction target"); public static final Difference PROCESSING_INSTRUCTION_DATA = new Difference(13, "processing instruction data"); public static final Difference TEXT_VALUE = new Difference(14, "text value"); public static final Difference NAMESPACE_PREFIX = new Difference(15, "namespace prefix", true); public static final Difference NAMESPACE_URI = new Difference(16, "namespace URI"); public static final Difference NODE_TYPE = new Difference(17, "node type"); public static final Difference HAS_CHILD_NODES = new Difference(18, "presence of child nodes to be"); public static final Difference CHILD_NODELIST_LENGTH = new Difference(19, "number of child nodes"); public static final Difference CHILD_NODELIST_SEQUENCE = new Difference(20, "sequence of child nodes", true); public static final Difference HAS_DOCTYPE_DECLARATION = new Difference(21, "presence of doctype declaration", true); public static final Difference CHILD_NODE_NOT_FOUND = new Difference(22, "presence of child node"); public static final Difference SCHEMA_LOCATION = new Difference(23, "xsi:schemaLocation attribute", true); public static final Difference NO_NAMESPACE_SCHEMA_LOCATION = new Difference(24, "xsi:noNamespaceSchemaLocation attribute", true); } /* Location: * Qualified Name: org.custommonkey.xmlunit.DifferenceConstants * Java Class Version: 1.3 (47.0) * JD-Core Version: 0.7.1 */ package org.custommonkey.xmlunit; class DifferenceEngine$1 {} /* Location: * Qualified Name: org.custommonkey.xmlunit.DifferenceEngine.1 * Java Class Version: 1.3 (47.0) * JD-Core Version: 0.7.1 */ package org.custommonkey.xmlunit; public final class DifferenceEngine$DifferenceFoundException extends Exception { DifferenceEngine$DifferenceFoundException(DifferenceEngine.1 x0) { this(); } private DifferenceEngine$DifferenceFoundException() { super("This exception is used to control flow"); } } /* Location: * Qualified Name: org.custommonkey.xmlunit.DifferenceEngine.DifferenceFoundException * Java Class Version: 1.3 (47.0) * JD-Core Version: 0.7.1 */ package org.custommonkey.xmlunit; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; import org.w3c.dom.Attr; import org.w3c.dom.CDATASection; import org.w3c.dom.CharacterData; import org.w3c.dom.Comment; import org.w3c.dom.Document; import org.w3c.dom.DocumentType; import org.w3c.dom.Element; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; import org.w3c.dom.NodeList; import org.w3c.dom.ProcessingInstruction; import org.w3c.dom.Text; public class DifferenceEngine implements DifferenceConstants { private static final String NULL_NODE = "null"; private static final String NOT_NULL_NODE = "not null"; private static final String ATTRIBUTE_ABSENT = "[attribute absent]"; private final ComparisonController controller; private MatchTracker matchTracker; private final XpathNodeTracker controlTracker; private final XpathNodeTracker testTracker; public DifferenceEngine(ComparisonController controller) { this(controller, null); } public DifferenceEngine(ComparisonController controller, MatchTracker matchTracker) { this.controller = controller; this.matchTracker = matchTracker; controlTracker = new XpathNodeTracker(); testTracker = new XpathNodeTracker(); } public void setMatchTracker(MatchTracker matchTracker) { this.matchTracker = matchTracker; } public void compare(Node control, Node test, DifferenceListener listener, ElementQualifier elementQualifier) { controlTracker.reset(); testTracker.reset(); try { compare(getNullOrNotNull(control), getNullOrNotNull(test), control, test, listener, NODE_TYPE); if (control != null) { compareNode(control, test, listener, elementQualifier); } } catch (DifferenceFoundException e) {} } private String getNullOrNotNull(Node aNode) { return aNode == null ? "null" : "not null"; } protected void compareNode(Node control, Node test, DifferenceListener listener, ElementQualifier elementQualifier) throws DifferenceEngine.DifferenceFoundException { boolean comparable = compareNodeBasics(control, test, listener); boolean isDocumentNode = false; if (comparable) { switch (control.getNodeType()) { case 1: compareElement((Element)control, (Element)test, listener); break; case 3: case 4: compareText((CharacterData)control, (CharacterData)test, listener); break; case 8: compareComment((Comment)control, (Comment)test, listener); break; case 10: compareDocumentType((DocumentType)control, (DocumentType)test, listener); break; case 7: compareProcessingInstruction((ProcessingInstruction)control, (ProcessingInstruction)test, listener); break; case 9: isDocumentNode = true; compareDocument((Document)control, (Document)test, listener, elementQualifier); break; case 2: case 5: case 6: default: listener.skippedComparison(control, test); } } compareHasChildNodes(control, test, listener); if (isDocumentNode) { Element controlElement = ((Document)control).getDocumentElement(); Element testElement = ((Document)test).getDocumentElement(); if ((controlElement != null) && (testElement != null)) { compareNode(controlElement, testElement, listener, elementQualifier); } } else { controlTracker.indent(); testTracker.indent(); compareNodeChildren(control, test, listener, elementQualifier); controlTracker.outdent(); testTracker.outdent(); } } protected void compareDocument(Document control, Document test, DifferenceListener listener, ElementQualifier elementQualifier) throws DifferenceEngine.DifferenceFoundException { DocumentType controlDoctype = control.getDoctype(); DocumentType testDoctype = test.getDoctype(); compare(getNullOrNotNull(controlDoctype), getNullOrNotNull(testDoctype), controlDoctype, testDoctype, listener, HAS_DOCTYPE_DECLARATION); if ((controlDoctype != null) && (testDoctype != null)) { compareNode(controlDoctype, testDoctype, listener, elementQualifier); } } protected boolean compareNodeBasics(Node control, Node test, DifferenceListener listener) throws DifferenceEngine.DifferenceFoundException { controlTracker.visited(control); testTracker.visited(test); Short controlType = new Short(control.getNodeType()); Short testType = new Short(test.getNodeType()); boolean textAndCDATA = comparingTextAndCDATA(control.getNodeType(), test.getNodeType()); if (!textAndCDATA) { compare(controlType, testType, control, test, listener, NODE_TYPE); } compare(control.getNamespaceURI(), test.getNamespaceURI(), control, test, listener, NAMESPACE_URI); compare(control.getPrefix(), test.getPrefix(), control, test, listener, NAMESPACE_PREFIX); return (textAndCDATA) || (controlType.equals(testType)); } private boolean comparingTextAndCDATA(short controlType, short testType) { return (XMLUnit.getIgnoreDiffBetweenTextAndCDATA()) && (((controlType == 3) && (testType == 4)) || ((testType == 3) && (controlType == 4))); } protected void compareHasChildNodes(Node control, Node test, DifferenceListener listener) throws DifferenceEngine.DifferenceFoundException { Boolean controlHasChildren = hasChildNodes(control); Boolean testHasChildren = hasChildNodes(test); compare(controlHasChildren, testHasChildren, control, test, listener, HAS_CHILD_NODES); } private Boolean hasChildNodes(Node n) { boolean flag = n.hasChildNodes(); if ((flag) && (XMLUnit.getIgnoreComments())) { List nl = nodeList2List(n.getChildNodes()); flag = !nl.isEmpty(); } return flag ? Boolean.TRUE : Boolean.FALSE; } static List nodeList2List(NodeList nl) { int len = nl.getLength(); ArrayList l = new ArrayList(len); for (int i = 0; i < len; i++) { Node n = nl.item(i); if ((!XMLUnit.getIgnoreComments()) || (!(n instanceof Comment))) { l.add(n); } } return l; } protected void compareNodeChildren(Node control, Node test, DifferenceListener listener, ElementQualifier elementQualifier) throws DifferenceEngine.DifferenceFoundException { if ((control.hasChildNodes()) && (test.hasChildNodes())) { List controlChildren = nodeList2List(control.getChildNodes()); List testChildren = nodeList2List(test.getChildNodes()); Integer controlLength = new Integer(controlChildren.size()); Integer testLength = new Integer(testChildren.size()); compare(controlLength, testLength, control, test, listener, CHILD_NODELIST_LENGTH); compareNodeList(controlChildren, testChildren, controlLength.intValue(), listener, elementQualifier); } } /** * @deprecated */ protected void compareNodeList(NodeList control, NodeList test, int numNodes, DifferenceListener listener, ElementQualifier elementQualifier) throws DifferenceEngine.DifferenceFoundException { compareNodeList(nodeList2List(control), nodeList2List(test), numNodes, listener, elementQualifier); } protected void compareNodeList(List controlChildren, List testChildren, int numNodes, DifferenceListener listener, ElementQualifier elementQualifier) throws DifferenceEngine.DifferenceFoundException { int j = 0; int lastTestNode = testChildren.size() - 1; testTracker.preloadChildList(testChildren); HashMap matchingNodes = new HashMap(); HashMap matchingNodeIndexes = new HashMap(); List unmatchedTestNodes = new ArrayList(testChildren); for (int i = 0; i < numNodes; i++) { Node nextControl = (Node)controlChildren.get(i); boolean matchOnElement = nextControl instanceof Element; short findNodeType = nextControl.getNodeType(); int startAt = i > lastTestNode ? lastTestNode : i; j = startAt; boolean matchFound = false; while (!matchFound) { Node t = (Node)testChildren.get(j); if ((findNodeType == t.getNodeType()) || (comparingTextAndCDATA(findNodeType, t.getNodeType()))) { matchFound = (!matchOnElement) || (elementQualifier == null) || (elementQualifier.qualifyForComparison((Element)nextControl, (Element)t)); } if (!matchFound) { j++; if (j > lastTestNode) { j = 0; } if (j == startAt) { break; } } } if (matchFound) { matchingNodes.put(nextControl, testChildren.get(j)); matchingNodeIndexes.put(nextControl, new Integer(j)); unmatchedTestNodes.remove(testChildren.get(j)); } } for (int i = 0; i < numNodes; i++) { Node nextControl = (Node)controlChildren.get(i); Node nextTest = (Node)matchingNodes.get(nextControl); Integer testIndex = (Integer)matchingNodeIndexes.get(nextControl); if ((nextTest == null) && (!unmatchedTestNodes.isEmpty())) { nextTest = (Node)unmatchedTestNodes.get(0); testIndex = new Integer(testChildren.indexOf(nextTest)); unmatchedTestNodes.remove(0); } if (nextTest != null) { compareNode(nextControl, nextTest, listener, elementQualifier); compare(new Integer(i), testIndex, nextControl, nextTest, listener, CHILD_NODELIST_SEQUENCE); } else { missingNode(nextControl, null, listener); } } for (Iterator iter = unmatchedTestNodes.iterator(); iter.hasNext();) { missingNode(null, (Node)iter.next(), listener); } } private void missingNode(Node control, Node test, DifferenceListener listener) throws DifferenceEngine.DifferenceFoundException { if (control != null) { controlTracker.visited(control); compare(control.getNodeName(), null, control, null, listener, CHILD_NODE_NOT_FOUND, controlTracker, null); } else { testTracker.visited(test); compare(null, test.getNodeName(), null, test, listener, CHILD_NODE_NOT_FOUND, null, testTracker); } } private boolean isNamespaced(Node aNode) { String namespace = aNode.getNamespaceURI(); return (namespace != null) && (namespace.length() > 0); } protected void compareElement(Element control, Element test, DifferenceListener listener) throws DifferenceEngine.DifferenceFoundException { compare(getUnNamespacedNodeName(control), getUnNamespacedNodeName(test), control, test, listener, ELEMENT_TAG_NAME); NamedNodeMap controlAttr = control.getAttributes(); Integer controlNonXmlnsAttrLength = getNonSpecialAttrLength(controlAttr); NamedNodeMap testAttr = test.getAttributes(); Integer testNonXmlnsAttrLength = getNonSpecialAttrLength(testAttr); compare(controlNonXmlnsAttrLength, testNonXmlnsAttrLength, control, test, listener, ELEMENT_NUM_ATTRIBUTES); compareElementAttributes(control, test, controlAttr, testAttr, listener); } private Integer getNonSpecialAttrLength(NamedNodeMap attributes) { int length = 0;int maxLength = attributes.getLength(); for (int i = 0; i < maxLength; i++) { Attr a = (Attr)attributes.item(i); if ((!isXMLNSAttribute(a)) && (!isRecognizedXMLSchemaInstanceAttribute(a))) { length++; } } return new Integer(length); } void compareElementAttributes(Element control, Element test, NamedNodeMap controlAttr, NamedNodeMap testAttr, DifferenceListener listener) throws DifferenceEngine.DifferenceFoundException { ArrayList unmatchedTestAttrs = new ArrayList(); for (int i = 0; i < testAttr.getLength(); i++) { Attr nextAttr = (Attr)testAttr.item(i); if (!isXMLNSAttribute(nextAttr)) { unmatchedTestAttrs.add(nextAttr); } } for (int i = 0; i < controlAttr.getLength(); i++) { Attr nextAttr = (Attr)controlAttr.item(i); if (!isXMLNSAttribute(nextAttr)) { boolean isNamespacedAttr = isNamespaced(nextAttr); String attrName = getUnNamespacedNodeName(nextAttr, isNamespacedAttr); Attr compareTo = null; if (isNamespacedAttr) { compareTo = (Attr)testAttr.getNamedItemNS(nextAttr.getNamespaceURI(), attrName); } else { compareTo = (Attr)testAttr.getNamedItem(attrName); } if (compareTo != null) { unmatchedTestAttrs.remove(compareTo); } if (isRecognizedXMLSchemaInstanceAttribute(nextAttr)) { compareRecognizedXMLSchemaInstanceAttribute(nextAttr, compareTo, listener); } else if (compareTo != null) { compareAttribute(nextAttr, compareTo, listener); if (!XMLUnit.getIgnoreAttributeOrder()) { Attr attributeItem = (Attr)testAttr.item(i); String testAttrName = "[attribute absent]"; if (attributeItem != null) { testAttrName = getUnNamespacedNodeName(attributeItem); } compare(attrName, testAttrName, nextAttr, compareTo, listener, ATTR_SEQUENCE); } } else { compare(attrName, null, control, test, listener, ATTR_NAME_NOT_FOUND); } } } for (Iterator iter = unmatchedTestAttrs.iterator(); iter.hasNext();) { Attr nextAttr = (Attr)iter.next(); if (isRecognizedXMLSchemaInstanceAttribute(nextAttr)) { compareRecognizedXMLSchemaInstanceAttribute(null, nextAttr, listener); } else { compare(null, getUnNamespacedNodeName(nextAttr, isNamespaced(nextAttr)), control, test, listener, ATTR_NAME_NOT_FOUND); } } controlTracker.clearTrackedAttribute(); testTracker.clearTrackedAttribute(); } private String getUnNamespacedNodeName(Node aNode) { return getUnNamespacedNodeName(aNode, isNamespaced(aNode)); } private String getUnNamespacedNodeName(Node aNode, boolean isNamespacedNode) { if (isNamespacedNode) { return aNode.getLocalName(); } return aNode.getNodeName(); } private boolean isXMLNSAttribute(Attr attribute) { return ("xmlns".equals(attribute.getPrefix())) || ("xmlns".equals(attribute.getName())); } private boolean isRecognizedXMLSchemaInstanceAttribute(Attr attr) { return ("http://www.w3.org/2001/XMLSchema-instance".equals(attr.getNamespaceURI())) && (("schemaLocation".equals(attr.getLocalName())) || ("noNamespaceSchemaLocation".equals(attr.getLocalName()))); } protected void compareRecognizedXMLSchemaInstanceAttribute(Attr control, Attr test, DifferenceListener listener) throws DifferenceEngine.DifferenceFoundException { Attr nonNullNode = control != null ? control : test; Difference d = "schemaLocation".equals(nonNullNode.getLocalName()) ? SCHEMA_LOCATION : NO_NAMESPACE_SCHEMA_LOCATION; if (control != null) { controlTracker.visited(control); } if (test != null) { testTracker.visited(test); } compare(control != null ? control.getValue() : "[attribute absent]", test != null ? test.getValue() : "[attribute absent]", control, test, listener, d); } protected void compareAttribute(Attr control, Attr test, DifferenceListener listener) throws DifferenceEngine.DifferenceFoundException { controlTracker.visited(control); testTracker.visited(test); compare(control.getPrefix(), test.getPrefix(), control, test, listener, NAMESPACE_PREFIX); compare(control.getValue(), test.getValue(), control, test, listener, ATTR_VALUE); compare(control.getSpecified() ? Boolean.TRUE : Boolean.FALSE, test.getSpecified() ? Boolean.TRUE : Boolean.FALSE, control, test, listener, ATTR_VALUE_EXPLICITLY_SPECIFIED); } protected void compareCDataSection(CDATASection control, CDATASection test, DifferenceListener listener) throws DifferenceEngine.DifferenceFoundException { compareText(control, test, listener); } protected void compareComment(Comment control, Comment test, DifferenceListener listener) throws DifferenceEngine.DifferenceFoundException { if (!XMLUnit.getIgnoreComments()) { compareCharacterData(control, test, listener, COMMENT_VALUE); } } protected void compareDocumentType(DocumentType control, DocumentType test, DifferenceListener listener) throws DifferenceEngine.DifferenceFoundException { compare(control.getName(), test.getName(), control, test, listener, DOCTYPE_NAME); compare(control.getPublicId(), test.getPublicId(), control, test, listener, DOCTYPE_PUBLIC_ID); compare(control.getSystemId(), test.getSystemId(), control, test, listener, DOCTYPE_SYSTEM_ID); } protected void compareProcessingInstruction(ProcessingInstruction control, ProcessingInstruction test, DifferenceListener listener) throws DifferenceEngine.DifferenceFoundException { compare(control.getTarget(), test.getTarget(), control, test, listener, PROCESSING_INSTRUCTION_TARGET); compare(control.getData(), test.getData(), control, test, listener, PROCESSING_INSTRUCTION_DATA); } protected void compareText(Text control, Text test, DifferenceListener listener) throws DifferenceEngine.DifferenceFoundException { compareText(control, test, listener); } protected void compareText(CharacterData control, CharacterData test, DifferenceListener listener) throws DifferenceEngine.DifferenceFoundException { compareCharacterData(control, test, listener, (control instanceof CDATASection) ? CDATA_VALUE : TEXT_VALUE); } private void compareCharacterData(CharacterData control, CharacterData test, DifferenceListener listener, Difference difference) throws DifferenceEngine.DifferenceFoundException { compare(control.getData(), test.getData(), control, test, listener, difference); } protected void compare(Object expected, Object actual, Node control, Node test, DifferenceListener listener, Difference difference) throws DifferenceEngine.DifferenceFoundException { compare(expected, actual, control, test, listener, difference, controlTracker, testTracker); } protected void compare(Object expected, Object actual, Node control, Node test, DifferenceListener listener, Difference difference, XpathNodeTracker controlLoc, XpathNodeTracker testLoc) throws DifferenceEngine.DifferenceFoundException { NodeDetail controlDetail = new NodeDetail(String.valueOf(expected), control, controlLoc == null ? null : controlLoc.toXpathString()); NodeDetail testDetail = new NodeDetail(String.valueOf(actual), test, testLoc == null ? null : testLoc.toXpathString()); Difference differenceInstance = new Difference(difference, controlDetail, testDetail); if (unequal(expected, actual)) { listener.differenceFound(differenceInstance); if (controller.haltComparison(differenceInstance)) { throw flowControlException; } } else if (matchTracker != null) { matchTracker.matchFound(differenceInstance); } } private boolean unequal(Object expected, Object actual) { return expected == null ? false : actual != null ? true : unequalNotNull(expected, actual); } private boolean unequalNotNull(Object expected, Object actual) { if (((XMLUnit.getIgnoreWhitespace()) || (XMLUnit.getNormalizeWhitespace())) && ((expected instanceof String)) && ((actual instanceof String))) { String expectedString = ((String)expected).trim(); String actualString = ((String)actual).trim(); if (XMLUnit.getNormalizeWhitespace()) { expectedString = normalizeWhitespace(expectedString); actualString = normalizeWhitespace(actualString); } return !expectedString.equals(actualString); } return !expected.equals(actual); } static final String normalizeWhitespace(String orig) { StringBuffer sb = new StringBuffer(); boolean lastCharWasWhitespace = false; boolean changed = false; char[] characters = orig.toCharArray(); for (int i = 0; i < characters.length; i++) { if (Character.isWhitespace(characters[i])) { if (lastCharWasWhitespace) { changed = true; } else { sb.append(' '); changed |= characters[i] != ' '; lastCharWasWhitespace = true; } } else { sb.append(characters[i]); lastCharWasWhitespace = false; } } return changed ? sb.toString() : orig; } protected static final class DifferenceFoundException extends Exception { DifferenceFoundException(DifferenceEngine.1 x0) { this(); } private DifferenceFoundException() { super(); } } private static final DifferenceFoundException flowControlException = new DifferenceFoundException(null); } /* Location: * Qualified Name: org.custommonkey.xmlunit.DifferenceEngine * Java Class Version: 1.3 (47.0) * JD-Core Version: 0.7.1 */ package org.custom Further reading...For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.New!JAR listings
|