private static class JAXPParser.XMLReaderEx
extends org.xml.sax.helpers.XMLFilterImpl
| Modifier and Type | Field and Description |
|---|---|
private org.xml.sax.Locator |
locator |
| Constructor and Description |
|---|
XMLReaderEx(org.xml.sax.XMLReader parent) |
| Modifier and Type | Method and Description |
|---|---|
org.xml.sax.InputSource |
resolveEntity(java.lang.String publicId,
java.lang.String systemId)
Resolves entities and reports user-friendly error messages.
|
void |
setDocumentLocator(org.xml.sax.Locator locator) |
characters, endDocument, endElement, endPrefixMapping, error, fatalError, getContentHandler, getDTDHandler, getEntityResolver, getErrorHandler, getFeature, getParent, getProperty, ignorableWhitespace, notationDecl, parse, parse, processingInstruction, setContentHandler, setDTDHandler, setEntityResolver, setErrorHandler, setFeature, setParent, setProperty, skippedEntity, startDocument, startElement, startPrefixMapping, unparsedEntityDecl, warningpublic org.xml.sax.InputSource resolveEntity(java.lang.String publicId,
java.lang.String systemId)
throws org.xml.sax.SAXException
Some XML parser (at least Xerces) does not report much information when it fails to resolve an entity, which is often quite frustrating. For example, if you are behind a firewall and the schema contains a reference to www.w3.org, and there is no entity resolver, the parser will just throw an IOException that doesn't contain any information about where that reference occurs nor what it is accessing.
By implementing an EntityResolver and resolving the reference by ourselves, we can report an error message with all the necessary information to fix the problem.
Note that we still need to the client-specified entity resolver to let the application handle entity resolution. Here we just catch an IOException and add more information.
resolveEntity in interface org.xml.sax.EntityResolverresolveEntity in class org.xml.sax.helpers.XMLFilterImplorg.xml.sax.SAXExceptionpublic void setDocumentLocator(org.xml.sax.Locator locator)
setDocumentLocator in interface org.xml.sax.ContentHandlersetDocumentLocator in class org.xml.sax.helpers.XMLFilterImpl