Class JAXPParser.XMLReaderEx

  • All Implemented Interfaces:
    org.xml.sax.ContentHandler, org.xml.sax.DTDHandler, org.xml.sax.EntityResolver, org.xml.sax.ErrorHandler, org.xml.sax.XMLFilter, org.xml.sax.XMLReader
    Enclosing class:
    JAXPParser

    private static class JAXPParser.XMLReaderEx
    extends org.xml.sax.helpers.XMLFilterImpl
    XMLReader with improved error message for entity resolution failure. TODO: this class is completely stand-alone, so it shouldn't be an inner class.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private org.xml.sax.Locator locator  
    • Constructor Summary

      Constructors 
      Constructor Description
      XMLReaderEx​(org.xml.sax.XMLReader parent)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method 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)  
      • Methods inherited from class org.xml.sax.helpers.XMLFilterImpl

        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, warning
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • locator

        private org.xml.sax.Locator locator
    • Constructor Detail

      • XMLReaderEx

        XMLReaderEx​(org.xml.sax.XMLReader parent)
    • Method Detail

      • resolveEntity

        public org.xml.sax.InputSource resolveEntity​(java.lang.String publicId,
                                                     java.lang.String systemId)
                                              throws org.xml.sax.SAXException
        Resolves entities and reports user-friendly error messages.

        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.

        Specified by:
        resolveEntity in interface org.xml.sax.EntityResolver
        Overrides:
        resolveEntity in class org.xml.sax.helpers.XMLFilterImpl
        Throws:
        org.xml.sax.SAXException
      • setDocumentLocator

        public void setDocumentLocator​(org.xml.sax.Locator locator)
        Specified by:
        setDocumentLocator in interface org.xml.sax.ContentHandler
        Overrides:
        setDocumentLocator in class org.xml.sax.helpers.XMLFilterImpl