You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commons-cvs@xml.apache.org by nd...@apache.org on 2005/04/12 23:02:54 UTC
cvs commit: xml-commons/java/src/org/apache/xml/resolver/tools CatalogResolver.java
ndw 2005/04/12 14:02:54
Modified: java/src/org/apache/xml/resolver/tools CatalogResolver.java
Log:
Fix bug #16336 as suggested.
Revision Changes Path
1.6 +42 -3 xml-commons/java/src/org/apache/xml/resolver/tools/CatalogResolver.java
Index: CatalogResolver.java
===================================================================
RCS file: /home/cvs/xml-commons/java/src/org/apache/xml/resolver/tools/CatalogResolver.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- CatalogResolver.java 2 Sep 2003 07:05:08 -0000 1.5
+++ CatalogResolver.java 12 Apr 2005 21:02:54 -0000 1.6
@@ -298,15 +298,54 @@
}
}
- // 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;
}
+ /**
+ * <p>Establish an entityResolver for newly resolved URIs.</p>
+ *
+ * <p>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:</p>
+ *
+ * <tt>"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"</tt>
+ *
+ * <p>...quoted from page 118 of the Java API for XML
+ * Processing 1.1 specification</p>
+ *
+ */
+ 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) {