From: <bo...@us...> - 2007-03-27 04:31:57
|
Revision: 157 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=157&view=rev Author: bodewig Date: 2007-03-26 21:31:56 -0700 (Mon, 26 Mar 2007) Log Message: ----------- Add InputSource as possible input Modified Paths: -------------- trunk/xmlunit/src/java/org/custommonkey/xmlunit/NodeTest.java trunk/xmlunit/src/java/org/custommonkey/xmlunit/Transform.java trunk/xmlunit/src/java/org/custommonkey/xmlunit/Validator.java Modified: trunk/xmlunit/src/java/org/custommonkey/xmlunit/NodeTest.java =================================================================== --- trunk/xmlunit/src/java/org/custommonkey/xmlunit/NodeTest.java 2007-03-27 04:05:20 UTC (rev 156) +++ trunk/xmlunit/src/java/org/custommonkey/xmlunit/NodeTest.java 2007-03-27 04:31:56 UTC (rev 157) @@ -45,6 +45,7 @@ import org.w3c.dom.traversal.DocumentTraversal; import org.w3c.dom.traversal.NodeFilter; import org.w3c.dom.traversal.NodeIterator; +import org.xml.sax.InputSource; import org.xml.sax.SAXException; /** @@ -76,6 +77,14 @@ } /** + * Construct a NodeTest for the DOM built using the InputSource. + */ + public NodeTest(InputSource src) throws SAXException, + IOException { + this(XMLUnit.buildDocument(XMLUnit.newControlParser(), src)); + } + + /** * Construct a NodeTest for the specified Document * @exception IllegalArgumentException if the Document does not support the DOM * DocumentTraversal interface (most DOM implementations should provide this Modified: trunk/xmlunit/src/java/org/custommonkey/xmlunit/Transform.java =================================================================== --- trunk/xmlunit/src/java/org/custommonkey/xmlunit/Transform.java 2007-03-27 04:05:20 UTC (rev 156) +++ trunk/xmlunit/src/java/org/custommonkey/xmlunit/Transform.java 2007-03-27 04:31:56 UTC (rev 157) @@ -53,8 +53,10 @@ import javax.xml.transform.URIResolver; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.dom.DOMResult; +import javax.xml.transform.sax.SAXSource; import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamSource; +import org.xml.sax.InputSource; import org.w3c.dom.Document; import org.w3c.dom.Node; @@ -91,6 +93,26 @@ } /** + * Create a transformation using InputSource input XML and + * InputSource stylesheet + * @param input + * @param stylesheet + */ + public Transform(InputSource input, InputSource stylesheet) { + this(new SAXSource(input), new SAXSource(stylesheet)); + } + + /** + * Create a transformation using InputSource input XML and + * stylesheet in a File + * @param input + * @param stylesheet + */ + public Transform(InputSource input, File stylesheet) { + this(new SAXSource(input), new StreamSource(stylesheet)); + } + + /** * Create a transformation that allows us to serialize a DOM Node * @param source */ Modified: trunk/xmlunit/src/java/org/custommonkey/xmlunit/Validator.java =================================================================== --- trunk/xmlunit/src/java/org/custommonkey/xmlunit/Validator.java 2007-03-27 04:05:20 UTC (rev 156) +++ trunk/xmlunit/src/java/org/custommonkey/xmlunit/Validator.java 2007-03-27 04:31:56 UTC (rev 157) @@ -41,6 +41,7 @@ import java.io.IOException; import java.io.InputStreamReader; import java.io.Reader; +import java.io.StringReader; import org.w3c.dom.Document; import org.xml.sax.ErrorHandler; @@ -83,14 +84,27 @@ private Boolean isValid; /** + * Kept for backwards compatibility. + * @deprecated Use the protected three arg constructor instead. + */ + protected Validator(InputSource inputSource, + boolean usingDoctypeReader) + throws SAXException, ConfigurationException { + this(inputSource, null, usingDoctypeReader); + } + + /** * Baseline constructor: called by all others * * @param inputSource + * @param systemId * @param usingDoctypeReader * @throws SAXException * @throws ConfigurationException if validation could not be turned on */ - protected Validator(InputSource inputSource, boolean usingDoctypeReader) + protected Validator(InputSource inputSource, + String systemId, + boolean usingDoctypeReader) throws SAXException, ConfigurationException { isValid = null; messages = new StringBuffer(); @@ -103,6 +117,9 @@ } this.validationInputSource = inputSource; + if (systemId != null) { + validationInputSource.setSystemId(systemId); + } this.usingDoctypeReader = usingDoctypeReader; } @@ -137,11 +154,38 @@ */ public Validator(Reader readerForValidation) throws SAXException, ConfigurationException { - this(new InputSource(readerForValidation), - (readerForValidation instanceof DoctypeReader)); + this(readerForValidation, null); } /** + * Basic constructor. + * Validates the contents of the String using the DTD or schema referenced + * by those contents. + * + * @param stringForValidation + * @throws SAXException if unable to obtain new Sax parser via JAXP factory + * @throws ConfigurationException if validation could not be turned on + */ + public Validator(String stringForValidation) + throws SAXException, ConfigurationException { + this(new StringReader(stringForValidation)); + } + + /** + * Basic constructor. + * Validates the contents of the InputSource using the DTD or + * schema referenced by those contents. + * + * @param readerForValidation + * @throws SAXException if unable to obtain new Sax parser via JAXP factory + * @throws ConfigurationException if validation could not be turned on + */ + public Validator(InputSource sourceForValidation) + throws SAXException, ConfigurationException { + this(sourceForValidation, null); + } + + /** * Extended constructor. * Validates the contents of the Reader using the DTD specified with the * systemID. There must be DOCTYPE instruction in the markup that @@ -155,11 +199,46 @@ */ public Validator(Reader readerForValidation, String systemID) throws SAXException, ConfigurationException { - this(readerForValidation); - validationInputSource.setSystemId(systemID); + this(new InputSource(readerForValidation), systemID, + (readerForValidation instanceof DoctypeReader)); } /** + * Extended constructor. + * Validates the contents of the String using the DTD specified with the + * systemID. There must be DOCTYPE instruction in the markup that + * references the DTD or else the markup will be considered invalid: if + * there is no DOCTYPE in the markup use the 3-argument constructor + * + * @param stringForValidation + * @param systemID + * @throws SAXException if unable to obtain new Sax parser via JAXP factory + * @throws ConfigurationException if validation could not be turned on + */ + public Validator(String stringForValidation, String systemID) + throws SAXException, ConfigurationException { + this(new StringReader(stringForValidation), systemID); + } + + /** + * Extended constructor. + * Validates the contents of the InputSource using the DTD + * specified with the systemID. There must be DOCTYPE instruction + * in the markup that references the DTD or else the markup will + * be considered invalid: if there is no DOCTYPE in the markup use + * the 3-argument constructor + * + * @param sourceForValidation + * @param systemID + * @throws SAXException if unable to obtain new Sax parser via JAXP factory + * @throws ConfigurationException if validation could not be turned on + */ + public Validator(InputSource sourceForValidation, String systemID) + throws SAXException, ConfigurationException { + this(sourceForValidation, systemID, false); + } + + /** * Full constructor. * Validates the contents of the Reader using the DTD specified with the * systemID and named with the doctype name. @@ -172,8 +251,8 @@ */ public Validator(Reader readerForValidation, String systemID, String doctype) throws SAXException, ConfigurationException { - this(new DoctypeReader(readerForValidation, doctype, systemID)); - validationInputSource.setSystemId(systemID); + this(new DoctypeReader(readerForValidation, doctype, systemID), + systemID); } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bo...@us...> - 2007-03-28 04:06:23
|
Revision: 158 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=158&view=rev Author: bodewig Date: 2007-03-27 21:06:22 -0700 (Tue, 27 Mar 2007) Log Message: ----------- Allow custom URI resolvers Modified Paths: -------------- trunk/xmlunit/src/java/org/custommonkey/xmlunit/Transform.java trunk/xmlunit/src/java/org/custommonkey/xmlunit/XMLUnit.java Modified: trunk/xmlunit/src/java/org/custommonkey/xmlunit/Transform.java =================================================================== --- trunk/xmlunit/src/java/org/custommonkey/xmlunit/Transform.java 2007-03-27 04:31:56 UTC (rev 157) +++ trunk/xmlunit/src/java/org/custommonkey/xmlunit/Transform.java 2007-03-28 04:06:22 UTC (rev 158) @@ -191,10 +191,13 @@ throws ConfigurationException { try { TransformerFactory factory = XMLUnit.getTransformerFactory(); - if (stylesheetSource == null) { - return factory.newTransformer(); + Transformer t = stylesheetSource == null + ? factory.newTransformer() + : factory.newTransformer(stylesheetSource); + if (XMLUnit.getURIResolver() != null) { + t.setURIResolver(XMLUnit.getURIResolver()); } - return factory.newTransformer(stylesheetSource); + return t; } catch (javax.xml.transform.TransformerConfigurationException ex) { throw new ConfigurationException(ex); } Modified: trunk/xmlunit/src/java/org/custommonkey/xmlunit/XMLUnit.java =================================================================== --- trunk/xmlunit/src/java/org/custommonkey/xmlunit/XMLUnit.java 2007-03-27 04:31:56 UTC (rev 157) +++ trunk/xmlunit/src/java/org/custommonkey/xmlunit/XMLUnit.java 2007-03-28 04:06:22 UTC (rev 158) @@ -43,6 +43,7 @@ import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParserFactory; import javax.xml.transform.TransformerFactory; +import javax.xml.transform.URIResolver; import java.io.IOException; import java.io.Reader; @@ -62,6 +63,7 @@ private static DocumentBuilderFactory testBuilderFactory; private static TransformerFactory transformerFactory; private static boolean ignoreWhitespace = false; + private static URIResolver uriResolver = null; private static EntityResolver testEntityResolver = null; private static EntityResolver controlEntityResolver = null; private static NamespaceContext namespaceContext = null; @@ -443,8 +445,21 @@ return transformerFactory; } + /** + * Sets the URIResolver to use during transformations. + */ + public static void setURIResolver(URIResolver resolver) { + uriResolver = resolver; + } /** + * Gets the URIResolver used during Transformations. + */ + public static URIResolver getURIResolver() { + return uriResolver; + } + + /** * Override the SAX parser to use in tests. * Currently only used by {@link Validator Validator class} * @param className This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bo...@us...> - 2007-03-30 04:00:41
|
Revision: 165 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=165&view=rev Author: bodewig Date: 2007-03-29 21:00:40 -0700 (Thu, 29 Mar 2007) Log Message: ----------- Use configured EntityResolver in Validator if present Modified Paths: -------------- trunk/xmlunit/src/java/org/custommonkey/xmlunit/Validator.java trunk/xmlunit/src/java/org/custommonkey/xmlunit/XMLUnit.java Modified: trunk/xmlunit/src/java/org/custommonkey/xmlunit/Validator.java =================================================================== --- trunk/xmlunit/src/java/org/custommonkey/xmlunit/Validator.java 2007-03-30 03:50:01 UTC (rev 164) +++ trunk/xmlunit/src/java/org/custommonkey/xmlunit/Validator.java 2007-03-30 04:00:40 UTC (rev 165) @@ -37,6 +37,7 @@ package org.custommonkey.xmlunit; import org.custommonkey.xmlunit.exceptions.ConfigurationException; +import org.custommonkey.xmlunit.exceptions.XMLUnitRuntimeException; import java.io.IOException; import java.io.InputStreamReader; @@ -444,8 +445,28 @@ public InputSource resolveEntity(String publicId, String systemId) { if (validationInputSource.getSystemId() != null) { return new InputSource(validationInputSource.getSystemId()); - } else if (systemId != null) { - return new InputSource(systemId); + } else { + InputSource s = null; + try { + if (XMLUnit.getControlEntityResolver() != null) { + s = XMLUnit.getControlEntityResolver() + .resolveEntity(publicId, systemId); + } + } catch (SAXException e) { + throw new XMLUnitRuntimeException("failed to resolve entity: " + + publicId, e); + } catch (IOException e) { + // even if we wanted to re-throw IOException (which we + // can't because of backwards compatibility) the mere + // fact that DefaultHandler has stripped IOException + // from EntityResolver's method's signature wouldn't + // let us. + throw new XMLUnitRuntimeException("failed to resolve entity: " + + publicId, e); + } + if (s == null && systemId != null) { + return new InputSource(systemId); + } } return null; } Modified: trunk/xmlunit/src/java/org/custommonkey/xmlunit/XMLUnit.java =================================================================== --- trunk/xmlunit/src/java/org/custommonkey/xmlunit/XMLUnit.java 2007-03-30 03:50:01 UTC (rev 164) +++ trunk/xmlunit/src/java/org/custommonkey/xmlunit/XMLUnit.java 2007-03-30 04:00:40 UTC (rev 165) @@ -146,6 +146,13 @@ } /** + * Obtains the EntityResolver to be added to all new control parsers. + */ + public static EntityResolver getControlEntityResolver() { + return controlEntityResolver; + } + + /** * Get the <code>DocumentBuilderFactory</code> instance used to instantiate * parsers for the control XML in an XMLTestCase. * @return factory for control parsers This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bo...@us...> - 2007-04-13 08:11:04
|
Revision: 179 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=179&view=rev Author: bodewig Date: 2007-04-13 01:11:02 -0700 (Fri, 13 Apr 2007) Log Message: ----------- fix a few javadocs, remove redundant public identifiers from interfaces Modified Paths: -------------- trunk/xmlunit/src/java/org/custommonkey/xmlunit/ComparisonController.java trunk/xmlunit/src/java/org/custommonkey/xmlunit/DifferenceListener.java trunk/xmlunit/src/java/org/custommonkey/xmlunit/NodeTester.java trunk/xmlunit/src/java/org/custommonkey/xmlunit/examples/MultiLevelElementNameAndTextQualifier.java Modified: trunk/xmlunit/src/java/org/custommonkey/xmlunit/ComparisonController.java =================================================================== --- trunk/xmlunit/src/java/org/custommonkey/xmlunit/ComparisonController.java 2007-04-12 09:07:12 UTC (rev 178) +++ trunk/xmlunit/src/java/org/custommonkey/xmlunit/ComparisonController.java 2007-04-13 08:11:02 UTC (rev 179) @@ -41,13 +41,13 @@ */ public interface ComparisonController { /** - * Determine whether a Difference that this listener has been notified of + * Determine whether a Difference that the listener has been notified of * should halt further XML comparison. Default behaviour for a Diff * instance is to halt if the Difference is not recoverable. * @see Difference#isRecoverable * @param afterDifference the last Difference passed to <code>differenceFound</code> * @return true to halt further comparison, false otherwise */ - public boolean haltComparison(Difference afterDifference); + boolean haltComparison(Difference afterDifference); } Modified: trunk/xmlunit/src/java/org/custommonkey/xmlunit/DifferenceListener.java =================================================================== --- trunk/xmlunit/src/java/org/custommonkey/xmlunit/DifferenceListener.java 2007-04-12 09:07:12 UTC (rev 178) +++ trunk/xmlunit/src/java/org/custommonkey/xmlunit/DifferenceListener.java 2007-04-13 08:11:02 UTC (rev 179) @@ -49,28 +49,29 @@ * Indicates that the <code>Difference</code> is interpreted as defined * in {@link DifferenceConstants DifferenceConstants}. */ - public final int RETURN_ACCEPT_DIFFERENCE = 0; + int RETURN_ACCEPT_DIFFERENCE = 0; /** * Override return value for the <code>differenceFound</code> method. * Indicates that the nodes identified as being different should be * interpreted as being identical. */ - public final int RETURN_IGNORE_DIFFERENCE_NODES_IDENTICAL = 1; + int RETURN_IGNORE_DIFFERENCE_NODES_IDENTICAL = 1; /** * Override return value for the <code>differenceFound</code> method. * Indicates that the nodes identified as being different should be * interpreted as being similar. */ - public final int RETURN_IGNORE_DIFFERENCE_NODES_SIMILAR = 2; + int RETURN_IGNORE_DIFFERENCE_NODES_SIMILAR = 2; /** * Receive notification that 2 nodes are different. - * @param difference a Difference instance as defined in - * {@link DifferenceConstants DifferenceConstants} describing the - * cause of the difference and containing the detail of the nodes that differ - * @return int one of the RETURN_... constants describing how this difference - * was interpreted + * @param difference a Difference instance as defined in {@link + * DifferenceConstants DifferenceConstants} describing the cause + * of the difference and containing the detail of the nodes that + * differ + * @return int one of the RETURN_... constants describing how this + * difference was interpreted */ - public int differenceFound(Difference difference); + int differenceFound(Difference difference); /** * Receive notification that a comparison between 2 nodes has been skipped @@ -79,6 +80,6 @@ * @param test the test node being compared * @see DifferenceEngine */ - public void skippedComparison(Node control, Node test); + void skippedComparison(Node control, Node test); } \ No newline at end of file Modified: trunk/xmlunit/src/java/org/custommonkey/xmlunit/NodeTester.java =================================================================== --- trunk/xmlunit/src/java/org/custommonkey/xmlunit/NodeTester.java 2007-04-12 09:07:12 UTC (rev 178) +++ trunk/xmlunit/src/java/org/custommonkey/xmlunit/NodeTester.java 2007-04-13 08:11:02 UTC (rev 179) @@ -53,7 +53,7 @@ * @param forTest * @exception NodeTestException if the node fails the test */ - public void testNode(Node aNode, NodeTest forTest) throws NodeTestException ; + void testNode(Node aNode, NodeTest forTest) throws NodeTestException ; /** * Validate that the Nodes passed one-by-one to the <code>testNode</code> @@ -61,5 +61,5 @@ * @param forTest * @exception NodeTestException if this instance was expecting more nodes */ - public void noMoreNodes(NodeTest forTest) throws NodeTestException ; + void noMoreNodes(NodeTest forTest) throws NodeTestException ; } \ No newline at end of file Modified: trunk/xmlunit/src/java/org/custommonkey/xmlunit/examples/MultiLevelElementNameAndTextQualifier.java =================================================================== --- trunk/xmlunit/src/java/org/custommonkey/xmlunit/examples/MultiLevelElementNameAndTextQualifier.java 2007-04-12 09:07:12 UTC (rev 178) +++ trunk/xmlunit/src/java/org/custommonkey/xmlunit/examples/MultiLevelElementNameAndTextQualifier.java 2007-04-13 08:11:02 UTC (rev 179) @@ -1,6 +1,6 @@ /* ****************************************************************** -Copyright (c) 2001, Jeff Martin, Tim Bacon +Copyright (c) 2006-2007, Jeff Martin, Tim Bacon All rights reserved. Redistribution and use in source and binary forms, with or without This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bo...@us...> - 2007-04-17 03:59:28
|
Revision: 188 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=188&view=rev Author: bodewig Date: 2007-04-16 20:59:29 -0700 (Mon, 16 Apr 2007) Log Message: ----------- remove deprecated methods Modified Paths: -------------- trunk/xmlunit/src/java/org/custommonkey/xmlunit/XMLAssert.java trunk/xmlunit/src/java/org/custommonkey/xmlunit/XMLTestCase.java trunk/xmlunit/src/java/org/custommonkey/xmlunit/XMLUnit.java Modified: trunk/xmlunit/src/java/org/custommonkey/xmlunit/XMLAssert.java =================================================================== --- trunk/xmlunit/src/java/org/custommonkey/xmlunit/XMLAssert.java 2007-04-16 13:06:55 UTC (rev 187) +++ trunk/xmlunit/src/java/org/custommonkey/xmlunit/XMLAssert.java 2007-04-17 03:59:29 UTC (rev 188) @@ -145,17 +145,6 @@ /** * Assert that the result of an XML comparison is or is not identical - * @param diff the result of an XML comparison - * @param assertion true if asserting that result is identical - * @param msg additional message to display if assertion fails - * @deprecated Use XMLTestCase#assertXMLIdentical(String, Diff, boolean) instead - */ - public static void assertXMLIdentical(Diff diff, boolean assertion, String msg) { - assertXMLIdentical(msg, diff, assertion); - } - - /** - * Assert that the result of an XML comparison is or is not identical * @param msg Message to display if assertion fails * @param diff the result of an XML comparison * @param assertion true if asserting that result is identical Modified: trunk/xmlunit/src/java/org/custommonkey/xmlunit/XMLTestCase.java =================================================================== --- trunk/xmlunit/src/java/org/custommonkey/xmlunit/XMLTestCase.java 2007-04-16 13:06:55 UTC (rev 187) +++ trunk/xmlunit/src/java/org/custommonkey/xmlunit/XMLTestCase.java 2007-04-17 03:59:29 UTC (rev 188) @@ -78,34 +78,6 @@ } /** - * Whether to ignore whitespace in attributes and elements - * @param ignore - * @deprecated this is a global setting and should be invoked on - * {@link XMLUnit#setIgnoreWhitespace XMLUnit} instead - */ - public void setIgnoreWhitespace(boolean ignore){ - XMLUnit.setIgnoreWhitespace(ignore); - } - - /** - * Overide default sax parser used to parser documents - * @deprecated this is a global setting and should be invoked on - * {@link XMLUnit#setControlParser XMLUnit} instead - */ - public void setControlParser(String parser){ - XMLUnit.setControlParser(parser); - } - - /** - * Overide default sax parser used to parse documents - * @deprecated this is a global setting and should be invoked on - * {@link XMLUnit#setTestParser XMLUnit} instead - */ - public void setTestParser(String parser){ - XMLUnit.setTestParser(parser); - } - - /** * Compare XML documents provided by two InputSource classes * @param control Control document * @param test Document to test @@ -191,18 +163,7 @@ /** * Assert that the result of an XML comparison is or is not similar. - * @param diff the result of an XML comparison - * @param assertion true if asserting that result is similar * @param msg additional message to display if assertion fails - * @deprecated Use XMLTestCase#assertXMLEqual(String, Diff, boolean) instead - */ - public void assertXMLEqual(Diff diff, boolean assertion, String msg) { - XMLAssert.assertXMLEqual(msg, diff, assertion); - } - - /** - * Assert that the result of an XML comparison is or is not similar. - * @param msg additional message to display if assertion fails * @param diff the result of an XML comparison * @param assertion true if asserting that result is similar */ @@ -221,17 +182,6 @@ /** * Assert that the result of an XML comparison is or is not identical - * @param diff the result of an XML comparison - * @param assertion true if asserting that result is identical - * @param msg additional message to display if assertion fails - * @deprecated Use XMLTestCase#assertXMLIdentical(String, Diff, boolean) instead - */ - public void assertXMLIdentical(Diff diff, boolean assertion, String msg) { - XMLAssert.assertXMLIdentical(msg, diff, assertion); - } - - /** - * Assert that the result of an XML comparison is or is not identical * @param msg Message to display if assertion fails * @param diff the result of an XML comparison * @param assertion true if asserting that result is identical @@ -925,18 +875,6 @@ /** * Assert that a specific XPath does NOT exist in some given XML * @param inXpathExpression - * @param inXMLString - * @deprecated Use assertXpathNotExists instead - */ - public void assertNotXpathExists(String xPathExpression, - String inXMLString) - throws IOException, SAXException , XpathException { - XMLAssert.assertXpathNotExists(xPathExpression, inXMLString); - } - - /** - * Assert that a specific XPath does NOT exist in some given XML - * @param inXpathExpression * @param inDocument * @see XpathEngine which provides the underlying evaluation mechanism */ @@ -947,18 +885,6 @@ } /** - * Assert that a specific XPath does NOT exist in some given XML - * @param inXpathExpression - * @param inDocument - * @deprecated Use assertXpathNotExists instead - */ - public void assertNotXpathExists(String xPathExpression, - Document inDocument) - throws XpathException { - XMLAssert.assertXpathNotExists(xPathExpression, inDocument); - } - - /** * Assert that a piece of XML contains valid XML: the input must * contain a DOCTYPE declaration to be validated * @param xml Modified: trunk/xmlunit/src/java/org/custommonkey/xmlunit/XMLUnit.java =================================================================== --- trunk/xmlunit/src/java/org/custommonkey/xmlunit/XMLUnit.java 2007-04-16 13:06:55 UTC (rev 187) +++ trunk/xmlunit/src/java/org/custommonkey/xmlunit/XMLUnit.java 2007-04-17 03:59:29 UTC (rev 188) @@ -280,76 +280,6 @@ } /** - * Compare XML documents provided by two Reader classes. - * @param control Control document - * @param test Document to test - * @return Diff object describing differences in documents - * @throws SAXException - * @throws IOException - * @deprecated use Diff constructor directly - */ - public static Diff compare(Reader control, Reader test) - throws SAXException, IOException { - return new Diff(control, test); - } - - /** - * Compare two XML documents provided by SAX <code>InputSources</code> - * @param control Control document - * @param test Document to test - * @return Diff object describing differences in documents - * @throws SAXException - * @throws IOException - * @deprecated use Diff constructor directly - */ - public static Diff compare(InputSource control, InputSource test) - throws SAXException, IOException { - return new Diff(control, test); - } - - /** - * Compare two XML documents provided by a string and a Reader. - * @param control Control document - * @param test Document to test - * @return Diff object describing differences in documents - * @throws SAXException - * @throws IOException - * @deprecated use Diff constructor directly - */ - public static Diff compare(String control, Reader test) throws SAXException, - IOException { - return new Diff(new StringReader(control), test); - } - - /** - * Compare two XML documents provided by a Reader and a string. - * @param control Control document - * @param test Document to test - * @return Diff object describing differences in documents - * @throws SAXException - * @throws IOException - * @deprecated use Diff constructor directly - */ - public static Diff compare(Reader control, String test) throws SAXException, - IOException { - return new Diff(control, new StringReader(test)); - } - - /** - * Compare two XML documents provided as strings. - * @param control Control document - * @param test Document to test - * @return Diff object describing differences in documents - * @throws SAXException - * @throws IOException - * @deprecated use Diff constructor directly - */ - public static Diff compare(String control, String test) throws SAXException, - IOException { - return new Diff(control, test); - } - - /** * Utility method to build a Document using the control DocumentBuilder * to parse the specified String. * @param fromXML This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bo...@us...> - 2007-05-01 11:41:21
|
Revision: 205 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=205&view=rev Author: bodewig Date: 2007-05-01 04:41:21 -0700 (Tue, 01 May 2007) Log Message: ----------- Make XPathFactory configurable Modified Paths: -------------- trunk/xmlunit/src/java/org/custommonkey/xmlunit/XMLUnit.java trunk/xmlunit/src/java/org/custommonkey/xmlunit/jaxp13/Jaxp13XpathEngine.java Modified: trunk/xmlunit/src/java/org/custommonkey/xmlunit/XMLUnit.java =================================================================== --- trunk/xmlunit/src/java/org/custommonkey/xmlunit/XMLUnit.java 2007-05-01 10:47:53 UTC (rev 204) +++ trunk/xmlunit/src/java/org/custommonkey/xmlunit/XMLUnit.java 2007-05-01 11:41:21 UTC (rev 205) @@ -76,6 +76,7 @@ private static boolean normalizeWhitespace = false; private static boolean ignoreAttributeOrder = false; private static String xsltVersion = "1.0"; + private static String xpathFactoryName = null; private static final String XSLT_VERSION_START = " version=\""; private static final String XSLT_VERSION_END = "\">"; @@ -744,6 +745,20 @@ } /** + * Sets the class to use as XPathFactory when using JAXP 1.3. + */ + public static void setXPathFactory(String className) { + xpathFactoryName = className; + } + + /** + * Gets the class to use as XPathFactory when using JAXP 1.3. + */ + public static String getXPathFactory() { + return xpathFactoryName; + } + + /** * XSLT stylesheet element using the configured XSLT version. */ static String getXSLTStart() { Modified: trunk/xmlunit/src/java/org/custommonkey/xmlunit/jaxp13/Jaxp13XpathEngine.java =================================================================== --- trunk/xmlunit/src/java/org/custommonkey/xmlunit/jaxp13/Jaxp13XpathEngine.java 2007-05-01 10:47:53 UTC (rev 204) +++ trunk/xmlunit/src/java/org/custommonkey/xmlunit/jaxp13/Jaxp13XpathEngine.java 2007-05-01 11:41:21 UTC (rev 205) @@ -1,6 +1,6 @@ /* ****************************************************************** -Copyright (c) 2001, Jeff Martin, Tim Bacon +Copyright (c) 2006-2007, Jeff Martin, Tim Bacon All rights reserved. Redistribution and use in source and binary forms, with or without @@ -36,10 +36,11 @@ package org.custommonkey.xmlunit.jaxp13; +import org.custommonkey.xmlunit.NamespaceContext; +import org.custommonkey.xmlunit.XMLUnit; +import org.custommonkey.xmlunit.XpathEngine; import org.custommonkey.xmlunit.exceptions.ConfigurationException; import org.custommonkey.xmlunit.exceptions.XpathException; -import org.custommonkey.xmlunit.NamespaceContext; -import org.custommonkey.xmlunit.XpathEngine; import javax.xml.xpath.XPath; import javax.xml.xpath.XPathConstants; @@ -59,7 +60,15 @@ public Jaxp13XpathEngine() throws ConfigurationException { try { - xpath = XPathFactory.newInstance().newXPath(); + XPathFactory f = null; + if (XMLUnit.getXPathFactory() != null) { + f = (XPathFactory) Class.forName(XMLUnit.getXPathFactory()) + .newInstance(); + } else { + f = XPathFactory.newInstance(); + } + + xpath = f.newXPath(); } catch (Exception ex) { throw new ConfigurationException(ex); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bo...@us...> - 2007-05-29 11:36:06
|
Revision: 215 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=215&view=rev Author: bodewig Date: 2007-05-29 04:35:11 -0700 (Tue, 29 May 2007) Log Message: ----------- fix FindBugs detected problems, nothing major Modified Paths: -------------- trunk/xmlunit/src/java/org/custommonkey/xmlunit/Difference.java trunk/xmlunit/src/java/org/custommonkey/xmlunit/ElementNameAndAttributeQualifier.java trunk/xmlunit/src/java/org/custommonkey/xmlunit/HTMLDocumentBuilder.java trunk/xmlunit/src/java/org/custommonkey/xmlunit/NodeDescriptor.java trunk/xmlunit/src/java/org/custommonkey/xmlunit/NodeTest.java trunk/xmlunit/src/java/org/custommonkey/xmlunit/NodeTestException.java trunk/xmlunit/src/java/org/custommonkey/xmlunit/XpathNodeTracker.java Modified: trunk/xmlunit/src/java/org/custommonkey/xmlunit/Difference.java =================================================================== --- trunk/xmlunit/src/java/org/custommonkey/xmlunit/Difference.java 2007-05-25 08:07:33 UTC (rev 214) +++ trunk/xmlunit/src/java/org/custommonkey/xmlunit/Difference.java 2007-05-29 11:35:11 UTC (rev 215) @@ -1,6 +1,6 @@ /* ****************************************************************** -Copyright (c) 2001, Jeff Martin, Tim Bacon +Copyright (c) 2001-2007, Jeff Martin, Tim Bacon All rights reserved. Redistribution and use in source and binary forms, with or without @@ -148,6 +148,13 @@ } /** + * hashcode implementation to go with equals. + */ + public int hashCode() { + return id; + } + + /** * @return a basic representation of the object state and identity * and if <code>NodeDetail</code> instances are populated append * their details also Modified: trunk/xmlunit/src/java/org/custommonkey/xmlunit/ElementNameAndAttributeQualifier.java =================================================================== --- trunk/xmlunit/src/java/org/custommonkey/xmlunit/ElementNameAndAttributeQualifier.java 2007-05-25 08:07:33 UTC (rev 214) +++ trunk/xmlunit/src/java/org/custommonkey/xmlunit/ElementNameAndAttributeQualifier.java 2007-05-29 11:35:11 UTC (rev 215) @@ -1,6 +1,6 @@ /* ****************************************************************** -Copyright (c) 2001, Jeff Martin, Tim Bacon +Copyright (c) 2001-2007, Jeff Martin, Tim Bacon All rights reserved. Redistribution and use in source and binary forms, with or without @@ -36,6 +36,7 @@ package org.custommonkey.xmlunit; +import java.util.Arrays; import org.w3c.dom.Attr; import org.w3c.dom.Element; import org.w3c.dom.NamedNodeMap; @@ -49,7 +50,7 @@ * @see Diff#overrideElementQualifier(ElementQualifier) */ public class ElementNameAndAttributeQualifier extends ElementNameQualifier { - public static final String[] ALL_ATTRIBUTES = {"*"}; + private static final String[] ALL_ATTRIBUTES = {"*"}; private final String[] qualifyingAttrNames; @@ -76,7 +77,9 @@ * elements can be compared further for differences */ public ElementNameAndAttributeQualifier(String[] attrNames) { - this.qualifyingAttrNames = attrNames; + this.qualifyingAttrNames = new String[attrNames.length]; + System.arraycopy(attrNames, 0, qualifyingAttrNames, 0, + attrNames.length); } /** @@ -109,7 +112,7 @@ String controlValue, testValue; Attr[] qualifyingAttributes; NamedNodeMap namedNodeMap = control.getAttributes(); - if (qualifyingAttrNames == ALL_ATTRIBUTES) { + if (matchesAllAttributes(qualifyingAttrNames)) { qualifyingAttributes = new Attr[namedNodeMap.getLength()]; for (int n=0; n < qualifyingAttributes.length; ++n) { qualifyingAttributes[n] = (Attr) namedNodeMap.item(n); @@ -150,4 +153,7 @@ return true; } + private static boolean matchesAllAttributes(String[] attributes) { + return Arrays.equals(attributes, ALL_ATTRIBUTES); + } } Modified: trunk/xmlunit/src/java/org/custommonkey/xmlunit/HTMLDocumentBuilder.java =================================================================== --- trunk/xmlunit/src/java/org/custommonkey/xmlunit/HTMLDocumentBuilder.java 2007-05-25 08:07:33 UTC (rev 214) +++ trunk/xmlunit/src/java/org/custommonkey/xmlunit/HTMLDocumentBuilder.java 2007-05-29 11:35:11 UTC (rev 215) @@ -1,6 +1,6 @@ /* ****************************************************************** -Copyright (c) 2001, Jeff Martin, Tim Bacon +Copyright (c) 2001-2007, Jeff Martin, Tim Bacon All rights reserved. Redistribution and use in source and binary forms, with or without @@ -121,7 +121,7 @@ * to a Sax-aware ContentHandler. */ public class SwingEvent2SaxAdapter extends HTMLEditorKit.ParserCallback { - private final boolean IGNORE_HTML_CHAR_SET = true; + private static final boolean IGNORE_HTML_CHAR_SET = true; private final AttributesImpl attributes; private final ParserDelegator delegator; private boolean lastTagWasSimpleTag; Modified: trunk/xmlunit/src/java/org/custommonkey/xmlunit/NodeDescriptor.java =================================================================== --- trunk/xmlunit/src/java/org/custommonkey/xmlunit/NodeDescriptor.java 2007-05-25 08:07:33 UTC (rev 214) +++ trunk/xmlunit/src/java/org/custommonkey/xmlunit/NodeDescriptor.java 2007-05-29 11:35:11 UTC (rev 215) @@ -1,6 +1,6 @@ /* ****************************************************************** -Copyright (c) 2001, Jeff Martin, Tim Bacon +Copyright (c) 2001-2007, Jeff Martin, Tim Bacon All rights reserved. Redistribution and use in source and binary forms, with or without @@ -45,7 +45,7 @@ * Class for describing Nodes */ public class NodeDescriptor implements XMLConstants { - protected static String DOCUMENT_NODE_DESCRIPTION = "Document Node "; + protected static final String DOCUMENT_NODE_DESCRIPTION = "Document Node "; /** * Convert a Node into a simple String representation Modified: trunk/xmlunit/src/java/org/custommonkey/xmlunit/NodeTest.java =================================================================== --- trunk/xmlunit/src/java/org/custommonkey/xmlunit/NodeTest.java 2007-05-25 08:07:33 UTC (rev 214) +++ trunk/xmlunit/src/java/org/custommonkey/xmlunit/NodeTest.java 2007-05-29 11:35:11 UTC (rev 215) @@ -1,6 +1,6 @@ /* ****************************************************************** -Copyright (c) 2001, Jeff Martin, Tim Bacon +Copyright (c) 2001-2007, Jeff Martin, Tim Bacon All rights reserved. Redistribution and use in source and binary forms, with or without @@ -160,7 +160,7 @@ * Node type specific Node Filter: accepts Nodes of those types specified * in constructor, rejects all others */ - private class NodeTypeNodeFilter implements NodeFilter { + private static class NodeTypeNodeFilter implements NodeFilter { private final short[] nodeTypes; /** Modified: trunk/xmlunit/src/java/org/custommonkey/xmlunit/NodeTestException.java =================================================================== --- trunk/xmlunit/src/java/org/custommonkey/xmlunit/NodeTestException.java 2007-05-25 08:07:33 UTC (rev 214) +++ trunk/xmlunit/src/java/org/custommonkey/xmlunit/NodeTestException.java 2007-05-29 11:35:11 UTC (rev 215) @@ -1,6 +1,6 @@ /* ****************************************************************** -Copyright (c) 2001, Jeff Martin, Tim Bacon +Copyright (c) 2001-2007, Jeff Martin, Tim Bacon All rights reserved. Redistribution and use in source and binary forms, with or without @@ -44,7 +44,7 @@ * @see NodeTest */ public class NodeTestException extends Exception { - private final Node node; + private transient final Node node; /** * Constructor for specific node and message Modified: trunk/xmlunit/src/java/org/custommonkey/xmlunit/XpathNodeTracker.java =================================================================== --- trunk/xmlunit/src/java/org/custommonkey/xmlunit/XpathNodeTracker.java 2007-05-25 08:07:33 UTC (rev 214) +++ trunk/xmlunit/src/java/org/custommonkey/xmlunit/XpathNodeTracker.java 2007-05-29 11:35:11 UTC (rev 215) @@ -58,8 +58,6 @@ private final List indentationList = new ArrayList(); private TrackingEntry currentEntry; - private boolean trackRepeatedVisits = false; - /** * Simple constructor */ @@ -198,7 +196,7 @@ * Wrapper class around a mutable <code>int</code> value * Avoids creation of many immutable <code>Integer</code> objects */ - private final class Int { + private static final class Int { private int value; public Int(int startAt) { @@ -222,7 +220,7 @@ * Holds node tracking details - one instance is used for each level of indentation in a DOM * Provides reference between a String-ified Node value and the xpath index of that value */ - private final class TrackingEntry { + private static final class TrackingEntry { private final Map valueMap = new HashMap(); private String currentValue, currentAttribute; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bo...@us...> - 2007-05-29 12:31:29
|
Revision: 216 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=216&view=rev Author: bodewig Date: 2007-05-29 05:31:26 -0700 (Tue, 29 May 2007) Log Message: ----------- fix PMD detected problems, nothing major Modified Paths: -------------- trunk/xmlunit/src/java/org/custommonkey/xmlunit/DetailedDiff.java trunk/xmlunit/src/java/org/custommonkey/xmlunit/Diff.java trunk/xmlunit/src/java/org/custommonkey/xmlunit/DifferenceEngine.java trunk/xmlunit/src/java/org/custommonkey/xmlunit/DoctypeReader.java trunk/xmlunit/src/java/org/custommonkey/xmlunit/DoctypeSupport.java trunk/xmlunit/src/java/org/custommonkey/xmlunit/ElementNameQualifier.java trunk/xmlunit/src/java/org/custommonkey/xmlunit/NodeInputStream.java trunk/xmlunit/src/java/org/custommonkey/xmlunit/SimpleXpathEngine.java trunk/xmlunit/src/java/org/custommonkey/xmlunit/TolerantSaxDocumentBuilder.java trunk/xmlunit/src/java/org/custommonkey/xmlunit/Transform.java trunk/xmlunit/src/java/org/custommonkey/xmlunit/Validator.java trunk/xmlunit/src/java/org/custommonkey/xmlunit/XpathEngine.java trunk/xmlunit/src/java/org/custommonkey/xmlunit/XpathNodeTracker.java trunk/xmlunit/src/java/org/custommonkey/xmlunit/examples/MultiLevelElementNameAndTextQualifier.java trunk/xmlunit/src/java/org/custommonkey/xmlunit/examples/XPathRegexAssert.java trunk/xmlunit/src/java/org/custommonkey/xmlunit/exceptions/XMLUnitException.java trunk/xmlunit/src/java/org/custommonkey/xmlunit/exceptions/XMLUnitRuntimeException.java trunk/xmlunit/src/java/org/custommonkey/xmlunit/exceptions/XpathException.java trunk/xmlunit/src/java/org/custommonkey/xmlunit/jaxp13/Jaxp13XpathEngine.java trunk/xmlunit/src/java/org/custommonkey/xmlunit/jaxp13/XMLUnitNamespaceContext2Jaxp13.java Modified: trunk/xmlunit/src/java/org/custommonkey/xmlunit/DetailedDiff.java =================================================================== --- trunk/xmlunit/src/java/org/custommonkey/xmlunit/DetailedDiff.java 2007-05-29 11:35:11 UTC (rev 215) +++ trunk/xmlunit/src/java/org/custommonkey/xmlunit/DetailedDiff.java 2007-05-29 12:31:26 UTC (rev 216) @@ -1,6 +1,6 @@ /* ****************************************************************** -Copyright (c) 2001, Jeff Martin, Tim Bacon +Copyright (c) 2001-2007, Jeff Martin, Tim Bacon All rights reserved. Redistribution and use in source and binary forms, with or without @@ -73,7 +73,6 @@ */ public int differenceFound(Difference difference) { final int returnValue = super.differenceFound(difference); - Difference localDifference = null; switch (returnValue) { case RETURN_IGNORE_DIFFERENCE_NODES_IDENTICAL: return returnValue; @@ -82,6 +81,11 @@ case RETURN_IGNORE_DIFFERENCE_NODES_SIMILAR: difference.setRecoverable(true); break; + default: + throw new IllegalArgumentException(returnValue + + " is not a defined " + + " DifferenceListener" + + ".RETURN_... value"); } allDifferences.add(difference); return returnValue; Modified: trunk/xmlunit/src/java/org/custommonkey/xmlunit/Diff.java =================================================================== --- trunk/xmlunit/src/java/org/custommonkey/xmlunit/Diff.java 2007-05-29 11:35:11 UTC (rev 215) +++ trunk/xmlunit/src/java/org/custommonkey/xmlunit/Diff.java 2007-05-29 12:31:26 UTC (rev 216) @@ -1,6 +1,6 @@ /* ****************************************************************** -Copyright (c) 2001, Jeff Martin, Tim Bacon +Copyright (c) 2001-2007, Jeff Martin, Tim Bacon All rights reserved. Redistribution and use in source and binary forms, with or without @@ -279,7 +279,7 @@ * @param difference */ private void appendDifference(StringBuffer appendTo, Difference difference) { - appendTo.append(" ").append(difference).append('\n'); + appendTo.append(' ').append(difference).append('\n'); } /** Modified: trunk/xmlunit/src/java/org/custommonkey/xmlunit/DifferenceEngine.java =================================================================== --- trunk/xmlunit/src/java/org/custommonkey/xmlunit/DifferenceEngine.java 2007-05-29 11:35:11 UTC (rev 215) +++ trunk/xmlunit/src/java/org/custommonkey/xmlunit/DifferenceEngine.java 2007-05-29 12:31:26 UTC (rev 216) @@ -37,7 +37,6 @@ package org.custommonkey.xmlunit; import java.util.ArrayList; -import java.util.Collection; import java.util.HashMap; import java.util.Iterator; import java.util.List; @@ -264,7 +263,7 @@ boolean flag = n.hasChildNodes(); if (flag && XMLUnit.getIgnoreComments()) { List nl = nodeList2List(n.getChildNodes()); - flag = nl.size() > 0; + flag = !nl.isEmpty(); } return flag ? Boolean.TRUE : Boolean.FALSE; } Modified: trunk/xmlunit/src/java/org/custommonkey/xmlunit/DoctypeReader.java =================================================================== --- trunk/xmlunit/src/java/org/custommonkey/xmlunit/DoctypeReader.java 2007-05-29 11:35:11 UTC (rev 215) +++ trunk/xmlunit/src/java/org/custommonkey/xmlunit/DoctypeReader.java 2007-05-29 12:31:26 UTC (rev 216) @@ -1,6 +1,6 @@ /* ****************************************************************** -Copyright (c) 2001, Jeff Martin, Tim Bacon +Copyright (c) 2001-2007, Jeff Martin, Tim Bacon All rights reserved. Redistribution and use in source and binary forms, with or without Modified: trunk/xmlunit/src/java/org/custommonkey/xmlunit/DoctypeSupport.java =================================================================== --- trunk/xmlunit/src/java/org/custommonkey/xmlunit/DoctypeSupport.java 2007-05-29 11:35:11 UTC (rev 215) +++ trunk/xmlunit/src/java/org/custommonkey/xmlunit/DoctypeSupport.java 2007-05-29 12:31:26 UTC (rev 216) @@ -1,6 +1,6 @@ /* ****************************************************************** -Copyright (c) 2001, Jeff Martin, Tim Bacon +Copyright (c) 2007, Jeff Martin, Tim Bacon All rights reserved. Redistribution and use in source and binary forms, with or without @@ -76,7 +76,7 @@ StringBuffer sb = new StringBuffer(DOCTYPE_OPEN_DECL); sb.append(DOCTYPE).append(name).append(SYSTEM) - .append(systemId).append("\"").append(DOCTYPE_CLOSE_DECL); + .append(systemId).append('\"').append(DOCTYPE_CLOSE_DECL); String s = sb.toString(); IntegerBuffer buf = new IntegerBuffer(s.length() * (characters ? 1 : 2)); Modified: trunk/xmlunit/src/java/org/custommonkey/xmlunit/ElementNameQualifier.java =================================================================== --- trunk/xmlunit/src/java/org/custommonkey/xmlunit/ElementNameQualifier.java 2007-05-29 11:35:11 UTC (rev 215) +++ trunk/xmlunit/src/java/org/custommonkey/xmlunit/ElementNameQualifier.java 2007-05-29 12:31:26 UTC (rev 216) @@ -1,6 +1,6 @@ /* ****************************************************************** -Copyright (c) 2001, Jeff Martin, Tim Bacon +Copyright (c) 2001-2007, Jeff Martin, Tim Bacon All rights reserved. Redistribution and use in source and binary forms, with or without Modified: trunk/xmlunit/src/java/org/custommonkey/xmlunit/NodeInputStream.java =================================================================== --- trunk/xmlunit/src/java/org/custommonkey/xmlunit/NodeInputStream.java 2007-05-29 11:35:11 UTC (rev 215) +++ trunk/xmlunit/src/java/org/custommonkey/xmlunit/NodeInputStream.java 2007-05-29 12:31:26 UTC (rev 216) @@ -1,6 +1,6 @@ /* ****************************************************************** -Copyright (c) 2001, Jeff Martin, Tim Bacon +Copyright (c) 2001-2007, Jeff Martin, Tim Bacon All rights reserved. Redistribution and use in source and binary forms, with or without Modified: trunk/xmlunit/src/java/org/custommonkey/xmlunit/SimpleXpathEngine.java =================================================================== --- trunk/xmlunit/src/java/org/custommonkey/xmlunit/SimpleXpathEngine.java 2007-05-29 11:35:11 UTC (rev 215) +++ trunk/xmlunit/src/java/org/custommonkey/xmlunit/SimpleXpathEngine.java 2007-05-29 12:31:26 UTC (rev 216) @@ -1,6 +1,6 @@ /* ****************************************************************** -Copyright (c) 2001, Jeff Martin, Tim Bacon +Copyright (c) 2001-2007, Jeff Martin, Tim Bacon All rights reserved. Redistribution and use in source and binary forms, with or without @@ -228,10 +228,10 @@ prefix = ""; } - if (uri.indexOf("'") != -1) { + if (uri.indexOf('\'') != -1) { quoteStyle = "\""; } - nsDecls.append(" ").append(XMLNS_PREFIX); + nsDecls.append(' ').append(XMLNS_PREFIX); if (prefix.length() > 0) { nsDecls.append(':'); } Modified: trunk/xmlunit/src/java/org/custommonkey/xmlunit/TolerantSaxDocumentBuilder.java =================================================================== --- trunk/xmlunit/src/java/org/custommonkey/xmlunit/TolerantSaxDocumentBuilder.java 2007-05-29 11:35:11 UTC (rev 215) +++ trunk/xmlunit/src/java/org/custommonkey/xmlunit/TolerantSaxDocumentBuilder.java 2007-05-29 12:31:26 UTC (rev 216) @@ -1,6 +1,6 @@ /* ****************************************************************** -Copyright (c) 2001, Jeff Martin, Tim Bacon +Copyright (c) 2001-2007, Jeff Martin, Tim Bacon All rights reserved. Redistribution and use in source and binary forms, with or without @@ -158,7 +158,6 @@ return; } - String nodeName; Node parentNode = null; boolean atDocumentRoot = false, foundTagToEnd = false; Element startElement = currentElement; Modified: trunk/xmlunit/src/java/org/custommonkey/xmlunit/Transform.java =================================================================== --- trunk/xmlunit/src/java/org/custommonkey/xmlunit/Transform.java 2007-05-29 11:35:11 UTC (rev 215) +++ trunk/xmlunit/src/java/org/custommonkey/xmlunit/Transform.java 2007-05-29 12:31:26 UTC (rev 216) @@ -1,6 +1,6 @@ /* ****************************************************************** -Copyright (c) 2001, Jeff Martin, Tim Bacon +Copyright (c) 2001-2007, Jeff Martin, Tim Bacon All rights reserved. Redistribution and use in source and binary forms, with or without @@ -37,6 +37,7 @@ package org.custommonkey.xmlunit; import org.custommonkey.xmlunit.exceptions.ConfigurationException; +import org.custommonkey.xmlunit.exceptions.XMLUnitRuntimeException; import java.io.File; import java.io.StringReader; @@ -178,7 +179,8 @@ try { return PWD.toURL().toExternalForm(); } catch (MalformedURLException e) { - throw new RuntimeException("Unable to determine current working directory!"); + throw new XMLUnitRuntimeException("Unable to determine current " + + "working directory!", e); } } /** Modified: trunk/xmlunit/src/java/org/custommonkey/xmlunit/Validator.java =================================================================== --- trunk/xmlunit/src/java/org/custommonkey/xmlunit/Validator.java 2007-05-29 11:35:11 UTC (rev 215) +++ trunk/xmlunit/src/java/org/custommonkey/xmlunit/Validator.java 2007-05-29 12:31:26 UTC (rev 216) @@ -1,6 +1,6 @@ /* ****************************************************************** -Copyright (c) 2001, Jeff Martin, Tim Bacon +Copyright (c) 2001-2007, Jeff Martin, Tim Bacon All rights reserved. Redistribution and use in source and binary forms, with or without Modified: trunk/xmlunit/src/java/org/custommonkey/xmlunit/XpathEngine.java =================================================================== --- trunk/xmlunit/src/java/org/custommonkey/xmlunit/XpathEngine.java 2007-05-29 11:35:11 UTC (rev 215) +++ trunk/xmlunit/src/java/org/custommonkey/xmlunit/XpathEngine.java 2007-05-29 12:31:26 UTC (rev 216) @@ -1,6 +1,6 @@ /* ****************************************************************** -Copyright (c) 2001, Jeff Martin, Tim Bacon +Copyright (c) 2006-2007, Jeff Martin, Tim Bacon All rights reserved. Redistribution and use in source and binary forms, with or without @@ -36,11 +36,9 @@ package org.custommonkey.xmlunit; -import org.custommonkey.xmlunit.exceptions.ConfigurationException; import org.custommonkey.xmlunit.exceptions.XpathException; import org.w3c.dom.Document; -import org.w3c.dom.Node; import org.w3c.dom.NodeList; /** Modified: trunk/xmlunit/src/java/org/custommonkey/xmlunit/XpathNodeTracker.java =================================================================== --- trunk/xmlunit/src/java/org/custommonkey/xmlunit/XpathNodeTracker.java 2007-05-29 11:35:11 UTC (rev 215) +++ trunk/xmlunit/src/java/org/custommonkey/xmlunit/XpathNodeTracker.java 2007-05-29 12:31:26 UTC (rev 216) @@ -62,7 +62,7 @@ * Simple constructor */ public XpathNodeTracker() { - indent(); + newLevel(); } /** @@ -81,6 +81,10 @@ if (currentEntry != null) { currentEntry.clearTrackedAttribute(); } + newLevel(); + } + + private void newLevel() { currentEntry = new TrackingEntry(); indentationList.add(currentEntry); } @@ -138,6 +142,9 @@ case Node.TEXT_NODE: visitedNode(node, XPATH_CHARACTER_NODE_IDENTIFIER); break; + default: + // ignore unhandled node types + break; } } @@ -203,15 +210,15 @@ value = startAt; } - public final void increment() { + public void increment() { ++value; } - public final int getValue() { + public int getValue() { return value; } - public final Integer toInteger() { + public Integer toInteger() { return new Integer(value); } } @@ -237,7 +244,7 @@ * @param visited the non-attribute node visited * @param value the String-ified value of the non-attribute node visited */ - public final void trackNode(Node visited, String value) { + public void trackNode(Node visited, String value) { if (nodeReferenceMap == null || trackNodeReferences) { Int occurrence = lookup(value); if (occurrence == null) { @@ -260,14 +267,14 @@ * Keep a reference to the visited attribute at the current visited node * @param value the attribute visited */ - public final void trackAttribute(String visited) { + public void trackAttribute(String visited) { currentAttribute = visited; } /** * Clear any reference to the current visited attribute */ - public final void clearTrackedAttribute() { + public void clearTrackedAttribute() { currentAttribute = null; } @@ -275,7 +282,7 @@ * Append the details of the current visited node to a StringBuffer * @param buf the StringBuffer to append to */ - public final void appendEntryTo(StringBuffer buf) { + public void appendEntryTo(StringBuffer buf) { if (currentValue == null) { return; } Modified: trunk/xmlunit/src/java/org/custommonkey/xmlunit/examples/MultiLevelElementNameAndTextQualifier.java =================================================================== --- trunk/xmlunit/src/java/org/custommonkey/xmlunit/examples/MultiLevelElementNameAndTextQualifier.java 2007-05-29 11:35:11 UTC (rev 215) +++ trunk/xmlunit/src/java/org/custommonkey/xmlunit/examples/MultiLevelElementNameAndTextQualifier.java 2007-05-29 12:31:26 UTC (rev 216) @@ -38,8 +38,6 @@ import org.w3c.dom.Element; import org.w3c.dom.Node; -import org.w3c.dom.NodeList; -import org.w3c.dom.Text; import org.custommonkey.xmlunit.ElementNameAndTextQualifier; import org.custommonkey.xmlunit.ElementNameQualifier; Modified: trunk/xmlunit/src/java/org/custommonkey/xmlunit/examples/XPathRegexAssert.java =================================================================== --- trunk/xmlunit/src/java/org/custommonkey/xmlunit/examples/XPathRegexAssert.java 2007-05-29 11:35:11 UTC (rev 215) +++ trunk/xmlunit/src/java/org/custommonkey/xmlunit/examples/XPathRegexAssert.java 2007-05-29 12:31:26 UTC (rev 216) @@ -1,7 +1,7 @@ // -*- Mode: JDE -*- /* ****************************************************************** -Copyright (c) 2001, Jeff Martin, Tim Bacon +Copyright (c) 2006-2007, Jeff Martin, Tim Bacon All rights reserved. Redistribution and use in source and binary forms, with or without @@ -56,6 +56,8 @@ */ public class XPathRegexAssert { + // no instances + private XPathRegexAssert() {} public static void assertXPathMatches(String message, String regex, String xpath, Document doc) Modified: trunk/xmlunit/src/java/org/custommonkey/xmlunit/exceptions/XMLUnitException.java =================================================================== --- trunk/xmlunit/src/java/org/custommonkey/xmlunit/exceptions/XMLUnitException.java 2007-05-29 11:35:11 UTC (rev 215) +++ trunk/xmlunit/src/java/org/custommonkey/xmlunit/exceptions/XMLUnitException.java 2007-05-29 12:31:26 UTC (rev 216) @@ -1,6 +1,6 @@ /* ****************************************************************** -Copyright (c) 2001, Jeff Martin, Tim Bacon +Copyright (c) 2006-2007, Jeff Martin, Tim Bacon All rights reserved. Redistribution and use in source and binary forms, with or without Modified: trunk/xmlunit/src/java/org/custommonkey/xmlunit/exceptions/XMLUnitRuntimeException.java =================================================================== --- trunk/xmlunit/src/java/org/custommonkey/xmlunit/exceptions/XMLUnitRuntimeException.java 2007-05-29 11:35:11 UTC (rev 215) +++ trunk/xmlunit/src/java/org/custommonkey/xmlunit/exceptions/XMLUnitRuntimeException.java 2007-05-29 12:31:26 UTC (rev 216) @@ -1,6 +1,6 @@ /* ****************************************************************** -Copyright (c) 2001, Jeff Martin, Tim Bacon +Copyright (c) 2006-2007, Jeff Martin, Tim Bacon All rights reserved. Redistribution and use in source and binary forms, with or without @@ -55,6 +55,15 @@ } /** + * Inititializes an exeption without cause. + * + * @param message the detail message + */ + public XMLUnitRuntimeException(String message) { + this(message, null); + } + + /** * Root cause of the exception, if any. */ public Throwable getCause() { Modified: trunk/xmlunit/src/java/org/custommonkey/xmlunit/exceptions/XpathException.java =================================================================== --- trunk/xmlunit/src/java/org/custommonkey/xmlunit/exceptions/XpathException.java 2007-05-29 11:35:11 UTC (rev 215) +++ trunk/xmlunit/src/java/org/custommonkey/xmlunit/exceptions/XpathException.java 2007-05-29 12:31:26 UTC (rev 216) @@ -1,6 +1,6 @@ /* ****************************************************************** -Copyright (c) 2001, Jeff Martin, Tim Bacon +Copyright (c) 2006-2007, Jeff Martin, Tim Bacon All rights reserved. Redistribution and use in source and binary forms, with or without Modified: trunk/xmlunit/src/java/org/custommonkey/xmlunit/jaxp13/Jaxp13XpathEngine.java =================================================================== --- trunk/xmlunit/src/java/org/custommonkey/xmlunit/jaxp13/Jaxp13XpathEngine.java 2007-05-29 11:35:11 UTC (rev 215) +++ trunk/xmlunit/src/java/org/custommonkey/xmlunit/jaxp13/Jaxp13XpathEngine.java 2007-05-29 12:31:26 UTC (rev 216) @@ -48,7 +48,6 @@ import javax.xml.xpath.XPathFactory; import org.w3c.dom.Document; -import org.w3c.dom.Node; import org.w3c.dom.NodeList; /** Modified: trunk/xmlunit/src/java/org/custommonkey/xmlunit/jaxp13/XMLUnitNamespaceContext2Jaxp13.java =================================================================== --- trunk/xmlunit/src/java/org/custommonkey/xmlunit/jaxp13/XMLUnitNamespaceContext2Jaxp13.java 2007-05-29 11:35:11 UTC (rev 215) +++ trunk/xmlunit/src/java/org/custommonkey/xmlunit/jaxp13/XMLUnitNamespaceContext2Jaxp13.java 2007-05-29 12:31:26 UTC (rev 216) @@ -1,6 +1,6 @@ /* ****************************************************************** -Copyright (c) 2001, Jeff Martin, Tim Bacon +Copyright (c) 2006-2007, Jeff Martin, Tim Bacon All rights reserved. Redistribution and use in source and binary forms, with or without @@ -52,7 +52,7 @@ public class XMLUnitNamespaceContext2Jaxp13 implements javax.xml.namespace.NamespaceContext { - private final HashMap/*<String, String>*/ nsMap; + private final Map/*<String, String>*/ nsMap; public XMLUnitNamespaceContext2Jaxp13(NamespaceContext ctx) { nsMap = turnIntoMap(ctx); @@ -91,7 +91,7 @@ return i.hasNext() ? (String) i.next() : null; } - private static HashMap turnIntoMap(NamespaceContext ctx) { + private static Map turnIntoMap(NamespaceContext ctx) { HashMap/*<String, String>*/ m = new HashMap(); for (Iterator i = ctx.getPrefixes(); i.hasNext(); ) { String prefix = (String) i.next(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bo...@us...> - 2007-06-27 06:50:31
|
Revision: 219 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=219&view=rev Author: bodewig Date: 2007-06-26 23:50:33 -0700 (Tue, 26 Jun 2007) Log Message: ----------- Fix for Bug 1742826 Modified Paths: -------------- trunk/xmlunit/src/java/org/custommonkey/xmlunit/Transform.java trunk/xmlunit/src/java/org/custommonkey/xmlunit/XMLUnit.java Modified: trunk/xmlunit/src/java/org/custommonkey/xmlunit/Transform.java =================================================================== --- trunk/xmlunit/src/java/org/custommonkey/xmlunit/Transform.java 2007-06-27 06:50:14 UTC (rev 218) +++ trunk/xmlunit/src/java/org/custommonkey/xmlunit/Transform.java 2007-06-27 06:50:33 UTC (rev 219) @@ -196,9 +196,6 @@ Transformer t = stylesheetSource == null ? factory.newTransformer() : factory.newTransformer(stylesheetSource); - if (XMLUnit.getURIResolver() != null) { - t.setURIResolver(XMLUnit.getURIResolver()); - } return t; } catch (javax.xml.transform.TransformerConfigurationException ex) { throw new ConfigurationException(ex); Modified: trunk/xmlunit/src/java/org/custommonkey/xmlunit/XMLUnit.java =================================================================== --- trunk/xmlunit/src/java/org/custommonkey/xmlunit/XMLUnit.java 2007-06-27 06:50:14 UTC (rev 218) +++ trunk/xmlunit/src/java/org/custommonkey/xmlunit/XMLUnit.java 2007-06-27 06:50:33 UTC (rev 219) @@ -397,6 +397,9 @@ public static TransformerFactory getTransformerFactory() { if (transformerFactory == null) { transformerFactory = TransformerFactory.newInstance(); + if (uriResolver != null) { + transformerFactory.setURIResolver(uriResolver); + } } return transformerFactory; } @@ -405,7 +408,11 @@ * Sets the URIResolver to use during transformations. */ public static void setURIResolver(URIResolver resolver) { - uriResolver = resolver; + if (uriResolver != resolver) { + uriResolver = resolver; + transformerFactory = null; + getTransformerFactory(); + } } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bo...@us...> - 2007-08-28 10:51:20
|
Revision: 231 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=231&view=rev Author: bodewig Date: 2007-08-28 03:51:17 -0700 (Tue, 28 Aug 2007) Log Message: ----------- Strip element content whitespace manually if using JDK 1.5's XSLTC, bug 1779701 Modified Paths: -------------- trunk/xmlunit/src/java/org/custommonkey/xmlunit/Diff.java trunk/xmlunit/src/java/org/custommonkey/xmlunit/XMLUnit.java trunk/xmlunit/src/java/org/custommonkey/xmlunit/XSLTConstants.java Modified: trunk/xmlunit/src/java/org/custommonkey/xmlunit/Diff.java =================================================================== --- trunk/xmlunit/src/java/org/custommonkey/xmlunit/Diff.java 2007-08-23 10:59:48 UTC (rev 230) +++ trunk/xmlunit/src/java/org/custommonkey/xmlunit/Diff.java 2007-08-28 10:51:17 UTC (rev 231) @@ -178,16 +178,9 @@ * differences ignore whitespace */ private Document getWhitespaceManipulatedDocument(Document originalDoc) { - if (!XMLUnit.getIgnoreWhitespace()) { - return originalDoc; - } - try { - Transform whitespaceStripper = XMLUnit.getStripWhitespaceTransform( - originalDoc); - return whitespaceStripper.getResultDocument(); - } catch (TransformerException e) { - throw new XMLUnitRuntimeException(e.getMessage(), e.getCause()); - } + return XMLUnit.getIgnoreWhitespace() + ? XMLUnit.getWhitespaceStrippedDocument(originalDoc) + : originalDoc; } /** Modified: trunk/xmlunit/src/java/org/custommonkey/xmlunit/XMLUnit.java =================================================================== --- trunk/xmlunit/src/java/org/custommonkey/xmlunit/XMLUnit.java 2007-08-23 10:59:48 UTC (rev 230) +++ trunk/xmlunit/src/java/org/custommonkey/xmlunit/XMLUnit.java 2007-08-28 10:51:17 UTC (rev 231) @@ -37,11 +37,13 @@ package org.custommonkey.xmlunit; import org.custommonkey.xmlunit.exceptions.ConfigurationException; +import org.custommonkey.xmlunit.exceptions.XMLUnitRuntimeException; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParserFactory; +import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerFactory; import javax.xml.transform.URIResolver; @@ -52,6 +54,8 @@ import java.text.ParseException; import java.util.Locale; import org.w3c.dom.Document; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; import org.xml.sax.InputSource; import org.xml.sax.SAXException; import org.xml.sax.EntityResolver; @@ -458,6 +462,54 @@ return new Transform(forDocument, getStripWhitespaceStylesheet()); } + /** + * Returns a new Document instance that is identical to the one + * passed in with element content whitespace removed. + * + * <p>Will use {@link #getStripWhitespaceTransform + * getStripWhitespaceTransform} unless we are operating under the + * severly broken XSLTC Transformer shipping with JDK 1.5.</p> + */ + public static Document getWhitespaceStrippedDocument(Document forDoc) { + String factory = getTransformerFactory().getClass().getName(); + if (XSLTConstants.JAVA5_XSLTC_FACTORY_NAME.equals(factory)) { + return stripWhiteSpaceWithoutXSLT(forDoc); + } else { + return stripWhiteSpaceUsingXSLT(forDoc); + } + } + + private static Document stripWhiteSpaceUsingXSLT(Document forDoc) { + try { + Transform whitespaceStripper = getStripWhitespaceTransform(forDoc); + return whitespaceStripper.getResultDocument(); + } catch (TransformerException e) { + throw new XMLUnitRuntimeException(e.getMessage(), e.getCause()); + } + } + + private static Document stripWhiteSpaceWithoutXSLT(Document forDoc) { + Document copy = (Document) forDoc.cloneNode(true); + stripEmptyTextNodes(copy); + return copy; + } + + private static void stripEmptyTextNodes(Node n) { + final NodeList nl = n.getChildNodes(); + for (int i = 0; i < nl.getLength(); i++) { + Node child = nl.item(i); + if (child.getNodeType() == Node.ELEMENT_NODE) { + stripEmptyTextNodes(child); + } else if (child.getNodeType() == Node.TEXT_NODE) { + String value = child.getNodeValue(); + if (value == null || value.trim().length() == 0) { + n.removeChild(child); + --i; + } + } + } + } + private static String getStripCommentsStylesheet() { return STRIP_COMMENTS_STYLESHEET_START + getXSLTVersion() + STRIP_COMMENTS_STYLESHEET_END; Modified: trunk/xmlunit/src/java/org/custommonkey/xmlunit/XSLTConstants.java =================================================================== --- trunk/xmlunit/src/java/org/custommonkey/xmlunit/XSLTConstants.java 2007-08-23 10:59:48 UTC (rev 230) +++ trunk/xmlunit/src/java/org/custommonkey/xmlunit/XSLTConstants.java 2007-08-28 10:51:17 UTC (rev 231) @@ -83,4 +83,11 @@ * </xsl:stylesheet> */ String XSLT_END = "</xsl:stylesheet>"; + + /** + * Factory class of the XSLTC version shipping with JDK 1.5 which + * is pretty broken. + */ + String JAVA5_XSLTC_FACTORY_NAME = + "com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl"; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bo...@us...> - 2008-06-06 14:16:30
|
Revision: 268 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=268&view=rev Author: bodewig Date: 2008-06-06 07:16:39 -0700 (Fri, 06 Jun 2008) Log Message: ----------- Try to get more information about the error if the XPath expression is invalid, Issue 1985229 Modified Paths: -------------- trunk/xmlunit/src/java/org/custommonkey/xmlunit/SimpleXpathEngine.java trunk/xmlunit/src/java/org/custommonkey/xmlunit/XMLUnit.java Modified: trunk/xmlunit/src/java/org/custommonkey/xmlunit/SimpleXpathEngine.java =================================================================== --- trunk/xmlunit/src/java/org/custommonkey/xmlunit/SimpleXpathEngine.java 2008-06-06 14:00:14 UTC (rev 267) +++ trunk/xmlunit/src/java/org/custommonkey/xmlunit/SimpleXpathEngine.java 2008-06-06 14:16:39 UTC (rev 268) @@ -42,9 +42,11 @@ import java.io.StringReader; import java.io.StringWriter; import java.util.Iterator; -import javax.xml.transform.Result; +import javax.xml.transform.ErrorListener; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.Result; import javax.xml.transform.dom.DOMResult; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; @@ -132,14 +134,31 @@ throws TransformerException, ConfigurationException, XpathException { try { StreamSource source = new StreamSource(new StringReader(xslt)); - Transformer transformer = - XMLUnit.getTransformerFactory().newTransformer(source); + TransformerFactory tf = XMLUnit.newTransformerFactory(); + ErrorListener el = new ErrorListener() { + public void error(TransformerException ex) + throws TransformerException { + // any error in our simple stylesheet must be fatal + throw ex; + } + public void fatalError(TransformerException ex) + throws TransformerException { + throw ex; + } + public void warning(TransformerException ex) { + // there shouldn't be any warning + ex.printStackTrace(); + } + }; + tf.setErrorListener(el); + Transformer transformer = tf.newTransformer(source); // Issue 1985229 says Xalan-J 2.7.0 may return null for // illegal input if (transformer == null) { throw new XpathException("failed to obtain an XSLT transformer" + " for XPath expression."); } + transformer.setErrorListener(el); transformer.transform(new DOMSource(document), result); } catch (javax.xml.transform.TransformerConfigurationException ex) { throw new ConfigurationException(ex); Modified: trunk/xmlunit/src/java/org/custommonkey/xmlunit/XMLUnit.java =================================================================== --- trunk/xmlunit/src/java/org/custommonkey/xmlunit/XMLUnit.java 2008-06-06 14:00:14 UTC (rev 267) +++ trunk/xmlunit/src/java/org/custommonkey/xmlunit/XMLUnit.java 2008-06-06 14:16:39 UTC (rev 268) @@ -402,15 +402,25 @@ */ public static TransformerFactory getTransformerFactory() { if (transformerFactory == null) { - transformerFactory = TransformerFactory.newInstance(); - if (uriResolver != null) { - transformerFactory.setURIResolver(uriResolver); - } + transformerFactory = newTransformerFactory(); } return transformerFactory; } /** + * Get a fresh transformer to use for XSLT transformations (and by + * implication serialization and XPaths). + * @return a new instance of the default transformer factory + */ + static TransformerFactory newTransformerFactory() { + TransformerFactory tf = TransformerFactory.newInstance(); + if (uriResolver != null) { + tf.setURIResolver(uriResolver); + } + return tf; + } + + /** * Sets the URIResolver to use during transformations. */ public static void setURIResolver(URIResolver resolver) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |