Hello Andrew,

You're registering the CatalogResolver with a TransformerFactory. It looks 
like Xalan does not propagate this resolver to the parser instances it 
creates (and I'm not sure that it should). You could try passing in a 
SAXSource instead and explicitly set the entity resolver on the XMLReader 
to be the CatalogResolver.

Thanks.

Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: [EMAIL PROTECTED]
E-mail: [EMAIL PROTECTED]

"Andrew Stevens" <[EMAIL PROTECTED]> wrote on 06/22/2006 12:52:30 PM:

> Hi,
> 
> I'm not entirely certain this is a xerces problem, but since the top 
part of 
> my stack trace is xerces classes I thought I'd try here first.  Let me 
know 
> if it's more likely one of the other components that's the problem, and 
I'll 
> go hassle them :-)
> 
> I have a servlet which runs an XSL transformation (stylesheet read from 
a 
> file) on an XML document held in a string.  The document's doctype 
includes 
> public & system IDs, but the URL in the system ID doesn't exist (yet) so 
I'm 
> using the Apache XML Commons catalog entity resolver to substitute a 
local 
> copy of the DTD.  At least, that's the theory.
> 
> I know the catalog manager is finding its configuration file okay (the 
log 
> shows messages resolving the URIs it contains to absolute paths) and the 

> resolved path is the location of my DTD.  However, when the transform 
runs, 
> I get an exception that seems to be because it's trying to access the 
> original (http) systemId instead of using the local copy.  I don't see 
any 
> messages from the resolver in the log to suggest that it's even been 
called 
> upon to resolve the DTD location.
> 
> The code I'm using is
> 
> URL xslUrl = MyServlet.class.getResource(XSL_STYLESHEET);
> InputStream xslIn = MyServlet.class.getResourceAsStream(XSL_STYLESHEET);
> DOMResult domOut = new DOMResult();
> TransformerFactory factory = TransformerFactory.newInstance();
> factory.setURIResolver(new CatalogResolver());
> Transformer stylesheet = factory.newTransformer(new StreamSource(xslIn, 
> xslUrl.toExternalForm()));
> stylesheet.transform(new StreamSource(new StringReader(xml)), domOut);
> 
> the document is
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <!DOCTYPE data PUBLIC "-//FOOBAR/DTD My Data 1.0//EN" 
> "http://internal.host/dtd/data-1.0.dtd";>
> <data>
>    <point x="0" y="0" size="5"/>
>    <point x="10" y="20" size="10"/>
>    <point x="20" y="40" size="2"/>
> </data>
> 
> and the log file contains
> 
> Parse catalog: file:/C:/app/build/web/WEB-INF/catalog.xml
> Loading catalog: file:/C:/app/build/web/WEB-INF/catalog.xml
> Default BASE: file:/C:/app/build/web/WEB-INF/catalog.xml
> public: -//FOOBAR/DTD My Data 1.0//EN
>    ../dtd/data-1.0.dtd
> PUBLIC: -//FOOBAR/DTD My Data 1.0//EN
>    file:/C:/app/build/web/dtd/data-1.0.dtd
> system: http://internal.host/dtd/data-1.0.dtd
>    ../dtd/data-1.0.dtd
> SYSTEM: http://internal.host/dtd/data-1.0.dtd
>    file:/C:/app/build/web/dtd/data-1.0.dtd
> [ERROR] TransformerException:java.io.FileNotFoundException: 
> http://internal.host/dtd/data-1.0.dtd
> javax.xml.transform.TransformerException: java.io.FileNotFoundException: 

> http://internal.host/dtd/data-1.0.dtd
>    at 
> org.apache.xalan.transformer.TransformerImpl.
> fatalError(TransformerImpl.java:741)
>    at 
> org.apache.xalan.transformer.TransformerImpl.
> transform(TransformerImpl.java:715)
>    at 
> org.apache.xalan.transformer.TransformerImpl.
> transform(TransformerImpl.java:1129)
>    at 
> org.apache.xalan.transformer.TransformerImpl.
> transform(TransformerImpl.java:1107)
>    at com.foobar.MyServlet.processRequest(MyServlet.java:86)
>    at com.foobar.MyServlet.doPost(MyServlet.java:203)
> ...
> Caused by: java.io.FileNotFoundException: 
> http://internal.host/dtd/data-1.0.dtd
>    at 
> sun.net.www.protocol.http.HttpURLConnection.
> getInputStream(HttpURLConnection.java:798)
>    at org.apache.xerces.impl.XMLEntityManager.setupCurrentEntity(Unknown 

> Source)
>    at org.apache.xerces.impl.XMLEntityManager.startEntity(Unknown 
Source)
>    at org.apache.xerces.impl.XMLEntityManager.startDTDEntity(Unknown 
Source)
>    at org.apache.xerces.impl.XMLDTDScannerImpl.setInputSource(Unknown 
Source)
>    at 
> 
org.apache.xerces.impl.XMLDocumentScannerImpl$DTDDispatcher.dispatch(Unknown 

> Source)
>    at 
> 
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown 

> Source)
>    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
>    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
>    at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
>    at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
>    at 
> 
org.apache.xml.dtm.ref.DTMManagerDefault.getDTM(DTMManagerDefault.java:495)
>    at 
> org.apache.xalan.transformer.TransformerImpl.
> transform(TransformerImpl.java:658)
>    ... 20 more
> java.io.FileNotFoundException: http://internal.host/dtd/data-1.0.dtd
>    at 
> sun.net.www.protocol.http.HttpURLConnection.
> getInputStream(HttpURLConnection.java:798)
>    at org.apache.xerces.impl.XMLEntityManager.setupCurrentEntity(Unknown 

> Source)
>    at org.apache.xerces.impl.XMLEntityManager.startEntity(Unknown 
Source)
>    at org.apache.xerces.impl.XMLEntityManager.startDTDEntity(Unknown 
Source)
>    at org.apache.xerces.impl.XMLDTDScannerImpl.setInputSource(Unknown 
Source)
>    at 
> 
org.apache.xerces.impl.XMLDocumentScannerImpl$DTDDispatcher.dispatch(Unknown 

> Source)
>    at 
> 
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown 

> Source)
>    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
>    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
>    at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
>    at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
>    at 
> 
org.apache.xml.dtm.ref.DTMManagerDefault.getDTM(DTMManagerDefault.java:495)
>    at 
> org.apache.xalan.transformer.TransformerImpl.
> transform(TransformerImpl.java:658)
>    at 
> org.apache.xalan.transformer.TransformerImpl.
> transform(TransformerImpl.java:1129)
>    at 
> org.apache.xalan.transformer.TransformerImpl.
> transform(TransformerImpl.java:1107)
>    at com.foobar.MyServlet.processRequest(MyServlet.java:86)
>    at com.foobar.MyServlet.doPost(MyServlet.java:203)
> 
> If I use some string manipulation to remove the doctype's public & 
system 
> IDs before passing the string on to the transform (i.e. leaving just 
> <!DOCTYPE data>) then it works fine.
> 
> Any suggestions?  Is there something wrong with my code, or is it a 
> xerces/xalan/entityresolver bug?
> 
> Thanks for any help,
> 
> 
> Andrew.
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to