From de3a669c71580d7fd8e750bda4f8fac3bf2d5bca Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Thu, 23 Oct 2003 08:43:22 +0000 Subject: [PATCH] Register xmlcatalog as entity resolver for the stylesheet as well git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@275548 13f79535-47bb-0310-9956-ffa450edef68 --- .../ant/taskdefs/optional/TraXLiaison.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/TraXLiaison.java b/src/main/org/apache/tools/ant/taskdefs/optional/TraXLiaison.java index 4d5feb7ad..8ef13138f 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/TraXLiaison.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/TraXLiaison.java @@ -64,6 +64,7 @@ import java.io.InputStream; import java.io.OutputStream; import java.util.Vector; import java.util.Enumeration; +import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParserFactory; import javax.xml.transform.ErrorListener; import javax.xml.transform.Source; @@ -86,6 +87,7 @@ import org.apache.tools.ant.types.XMLCatalog; import org.apache.tools.ant.util.JAXPUtils; import org.xml.sax.EntityResolver; import org.xml.sax.InputSource; +import org.xml.sax.SAXException; import org.xml.sax.XMLReader; /** @@ -199,7 +201,8 @@ public class TraXLiaison implements XSLTLiaison2, ErrorListener, XSLTLoggerAware * @return the configured source instance matching the stylesheet. * @throws Exception if there is a problem creating the source. */ - private Source getSource(InputStream is, File infile) throws Exception { + private Source getSource(InputStream is, File infile) + throws ParserConfigurationException, SAXException { // todo: is this comment still relevant ?? // FIXME: need to use a SAXSource as the source for the transform // so we can plug in our own entity resolver @@ -216,6 +219,8 @@ public class TraXLiaison implements XSLTLiaison2, ErrorListener, XSLTLoggerAware + "parser doesn't support SAX"); } } else { + // WARN: Don't use the StreamSource(File) ctor. It won't work with + // xalan prior to 2.2 because of systemid bugs. src = new StreamSource(is); } src.setSystemId(JAXPUtils.getSystemId(infile)); @@ -226,9 +231,8 @@ public class TraXLiaison implements XSLTLiaison2, ErrorListener, XSLTLoggerAware * Read in templates from the stylesheet */ private void readTemplates() - throws IOException, TransformerConfigurationException { - // WARN: Don't use the StreamSource(File) ctor. It won't work with - // xalan prior to 2.2 because of systemid bugs. + throws IOException, TransformerConfigurationException, + ParserConfigurationException, SAXException { // Use a stream so that you can close it yourself quickly // and avoid keeping the handle until the object is garbaged. @@ -239,10 +243,7 @@ public class TraXLiaison implements XSLTLiaison2, ErrorListener, XSLTLoggerAware xslStream = new BufferedInputStream(new FileInputStream(stylesheet)); templatesModTime = stylesheet.lastModified(); - StreamSource src = new StreamSource(xslStream); - // Always set the systemid to the source for imports, includes... - // in xsl and xml... - src.setSystemId(JAXPUtils.getSystemId(stylesheet)); + Source src = getSource(xslStream, stylesheet); templates = getFactory().newTemplates(src); } finally { if (xslStream != null) {