Top Description Inners Fields Constructors Methods
com.sun.xml.xsom.parser

public Class JAXPParser

extends Object
implements XMLParser
Class Inheritance
All Implemented Interfaces
com.sun.xml.xsom.parser.XMLParser
Imports
java.io.IOException, java.net.URL, java.util.logging.Level, .Logger, javax.xml.XMLConstants, javax.xml.parsers.ParserConfigurationException, .SAXParser, .SAXParserFactory, org.xml.sax.*, org.xml.sax.helpers.XMLFilterImpl, com.sun.xml.xsom.impl.parser.Messages

Standard XMLParser implemented by using JAXP.
Author
Kohsuke Kawaguchi ([email protected])

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
JAXPParser.XMLReaderEx

XMLReader with improved error message for entity resolution failure.

Field Summary

Modifier and TypeField and Description
private final SAXParserFactory
private static final Logger

Constructor Summary

AccessConstructor and Description
public
JAXPParser(SAXParserFactory factory)

Creates a new JAXPParser that uses the given SAXParserFactory for creating new XMLReaders.

Method Summary

Modifier and TypeMethod and Description
private static SAXParser
allowFileAccess(SAXParser saxParser, boolean disableSecureProcessing)

public void
parse(InputSource source, ContentHandler handler, ErrorHandler errorHandler, EntityResolver entityResolver)

Implements com.sun.xml.xsom.parser.XMLParser.parse.

Parses the document identified by the given input source and sends SAX events to the given content handler.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

factoryback to summary
private final SAXParserFactory factory
LOGGERback to summary
private static final Logger LOGGER

Constructor Detail

JAXPParserback to summary
public JAXPParser(SAXParserFactory factory)

Creates a new JAXPParser that uses the given SAXParserFactory for creating new XMLReaders.

The caller needs to configure it properly with security features initialized by setting XMLConstants.FEATURE_SECURE_PROCESSING feature. Also don't forget to call setNamespaceAware(true) or you'll see some strange errors.

Method Detail

allowFileAccessback to summary
private static SAXParser allowFileAccess(SAXParser saxParser, boolean disableSecureProcessing) throws SAXException
parseback to summary
public void parse(InputSource source, ContentHandler handler, ErrorHandler errorHandler, EntityResolver entityResolver) throws SAXException, IOException

Implements com.sun.xml.xsom.parser.XMLParser.parse.

Doc from com.sun.xml.xsom.parser.XMLParser.parse.

Parses the document identified by the given input source and sends SAX events to the given content handler.

This method must be re-entrant.

Exceptions
SAXException:
If ErrorHandler throws a SAXException, this method will tunnel it to the caller. All the other errors must be reported to the error handler.
com.sun.xml.xsom.parser back to summary

private Class JAXPParser.XMLReaderEx

extends XMLFilterImpl
Class Inheritance

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

Modifier and TypeField and Description
private Locator

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public InputSource
resolveEntity(String publicId, String systemId)

Overrides org.xml.sax.helpers.XMLFilterImpl.resolveEntity.

Implements org.xml.sax.EntityResolver.resolveEntity.

Resolves entities and reports user-friendly error messages.

public void
Inherited from org.xml.sax.helpers.XMLFilterImpl:
charactersendDocumentendElementendPrefixMappingerrorfatalErrorgetContentHandlergetDTDHandlergetEntityResolvergetErrorHandlergetFeaturegetParentgetPropertyignorableWhitespacenotationDeclparseparseprocessingInstructionsetContentHandlersetDTDHandlersetEntityResolversetErrorHandlersetFeaturesetParentsetPropertyskippedEntitystartDocumentstartElementstartPrefixMappingunparsedEntityDeclwarning

Field Detail

locatorback to summary
private Locator locator

Hides org.xml.sax.helpers.XMLFilterImpl.locator.

Constructor Detail

XMLReaderExback to summary
pack-priv XMLReaderEx(XMLReader parent)

Method Detail

resolveEntityback to summary
public InputSource resolveEntity(String publicId, String systemId) throws SAXException

Overrides org.xml.sax.helpers.XMLFilterImpl.resolveEntity.

Implements org.xml.sax.EntityResolver.resolveEntity.

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.

Annotations
@Override
Exceptions
SAXException:

Doc from org.xml.sax.helpers.XMLFilterImpl.resolveEntity.

The client may throw an exception during processing.

setDocumentLocatorback to summary
public void setDocumentLocator(Locator locator)

Overrides org.xml.sax.helpers.XMLFilterImpl.setDocumentLocator.

Implements org.xml.sax.ContentHandler.setDocumentLocator.

Doc from org.xml.sax.helpers.XMLFilterImpl.setDocumentLocator.

Filter a new document locator event.

Annotations
@Override