Class AbstractSAXParser

All Implemented Interfaces:
XMLDocumentHandler, XMLReader
Direct Known Subclasses:
SAXParser

public abstract class AbstractSAXParser extends AbstractXMLDocumentParser implements XMLReader
This is the base class of all SAX parsers. It implements both the SAX1 and SAX2 parser functionality, while the actual pipeline is defined in the parser configuration.
  • Field Details

    • NAMESPACES

      protected static final String NAMESPACES
      Feature identifier: namespaces.
      See Also:
    • RECOGNIZED_FEATURES

      private static final String[] RECOGNIZED_FEATURES
      Recognized features.
    • LEXICAL_HANDLER

      protected static final String LEXICAL_HANDLER
      Property id: lexical handler.
      See Also:
    • RECOGNIZED_PROPERTIES

      private static final String[] RECOGNIZED_PROPERTIES
      Recognized properties.
    • fNamespaces

      protected boolean fNamespaces
      Namespaces.
    • fNamespacePrefixes

      protected boolean fNamespacePrefixes
      Namespace prefixes.
    • fLexicalHandlerParameterEntities

      protected boolean fLexicalHandlerParameterEntities
      Lexical handler parameter entities.
    • fStandalone

      protected boolean fStandalone
      Standalone document declaration.
    • fUseEntityResolver2

      protected boolean fUseEntityResolver2
      Use EntityResolver2.
    • fContentHandler

      protected ContentHandler fContentHandler
      Content handler.
    • fNamespaceContext

      protected NamespaceContext fNamespaceContext
      Namespace context
    • fDTDHandler

      protected DTDHandler fDTDHandler
      DTD handler.
    • fLexicalHandler

      protected LexicalHandler fLexicalHandler
      Lexical handler.
    • fVersion

      protected String fVersion
    • fAttributesProxy

      private final AbstractSAXParser.AttributesProxy fAttributesProxy
  • Constructor Details

  • Method Details

    • startDocument

      public void startDocument(XMLLocator locator, String encoding, NamespaceContext namespaceContext, Augmentations augs) throws XNIException
      The start of the document.
      Specified by:
      startDocument in interface XMLDocumentHandler
      Overrides:
      startDocument in class AbstractXMLDocumentParser
      Parameters:
      locator - The document locator, or null if the document location cannot be reported during the parsing of this document. However, it is strongly recommended that a locator be supplied that can at least report the system identifier of the document.
      encoding - The auto-detected IANA encoding name of the entity stream. This value will be null in those situations where the entity encoding is not auto-detected (e.g. internal entities or a document entity that is parsed from a java.io.Reader).
      namespaceContext - The namespace context in effect at the start of this document. This object represents the current context. Implementors of this class are responsible for copying the namespace bindings from the the current context (and its parent contexts) if that information is important.
      augs - Additional information that may include infoset augmentations
      Throws:
      XNIException - Thrown by handler to signal an error.
    • xmlDecl

      public void xmlDecl(String version, String encoding, String standalone, Augmentations augs) throws XNIException
      Notifies of the presence of an XMLDecl line in the document. If present, this method will be called immediately following the startDocument call.
      Specified by:
      xmlDecl in interface XMLDocumentHandler
      Overrides:
      xmlDecl in class AbstractXMLDocumentParser
      Parameters:
      version - The XML version.
      encoding - The IANA encoding name of the document, or null if not specified.
      standalone - The standalone value, or null if not specified.
      augs - Additional information that may include infoset augmentations
      Throws:
      XNIException - Thrown by handler to signal an error.
    • doctypeDecl

      public void doctypeDecl(String rootElement, String publicId, String systemId, Augmentations augs) throws XNIException
      Notifies of the presence of the DOCTYPE line in the document.
      Specified by:
      doctypeDecl in interface XMLDocumentHandler
      Overrides:
      doctypeDecl in class AbstractXMLDocumentParser
      Parameters:
      rootElement - The name of the root element.
      publicId - The public identifier if an external DTD or null if the external DTD is specified using SYSTEM.
      systemId - The system identifier if an external DTD, null otherwise.
      augs - Additional information that may include infoset augmentations
      Throws:
      XNIException - Thrown by handler to signal an error.
    • startElement

      public void startElement(QName element, XMLAttributes attributes, Augmentations augs) throws XNIException
      The start of an element. If the document specifies the start element by using an empty tag, then the startElement method will immediately be followed by the endElement method, with no intervening methods.
      Specified by:
      startElement in interface XMLDocumentHandler
      Overrides:
      startElement in class AbstractXMLDocumentParser
      Parameters:
      element - The name of the element.
      attributes - The element attributes.
      augs - Additional information that may include infoset augmentations
      Throws:
      XNIException - Thrown by handler to signal an error.
    • characters

      public void characters(XMLString text, Augmentations augs) throws XNIException
      Character content.
      Specified by:
      characters in interface XMLDocumentHandler
      Overrides:
      characters in class AbstractXMLDocumentParser
      Parameters:
      text - The content.
      augs - Additional information that may include infoset augmentations
      Throws:
      XNIException - Thrown by handler to signal an error.
    • endElement

      public void endElement(QName element, Augmentations augs) throws XNIException
      The end of an element.
      Specified by:
      endElement in interface XMLDocumentHandler
      Overrides:
      endElement in class AbstractXMLDocumentParser
      Parameters:
      element - The name of the element.
      augs - Additional information that may include infoset augmentations
      Throws:
      XNIException - Thrown by handler to signal an error.
    • startCDATA

      public void startCDATA(Augmentations augs) throws XNIException
      The start of a CDATA section.
      Specified by:
      startCDATA in interface XMLDocumentHandler
      Overrides:
      startCDATA in class AbstractXMLDocumentParser
      Parameters:
      augs - Additional information that may include infoset augmentations
      Throws:
      XNIException - Thrown by handler to signal an error.
    • endCDATA

      public void endCDATA(Augmentations augs) throws XNIException
      The end of a CDATA section.
      Specified by:
      endCDATA in interface XMLDocumentHandler
      Overrides:
      endCDATA in class AbstractXMLDocumentParser
      Parameters:
      augs - Additional information that may include infoset augmentations
      Throws:
      XNIException - Thrown by handler to signal an error.
    • comment

      public void comment(XMLString text, Augmentations augs) throws XNIException
      A comment.
      Specified by:
      comment in interface XMLDocumentHandler
      Overrides:
      comment in class AbstractXMLDocumentParser
      Parameters:
      text - The text in the comment.
      augs - Additional information that may include infoset augmentations
      Throws:
      XNIException - Thrown by application to signal an error.
    • processingInstruction

      public void processingInstruction(String target, XMLString data, Augmentations augs) throws XNIException
      A processing instruction. Processing instructions consist of a target name and, optionally, text data. The data is only meaningful to the application.

      Typically, a processing instruction's data will contain a series of pseudo-attributes. These pseudo-attributes follow the form of element attributes but are not parsed or presented to the application as anything other than text. The application is responsible for parsing the data.

      Specified by:
      processingInstruction in interface XMLDocumentHandler
      Overrides:
      processingInstruction in class AbstractXMLDocumentParser
      Parameters:
      target - The target.
      data - The data or null if none specified.
      augs - Additional information that may include infoset augmentations
      Throws:
      XNIException - Thrown by handler to signal an error.
    • endDocument

      public void endDocument(Augmentations augs) throws XNIException
      The end of the document.
      Specified by:
      endDocument in interface XMLDocumentHandler
      Overrides:
      endDocument in class AbstractXMLDocumentParser
      Parameters:
      augs - Additional information that may include infoset augmentations
      Throws:
      XNIException - Thrown by handler to signal an error.
    • parse

      public void parse(String systemId) throws SAXException, IOException
      Parses the input source specified by the given system identifier.

      This method is equivalent to the following:

       parse(new InputSource(systemId));
       
      Specified by:
      parse in interface XMLReader
      Parameters:
      systemId - The system identifier (URI).
      Throws:
      SAXException - Throws exception on SAX error.
      IOException - Throws exception on i/o error.
    • parse

      public void parse(InputSource inputSource) throws SAXException, IOException
      Specified by:
      parse in interface XMLReader
      Throws:
      SAXException
      IOException
    • setEntityResolver

      public void setEntityResolver(EntityResolver resolver)
      Specified by:
      setEntityResolver in interface XMLReader
    • getEntityResolver

      public EntityResolver getEntityResolver()
      Return the current entity resolver.
      Specified by:
      getEntityResolver in interface XMLReader
      Returns:
      The current entity resolver, or null if none has been registered.
      See Also:
    • setErrorHandler

      public void setErrorHandler(ErrorHandler errorHandler)
      Allow an application to register an error event handler.

      If the application does not register an error handler, all error events reported by the SAX parser will be silently ignored; however, normal processing may not continue. It is highly recommended that all SAX applications implement an error handler to avoid unexpected bugs.

      Applications may register a new or different handler in the middle of a parse, and the SAX parser must begin using the new handler immediately.

      Specified by:
      setErrorHandler in interface XMLReader
      Parameters:
      errorHandler - The error handler.
      See Also:
    • getErrorHandler

      public ErrorHandler getErrorHandler()
      Return the current error handler.
      Specified by:
      getErrorHandler in interface XMLReader
      Returns:
      The current error handler, or null if none has been registered.
      See Also:
    • setDTDHandler

      public void setDTDHandler(DTDHandler dtdHandler)
      Allow an application to register a DTD event handler.

      If the application does not register a DTD handler, all DTD events reported by the SAX parser will be silently ignored.

      Applications may register a new or different handler in the middle of a parse, and the SAX parser must begin using the new handler immediately.

      Specified by:
      setDTDHandler in interface XMLReader
      Parameters:
      dtdHandler - The DTD handler.
      See Also:
    • setContentHandler

      public void setContentHandler(ContentHandler contentHandler)
      Allow an application to register a content event handler.

      If the application does not register a content handler, all content events reported by the SAX parser will be silently ignored.

      Applications may register a new or different handler in the middle of a parse, and the SAX parser must begin using the new handler immediately.

      Specified by:
      setContentHandler in interface XMLReader
      Parameters:
      contentHandler - The content handler.
      See Also:
    • getContentHandler

      public ContentHandler getContentHandler()
      Return the current content handler.
      Specified by:
      getContentHandler in interface XMLReader
      Returns:
      The current content handler, or null if none has been registered.
      See Also:
    • getDTDHandler

      public DTDHandler getDTDHandler()
      Return the current DTD handler.
      Specified by:
      getDTDHandler in interface XMLReader
      Returns:
      The current DTD handler, or null if none has been registered.
      See Also:
    • setFeature

      public void setFeature(String featureId, boolean state) throws SAXNotRecognizedException, SAXNotSupportedException
      Set the state of any feature in a SAX2 parser. The parser might not recognize the feature, and if it does recognize it, it might not be able to fulfill the request.
      Specified by:
      setFeature in interface XMLReader
      Parameters:
      featureId - The unique identifier (URI) of the feature.
      state - The requested state of the feature (true or false).
      Throws:
      SAXNotRecognizedException - If the requested feature is not known.
      SAXNotSupportedException - If the requested feature is known, but the requested state is not supported.
    • getFeature

      public boolean getFeature(String featureId) throws SAXNotRecognizedException, SAXNotSupportedException
      Query the state of a feature.

      Query the current state of any feature in a SAX2 parser. The parser might not recognize the feature.

      Specified by:
      getFeature in interface XMLReader
      Parameters:
      featureId - The unique identifier (URI) of the feature being set.
      Returns:
      The current state of the feature.
      Throws:
      SAXNotRecognizedException - If the requested feature is not known.
      SAXNotSupportedException - If the requested feature is known but not supported.
    • setProperty

      public void setProperty(String propertyId, Object value) throws SAXNotRecognizedException, SAXNotSupportedException
      Set the value of any property in a SAX2 parser. The parser might not recognize the property, and if it does recognize it, it might not support the requested value.
      Specified by:
      setProperty in interface XMLReader
      Parameters:
      propertyId - The unique identifier (URI) of the property being set.
      value - The value to which the property is being set.
      Throws:
      SAXNotRecognizedException - If the requested property is not known.
      SAXNotSupportedException - If the requested property is known, but the requested value is not supported.
    • getProperty

      public Object getProperty(String propertyId) throws SAXNotRecognizedException, SAXNotSupportedException
      Query the value of a property.

      Return the current value of a property in a SAX2 parser. The parser might not recognize the property.

      Specified by:
      getProperty in interface XMLReader
      Parameters:
      propertyId - The unique identifier (URI) of the property being set.
      Returns:
      The current value of the property.
      Throws:
      SAXNotRecognizedException - If the requested property is not known.
      SAXNotSupportedException - If the requested property is known but not supported.
    • setLexicalHandler

      protected void setLexicalHandler(LexicalHandler handler) throws SAXNotSupportedException
      Set the lexical event handler.

      This method is the equivalent to the property:

       http://xml.org/sax/properties/lexical-handler
       
      Parameters:
      handler - lexical event handler
      Throws:
      SAXNotSupportedException - on error
      See Also:
    • getLexicalHandler

      protected LexicalHandler getLexicalHandler()
      Returns:
      the lexical handler.
      See Also:
    • startNamespaceMapping

      protected final void startNamespaceMapping() throws SAXException
      Send startPrefixMapping events
      Throws:
      SAXException - on error
    • endNamespaceMapping

      protected final void endNamespaceMapping() throws SAXException
      Send endPrefixMapping events
      Throws:
      SAXException - on error
    • reset

      public void reset() throws XNIException
      Reset all components before parsing.
      Overrides:
      reset in class XMLParser
      Throws:
      XNIException - Thrown if an error occurs during initialization.