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. |