org.apache.xerces.parsers
Class BasicParserConfiguration

java.lang.Object
  |
  +--org.apache.xerces.parsers.BasicParserConfiguration
Direct Known Subclasses:
StandardParserConfiguration

public abstract class BasicParserConfiguration
extends java.lang.Object
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:

Version:
$Id: BasicParserConfiguration.java,v 1.1.2.8 2001/08/09 07:08:44 andyc Exp $
Author:
Arnaud Le Hors, IBM, Andy Clark, IBM

Field Summary
protected static java.lang.String ENTITY_RESOLVER
          Property identifier: entity resolver.
protected static java.lang.String ERROR_HANDLER
          Property identifier: error handler.
protected static java.lang.String EXTERNAL_GENERAL_ENTITIES
          Feature identifier: external general entities.
protected static java.lang.String EXTERNAL_PARAMETER_ENTITIES
          Feature identifier: external parameter entities.
protected  java.util.Vector fComponents
          Components.
protected  org.apache.xerces.xni.XMLDocumentHandler fDocumentHandler
          The document handler.
protected  org.apache.xerces.xni.XMLDTDContentModelHandler fDTDContentModelHandler
          The DTD content model handler.
protected  org.apache.xerces.xni.XMLDTDHandler fDTDHandler
          The DTD handler.
protected  java.util.Hashtable fFeatures
          Features.
protected  java.util.Hashtable fProperties
          Properties.
protected  java.util.Vector fRecognizedFeatures
          Recognized features.
protected  java.util.Vector fRecognizedProperties
          Recognized properties.
protected  SymbolTable fSymbolTable
          Symbol table.
protected static java.lang.String NAMESPACES
          Feature identifier: namespaces.
protected static java.lang.String SYMBOL_TABLE
          Property identifier: symbol table.
protected static java.lang.String VALIDATION
          Feature identifier: validation.
protected static java.lang.String XML_STRING
          Property identifier: xml string.
 
Constructor Summary
protected BasicParserConfiguration()
          Default Constructor.
protected BasicParserConfiguration(SymbolTable symbolTable)
          Constructs a document parser using the specified symbol table and a default grammar pool.
 
Method Summary
protected  void addComponent(org.apache.xerces.xni.parser.XMLComponent component)
          Adds a component to the parser configuration.
 void addRecognizedFeatures(java.lang.String[] featureIds)
          Allows a parser to add parser specific features to be recognized and managed by the parser configuration.
 void addRecognizedProperties(java.lang.String[] propertyIds)
          Allows a parser to add parser specific properties to be recognized and managed by the parser configuration.
protected  void checkFeature(java.lang.String featureId)
          Check a feature.
protected  void checkProperty(java.lang.String propertyId)
          Check a property.
 org.apache.xerces.xni.parser.XMLEntityResolver getEntityResolver()
          Return the current entity resolver.
 org.apache.xerces.xni.parser.XMLErrorHandler getErrorHandler()
          Return the current error handler.
 boolean getFeature(java.lang.String featureId)
          Returns the state of a feature.
 java.lang.Object getProperty(java.lang.String propertyId)
          Returns the value of a property.
abstract  void parse(org.apache.xerces.xni.parser.XMLInputSource inputSource)
          public void parse(String systemId) throws XNIException, IOException { InputSource source = new InputSource(systemId); parse(source); try { Reader reader = source.getCharacterStream(); if (reader != null) { reader.close(); } else { InputStream is = source.getByteStream(); if (is != null) { is.close(); } } } catch (IOException e) { // ignore } } // parse(String) /** parse
protected  void reset()
          reset all components before parsing
 void setDocumentHandler(org.apache.xerces.xni.XMLDocumentHandler handler)
          Sets the document handler to receive information about the document.
 void setDTDContentModelHandler(org.apache.xerces.xni.XMLDTDContentModelHandler handler)
          Sets the DTD content model handler.
 void setDTDHandler(org.apache.xerces.xni.XMLDTDHandler handler)
          Sets the DTD handler.
 void setEntityResolver(org.apache.xerces.xni.parser.XMLEntityResolver resolver)
          Sets the resolver used to resolve external entities.
 void setErrorHandler(org.apache.xerces.xni.parser.XMLErrorHandler errorHandler)
          Allow an application to register an error event handler.
 void setFeature(java.lang.String featureId, boolean state)
          Set the state of a feature.
 void setProperty(java.lang.String propertyId, java.lang.Object value)
          setProperty
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VALIDATION

protected static final java.lang.String VALIDATION
Feature identifier: validation.

NAMESPACES

protected static final java.lang.String NAMESPACES
Feature identifier: namespaces.

EXTERNAL_GENERAL_ENTITIES

protected static final java.lang.String EXTERNAL_GENERAL_ENTITIES
Feature identifier: external general entities.

EXTERNAL_PARAMETER_ENTITIES

protected static final java.lang.String EXTERNAL_PARAMETER_ENTITIES
Feature identifier: external parameter entities.

XML_STRING

protected static final java.lang.String XML_STRING
Property identifier: xml string.

SYMBOL_TABLE

protected static final java.lang.String SYMBOL_TABLE
Property identifier: symbol table.

ERROR_HANDLER

protected static final java.lang.String ERROR_HANDLER
Property identifier: error handler.

ENTITY_RESOLVER

protected static final java.lang.String ENTITY_RESOLVER
Property identifier: entity resolver.

fSymbolTable

protected SymbolTable fSymbolTable
Symbol table.

fRecognizedProperties

protected java.util.Vector fRecognizedProperties
Recognized properties.

fProperties

protected java.util.Hashtable fProperties
Properties.

fRecognizedFeatures

protected java.util.Vector fRecognizedFeatures
Recognized features.

fFeatures

protected java.util.Hashtable fFeatures
Features.

fComponents

protected java.util.Vector 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.
Constructor Detail

BasicParserConfiguration

protected BasicParserConfiguration()
Default Constructor.

BasicParserConfiguration

protected BasicParserConfiguration(SymbolTable symbolTable)
Constructs a document parser using the specified symbol table and a default grammar pool.
Method Detail

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,
                           java.io.IOException
public void parse(String systemId) throws XNIException, IOException { InputSource source = new InputSource(systemId); parse(source); try { Reader reader = source.getCharacterStream(); if (reader != null) { reader.close(); } else { InputStream is = source.getByteStream(); if (is != null) { is.close(); } } } catch (IOException e) { // ignore } } // parse(String) /** parse
Specified by:
parse in interface org.apache.xerces.xni.parser.XMLParserConfiguration
Parameters:
inputSource -  
Throws:
org.xml.sax.SAXException -  
java.io.IOException -  

setDocumentHandler

public void setDocumentHandler(org.apache.xerces.xni.XMLDocumentHandler handler)
Description copied from interface: org.apache.xerces.xni.parser.XMLParserConfiguration
Sets the document handler to receive information about the document.
Specified by:
setDocumentHandler in interface org.apache.xerces.xni.parser.XMLParserConfiguration
Tags copied from interface: org.apache.xerces.xni.parser.XMLParserConfiguration
Parameters:
documentHandler - The document handler.

setDTDHandler

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

setDTDContentModelHandler

public void setDTDContentModelHandler(org.apache.xerces.xni.XMLDTDContentModelHandler handler)
Description copied from interface: org.apache.xerces.xni.parser.XMLParserConfiguration
Sets the DTD content model handler.
Specified by:
setDTDContentModelHandler in interface org.apache.xerces.xni.parser.XMLParserConfiguration
Tags copied from interface: org.apache.xerces.xni.parser.XMLParserConfiguration
Parameters:
dtdContentModelHandler - The DTD content model handler.

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.
Returns:
The current entity resolver, or null if none has been registered.
See Also:
setEntityResolver(org.apache.xerces.xni.parser.XMLEntityResolver)

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:
java.lang.NullPointerException - If the handler argument is null.
See Also:
getErrorHandler()

getErrorHandler

public org.apache.xerces.xni.parser.XMLErrorHandler getErrorHandler()
Return the current error handler.
Returns:
The current error handler, or null if none has been registered.
See Also:
setErrorHandler(org.apache.xerces.xni.parser.XMLErrorHandler)

addRecognizedFeatures

public void addRecognizedFeatures(java.lang.String[] featureIds)
Allows a parser to add parser specific features to be recognized and managed by the parser configuration.
Specified by:
addRecognizedFeatures in interface org.apache.xerces.xni.parser.XMLParserConfiguration
Parameters:
featureIds - An array of the additional feature identifiers to be recognized.

setFeature

public void setFeature(java.lang.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
Parameters:
featureId - The unique identifier (URI) of the feature.
state - The requested state of the feature (true or false).
Throws:
org.xml.sax.SAXNotRecognizedException - If the requested feature is not known.
org.xml.sax.SAXNotSupportedException - If the requested feature is known, but the requested state is not supported.
org.xml.sax.SAXException - If there is any other problem fulfilling the request.

addRecognizedProperties

public void addRecognizedProperties(java.lang.String[] propertyIds)
Allows a parser to add parser specific properties to be recognized and managed by the parser configuration.
Specified by:
addRecognizedProperties in interface org.apache.xerces.xni.parser.XMLParserConfiguration
Parameters:
propertyIds - An array of the additional property identifiers to be recognized.

setProperty

public void setProperty(java.lang.String propertyId,
                        java.lang.Object value)
                 throws org.apache.xerces.xni.parser.XMLConfigurationException
setProperty
Specified by:
setProperty in interface org.apache.xerces.xni.parser.XMLParserConfiguration
Parameters:
propertyId -  
value -  

getFeature

public boolean getFeature(java.lang.String featureId)
                   throws org.apache.xerces.xni.parser.XMLConfigurationException
Returns the state of a feature.
Specified by:
getFeature in interface org.apache.xerces.xni.parser.XMLParserConfiguration
Parameters:
featureId - The feature identifier.
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.

getProperty

public java.lang.Object getProperty(java.lang.String propertyId)
                             throws org.apache.xerces.xni.parser.XMLConfigurationException
Returns the value of a property.
Specified by:
getProperty in interface org.apache.xerces.xni.parser.XMLParserConfiguration
Parameters:
propertyId - The property identifier.
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.

reset

protected void reset()
              throws org.apache.xerces.xni.XNIException
reset all components before parsing

checkFeature

protected void checkFeature(java.lang.String featureId)
                     throws org.apache.xerces.xni.parser.XMLConfigurationException
Check a feature. If feature is known and supported, this method simply returns. Otherwise, the appropriate exception is thrown.
Parameters:
featureId - The unique identifier (URI) of the feature.
Throws:
org.xml.sax.SAXNotRecognizedException - If the requested feature is not known.
org.xml.sax.SAXNotSupportedException - If the requested feature is known, but the requested state is not supported.
org.xml.sax.SAXException - If there is any other problem fulfilling the request.

checkProperty

protected void checkProperty(java.lang.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.
Parameters:
propertyId - The unique identifier (URI) of the property being set.
Throws:
org.xml.sax.SAXNotRecognizedException - If the requested property is not known.
org.xml.sax.SAXNotSupportedException - If the requested property is known, but the requested value is not supported.
org.xml.sax.SAXException - If there is any other problem fulfilling the request.


Copyright © 1999-2001 Apache XML Project. All Rights Reserved.