Class BasicParserConfiguration

java.lang.Object
org.apache.xerces.util.ParserConfigurationSettings
org.apache.xerces.parsers.BasicParserConfiguration
All Implemented Interfaces:
org.apache.xerces.xni.parser.XMLComponentManager, org.apache.xerces.xni.parser.XMLParserConfiguration
Direct Known Subclasses:
DTDConfiguration, NonValidatingConfiguration, SchemaParsingConfig

public abstract class BasicParserConfiguration extends ParserConfigurationSettings implements org.apache.xerces.xni.parser.XMLParserConfiguration
A very basic parser configuration. This configuration class can be used as a base class for custom parser configurations. The basic parser configuration creates the symbol table (if not specified at construction time) and manages all of the recognized features and properties.

The basic parser configuration does not mandate any particular pipeline configuration or the use of specific components except for the symbol table. If even this is too much for a basic parser configuration, the programmer can create a new configuration class that implements the XMLParserConfiguration interface.

Subclasses of the basic parser configuration can add their own recognized features and properties by calling the addRecognizedFeature and addRecognizedProperty methods, respectively.

The basic parser configuration assumes that the configuration will be made up of various parser components that implement the XMLComponent interface. If subclasses of this configuration create their own components for use in the parser configuration, then each component should be added to the list of components by calling the addComponent method. The basic parser configuration will make sure to call the reset method of each registered component before parsing an instance document.

This class recognizes the following features and properties:

  • Features
    • http://xml.org/sax/features/validation
    • http://xml.org/sax/features/namespaces
    • http://xml.org/sax/features/external-general-entities
    • http://xml.org/sax/features/external-parameter-entities
  • Properties
    • http://xml.org/sax/properties/xml-string
    • http://apache.org/xml/properties/internal/symbol-table
    • http://apache.org/xml/properties/internal/error-handler
    • http://apache.org/xml/properties/internal/entity-resolver
Version:
$Id: BasicParserConfiguration.java 447239 2006-09-18 05:08:26Z mrglavas $
Author:
Arnaud Le Hors, IBM, Andy Clark, IBM
  • Field Details

    • VALIDATION

      protected static final String VALIDATION
      Feature identifier: validation.
      See Also:
    • NAMESPACES

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

      protected static final String EXTERNAL_GENERAL_ENTITIES
      Feature identifier: external general entities.
      See Also:
    • EXTERNAL_PARAMETER_ENTITIES

      protected static final String EXTERNAL_PARAMETER_ENTITIES
      Feature identifier: external parameter entities.
      See Also:
    • XML_STRING

      protected static final String XML_STRING
      Property identifier: xml string.
      See Also:
    • SYMBOL_TABLE

      protected static final String SYMBOL_TABLE
      Property identifier: symbol table.
      See Also:
    • ERROR_HANDLER

      protected static final String ERROR_HANDLER
      Property identifier: error handler.
      See Also:
    • ENTITY_RESOLVER

      protected static final String ENTITY_RESOLVER
      Property identifier: entity resolver.
      See Also:
    • fSymbolTable

      protected SymbolTable fSymbolTable
      Symbol table.
    • fLocale

      protected Locale fLocale
      Locale.
    • fComponents

      protected ArrayList fComponents
      Components.
    • fDocumentHandler

      protected org.apache.xerces.xni.XMLDocumentHandler fDocumentHandler
      The document handler.
    • fDTDHandler

      protected org.apache.xerces.xni.XMLDTDHandler fDTDHandler
      The DTD handler.
    • fDTDContentModelHandler

      protected org.apache.xerces.xni.XMLDTDContentModelHandler fDTDContentModelHandler
      The DTD content model handler.
    • fLastComponent

      protected org.apache.xerces.xni.parser.XMLDocumentSource fLastComponent
      Last component in the document pipeline
  • Constructor Details

    • BasicParserConfiguration

      protected BasicParserConfiguration()
      Default Constructor.
    • BasicParserConfiguration

      protected BasicParserConfiguration(SymbolTable symbolTable)
      Constructs a parser configuration using the specified symbol table.
      Parameters:
      symbolTable - The symbol table to use.
    • BasicParserConfiguration

      protected BasicParserConfiguration(SymbolTable symbolTable, org.apache.xerces.xni.parser.XMLComponentManager parentSettings)
      Constructs a parser configuration using the specified symbol table and parent settings.
      Parameters:
      symbolTable - The symbol table to use.
      parentSettings - The parent settings.
  • Method Details

    • addComponent

      protected void addComponent(org.apache.xerces.xni.parser.XMLComponent component)
      Adds a component to the parser configuration. This method will also add all of the component's recognized features and properties to the list of default recognized features and properties.
      Parameters:
      component - The component to add.
    • parse

      public abstract void parse(org.apache.xerces.xni.parser.XMLInputSource inputSource) throws org.apache.xerces.xni.XNIException, IOException
      Parse an XML document.

      The parser can use this method to instruct this configuration to begin parsing an XML document from any valid input source (a character stream, a byte stream, or a URI).

      Parsers may not invoke this method while a parse is in progress. Once a parse is complete, the parser may then parse another XML document.

      This method is synchronous: it will not return until parsing has ended. If a client application wants to terminate parsing early, it should throw an exception.

      Specified by:
      parse in interface org.apache.xerces.xni.parser.XMLParserConfiguration
      Parameters:
      inputSource - The input source for the top-level of the XML document.
      Throws:
      org.apache.xerces.xni.XNIException - Any XNI exception, possibly wrapping another exception.
      IOException - An IO exception from the parser, possibly from a byte stream or character stream supplied by the parser.
    • setDocumentHandler

      public void setDocumentHandler(org.apache.xerces.xni.XMLDocumentHandler documentHandler)
      Sets the document handler on the last component in the pipeline to receive information about the document.
      Specified by:
      setDocumentHandler in interface org.apache.xerces.xni.parser.XMLParserConfiguration
      Parameters:
      documentHandler - The document handler.
    • getDocumentHandler

      public org.apache.xerces.xni.XMLDocumentHandler getDocumentHandler()
      Returns the registered document handler.
      Specified by:
      getDocumentHandler in interface org.apache.xerces.xni.parser.XMLParserConfiguration
    • setDTDHandler

      public void setDTDHandler(org.apache.xerces.xni.XMLDTDHandler dtdHandler)
      Sets the DTD handler.
      Specified by:
      setDTDHandler in interface org.apache.xerces.xni.parser.XMLParserConfiguration
      Parameters:
      dtdHandler - The DTD handler.
    • getDTDHandler

      public org.apache.xerces.xni.XMLDTDHandler getDTDHandler()
      Returns the registered DTD handler.
      Specified by:
      getDTDHandler in interface org.apache.xerces.xni.parser.XMLParserConfiguration
    • setDTDContentModelHandler

      public void setDTDContentModelHandler(org.apache.xerces.xni.XMLDTDContentModelHandler handler)
      Sets the DTD content model handler.
      Specified by:
      setDTDContentModelHandler in interface org.apache.xerces.xni.parser.XMLParserConfiguration
      Parameters:
      handler - The DTD content model handler.
    • getDTDContentModelHandler

      public org.apache.xerces.xni.XMLDTDContentModelHandler getDTDContentModelHandler()
      Returns the registered DTD content model handler.
      Specified by:
      getDTDContentModelHandler in interface org.apache.xerces.xni.parser.XMLParserConfiguration
    • setEntityResolver

      public void setEntityResolver(org.apache.xerces.xni.parser.XMLEntityResolver resolver)
      Sets the resolver used to resolve external entities. The EntityResolver interface supports resolution of public and system identifiers.
      Specified by:
      setEntityResolver in interface org.apache.xerces.xni.parser.XMLParserConfiguration
      Parameters:
      resolver - The new entity resolver. Passing a null value will uninstall the currently installed resolver.
    • getEntityResolver

      public org.apache.xerces.xni.parser.XMLEntityResolver getEntityResolver()
      Return the current entity resolver.
      Specified by:
      getEntityResolver in interface org.apache.xerces.xni.parser.XMLParserConfiguration
      Returns:
      The current entity resolver, or null if none has been registered.
      See Also:
    • setErrorHandler

      public void setErrorHandler(org.apache.xerces.xni.parser.XMLErrorHandler 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 org.apache.xerces.xni.parser.XMLParserConfiguration
      Parameters:
      errorHandler - The error handler.
      Throws:
      NullPointerException - If the handler argument is null.
      See Also:
    • getErrorHandler

      public org.apache.xerces.xni.parser.XMLErrorHandler getErrorHandler()
      Return the current error handler.
      Specified by:
      getErrorHandler in interface org.apache.xerces.xni.parser.XMLParserConfiguration
      Returns:
      The current error handler, or null if none has been registered.
      See Also:
    • setFeature

      public void setFeature(String featureId, boolean state) throws org.apache.xerces.xni.parser.XMLConfigurationException
      Set the state of a feature. 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 org.apache.xerces.xni.parser.XMLParserConfiguration
      Overrides:
      setFeature in class ParserConfigurationSettings
      Parameters:
      featureId - The unique identifier (URI) of the feature.
      state - The requested state of the feature (true or false).
      Throws:
      org.apache.xerces.xni.parser.XMLConfigurationException - If the requested feature is not known.
    • setProperty

      public void setProperty(String propertyId, Object value) throws org.apache.xerces.xni.parser.XMLConfigurationException
      setProperty
      Specified by:
      setProperty in interface org.apache.xerces.xni.parser.XMLParserConfiguration
      Overrides:
      setProperty in class ParserConfigurationSettings
      Parameters:
      propertyId -
      value -
      Throws:
      org.apache.xerces.xni.parser.XMLConfigurationException - If the requested feature is not known.
    • setLocale

      public void setLocale(Locale locale) throws org.apache.xerces.xni.XNIException
      Set the locale to use for messages.
      Specified by:
      setLocale in interface org.apache.xerces.xni.parser.XMLParserConfiguration
      Parameters:
      locale - The locale object to use for localization of messages.
      Throws:
      org.apache.xerces.xni.XNIException - Thrown if the parser does not support the specified locale.
    • getLocale

      public Locale getLocale()
      Returns the locale.
      Specified by:
      getLocale in interface org.apache.xerces.xni.parser.XMLParserConfiguration
    • reset

      protected void reset() throws org.apache.xerces.xni.XNIException
      reset all components before parsing and namespace context
      Throws:
      org.apache.xerces.xni.XNIException
    • checkProperty

      protected void checkProperty(String propertyId) throws org.apache.xerces.xni.parser.XMLConfigurationException
      Check a property. If the property is known and supported, this method simply returns. Otherwise, the appropriate exception is thrown.
      Overrides:
      checkProperty in class ParserConfigurationSettings
      Parameters:
      propertyId - The unique identifier (URI) of the property being set.
      Throws:
      org.apache.xerces.xni.parser.XMLConfigurationException - If the requested feature is not known or supported.
    • checkFeature

      protected void checkFeature(String featureId) throws org.apache.xerces.xni.parser.XMLConfigurationException
      Check a feature. If feature is know and supported, this method simply returns. Otherwise, the appropriate exception is thrown.
      Overrides:
      checkFeature in class ParserConfigurationSettings
      Parameters:
      featureId - The unique identifier (URI) of the feature.
      Throws:
      org.apache.xerces.xni.parser.XMLConfigurationException - Thrown for configuration error. In general, components should only throw this exception if it is really a critical error.