Bug 31317 - EntityResolver not called uniformly
Summary: EntityResolver not called uniformly
Status: NEW
Alias: None
Product: Xerces-J
Classification: Unclassified
Component: Core (show other bugs)
Version: 1.4.4
Hardware: All Solaris
: P3 major
Target Milestone: ---
Assignee: Xerces-J Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-09-20 19:34 UTC by justin
Modified: 2004-11-16 19:05 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description justin 2004-09-20 19:34:42 UTC
The EntityResolver set on XMLReader via XMLReader.setEntityResolver(ER) is
sometimes called and sometimes not called depending on the format of the URI for
the DTD.

I am trying to use my entity resolver to load the DTD out of the classpath.

However, my Entity Resolver, ER is not always called.  The behavior seems to
depend on the format of the URI.  If the parser thinks it knows how to resolve
the URI then it does not call the entity resolver and instead tries to use some
default resolver (which cant find the DTD since i'm loading it out of the
classpath).

For example:

These entities will try to use the default resolver
 <!DOCTYPE Modules SYSTEM "MatchingEngineEngineConfig.dtd">
 <!DOCTYPE Modules SYSTEM "justin:MatchingEngineEngineConfig.dtd">
 <!DOCTYPE Modules SYSTEM "classpath:MatchingEngineEngineConfig.dtd">

However these entities will use the custom resolver.
 <!DOCTYPE Modules SYSTEM "file://MatchingEngineEngineConfig.dtd">

I see 1 bug, and one missing feature here:
 1) The javadoc for XMLReader.setEntityResolver() needs to be updated
    to specify this behavior.  I would like to know specifically when
    the custom entity resolver will be called and when it wont.

 2) There should be some way to FORCE the parser to use the entity resolver
    no matter what.  This behavior is intimately coupled with using the 
    XMLReader.parse(InputSource) method instead of using the 
    XMLReader.parse(systemID) method.  There should be a method:

              XMLReader.parse(InputSource, EntityResolver) 

    since when you are using an input source you have some reason 
    to avoid the nomral file system mechanisms.
    (i.e. you have XML and DTDs in a database or an encrypted jar file).

---[ code snippet : getting and configuring the reader ]----------

XMLContentHandler handler = new XMLContentHandler();
XMLReader reader = null;
SAXParserFactory factory = javax.xml.parsers.SAXParserFactory.newInstance();
SAXParser parser = factory.newSAXParser();
reader = parser.getXMLReader();
reader.setFeature("http://xml.org/sax/features/validation", true);
reader.setContentHandler(handler);
reader.setDTDHandler(handler);
reader.setEntityResolver(new ClasspathDTDResolver("com/mycorp/mypackage"));
reader.setErrorHandler(handler);

InputStream xmlInputStream=getClass().getClassLoader().getResourceAsStream(xmlFile);
reader.parse(new InputSource(xmlInputStream));

------------------------