Bug 16336 - URIResolver needs to set an EntityResolver on the SAX parser to be used for new XML documents
Summary: URIResolver needs to set an EntityResolver on the SAX parser to be used for n...
Status: RESOLVED FIXED
Alias: None
Product: XmlCommons - Now in JIRA
Classification: Unclassified
Component: Resolver (show other bugs)
Version: 1.x
Hardware: PC All
: P3 normal (vote)
Target Milestone: ---
Assignee: Commons Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-01-22 16:40 UTC by Ella Belisario
Modified: 2005-04-12 15:03 UTC (History)
0 users



Attachments
Test case for CatalogResolver, unzip, set class path in runtest.bat and run (19.03 KB, application/octet-stream)
2003-01-22 16:46 UTC, Ella Belisario
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Ella Belisario 2003-01-22 16:40:23 UTC
CatalogResolver.resolve(String href, String base) needs to set 
EntityResolver to the resulted input source in order entities be resolved in 
the new XML documents:
    SAXSource source = new SAXSource();
    source.setInputSource(new InputSource(result));
    setEntityResolver(source);
    return source;

    /**
     * <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);
    }

I'll attach a test case to show that the current CatalogResolver does not 
resolve entity in the xml file which was created with the document() function 
in xsl file
Comment 1 Ella Belisario 2003-01-22 16:46:40 UTC
Created attachment 4513 [details]
Test case for CatalogResolver, unzip, set class path in runtest.bat and run
Comment 2 Norman Walsh 2005-04-12 23:03:02 UTC
Thanks!