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