From 1dafbf63c9444302b8d6e6332a9276db1a69f31b Mon Sep 17 00:00:00 2001 From: ndw Date: Tue, 12 Apr 2005 21:02:54 +0000 Subject: [PATCH] Fix bug #16336 as suggested. git-svn-id: https://svn.apache.org/repos/asf/xml/commons/trunk@226194 13f79535-47bb-0310-9956-ffa450edef68 --- .../xml/resolver/tools/CatalogResolver.java | 45 +++++++++++++++++-- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/java/src/org/apache/xml/resolver/tools/CatalogResolver.java b/java/src/org/apache/xml/resolver/tools/CatalogResolver.java index a79d248..98eb1bb 100644 --- a/java/src/org/apache/xml/resolver/tools/CatalogResolver.java +++ b/java/src/org/apache/xml/resolver/tools/CatalogResolver.java @@ -298,15 +298,54 @@ public class CatalogResolver implements EntityResolver, URIResolver { } } - // if (!href.equals(result)) { - catalogManager.debug.message(2, "Resolved URI", href, result); - // } + catalogManager.debug.message(2, "Resolved URI", href, result); SAXSource source = new SAXSource(); source.setInputSource(new InputSource(result)); + setEntityResolver(source); return source; } + /** + *

Establish an entityResolver for newly resolved URIs.

+ * + *

This is called from the URIResolver to set an EntityResolver + * on the SAX parser to be used for new XML documents that are + * encountered as a result of the document() function, xsl:import, + * or xsl:include. This is done because the XSLT processor calls + * out to the SAXParserFactory itself to create a new SAXParser to + * parse the new document. The new parser does not automatically + * inherit the EntityResolver of the original (although arguably + * it should). See below:

+ * + * "If an application wants to set the ErrorHandler or + * EntityResolver for an XMLReader used during a transformation, + * it should use a URIResolver to return the SAXSource which + * provides (with getXMLReader) a reference to the XMLReader" + * + *

...quoted from page 118 of the Java API for XML + * Processing 1.1 specification

+ * + */ + private void setEntityResolver(SAXSource source) throws TransformerException { + XMLReader reader = source.getXMLReader(); + if (reader == null) { + SAXParserFactory spFactory = SAXParserFactory.newInstance(); + spFactory.setNamespaceAware(true); + try { + reader = spFactory.newSAXParser().getXMLReader(); + } + catch (ParserConfigurationException ex) { + throw new TransformerException(ex); + } + catch (SAXException ex) { + throw new TransformerException(ex); + } + } + reader.setEntityResolver(this); + source.setXMLReader(reader); + } + /** Attempt to construct an absolute URI */ private String makeAbsolute(String uri) { if (uri == null) {