From: <bo...@us...> - 2010-04-29 06:44:48
|
Revision: 363 http://xmlunit.svn.sourceforge.net/xmlunit/?rev=363&view=rev Author: bodewig Date: 2010-04-29 06:44:42 +0000 (Thu, 29 Apr 2010) Log Message: ----------- docs - and don't hard code Source implementations SAXSource can deal with Modified Paths: -------------- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/util/Convert.java trunk/xmlunit/src/main/java-core/net/sf/xmlunit/xpath/XPathEngine.java Modified: trunk/xmlunit/src/main/java-core/net/sf/xmlunit/util/Convert.java =================================================================== --- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/util/Convert.java 2010-04-29 06:14:31 UTC (rev 362) +++ trunk/xmlunit/src/main/java-core/net/sf/xmlunit/util/Convert.java 2010-04-29 06:44:42 UTC (rev 363) @@ -25,12 +25,22 @@ import net.sf.xmlunit.exceptions.XMLUnitException; import org.xml.sax.InputSource; +/** + * Conversion methods. + */ public final class Convert { private Convert() { } + /** + * Creates a SAX InputSource from a TraX Source. + * + * <p>May use an XSLT identity transformation if SAXSource cannot + * convert it directly.</p> + */ public static InputSource toInputSource(Source s) { try { - if (!(s instanceof SAXSource) && !(s instanceof StreamSource)) { + InputSource is = SAXSource.sourceToInputSource(s); + if (is == null) { ByteArrayOutputStream bos = new ByteArrayOutputStream(); StreamResult r = new StreamResult(bos); TransformerFactory fac = TransformerFactory.newInstance(); @@ -38,8 +48,9 @@ t.transform(s, r); s = new StreamSource(new ByteArrayInputStream(bos .toByteArray())); + is = SAXSource.sourceToInputSource(s); } - return SAXSource.sourceToInputSource(s); + return is; } catch (javax.xml.transform.TransformerConfigurationException e) { throw new ConfigurationException(e); } catch (javax.xml.transform.TransformerException e) { Modified: trunk/xmlunit/src/main/java-core/net/sf/xmlunit/xpath/XPathEngine.java =================================================================== --- trunk/xmlunit/src/main/java-core/net/sf/xmlunit/xpath/XPathEngine.java 2010-04-29 06:14:31 UTC (rev 362) +++ trunk/xmlunit/src/main/java-core/net/sf/xmlunit/xpath/XPathEngine.java 2010-04-29 06:44:42 UTC (rev 363) @@ -31,6 +31,9 @@ import org.w3c.dom.Node; import org.w3c.dom.NodeList; +/** + * Simplified access to JAXP's XPath API. + */ public class XPathEngine { private final XPath xpath; @@ -42,10 +45,18 @@ } } + /** + * Create an XPathEngine that uses JAXP's default XPathFactory + * under the covers. + */ public XPathEngine() { this(XPathFactory.newInstance()); } + /** + * Returns a potentially empty collection of Nodes matching an + * XPath expression. + */ public Iterable<Node> selectNodes(String xPath, Source s) { try { NodeList nl = (NodeList) xpath.evaluate(xPath, @@ -57,6 +68,9 @@ } } + /** + * Evaluates an XPath expression and stringifies the result. + */ public String evaluate(String xPath, Source s) { try { return xpath.evaluate(xPath, Convert.toInputSource(s)); @@ -65,6 +79,11 @@ } } + /** + * Establish a namespace context. + * + * @param prefix2Uri maps from prefix to namespace URI. + */ public void setNamespaceContext(Map<String, String> prefix2Uri) { xpath.setNamespaceContext(new NC(prefix2Uri)); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |