com.sun.xml.stream
Class XMLEntityManager

java.lang.Object
  extended by com.sun.xml.stream.XMLEntityManager
All Implemented Interfaces:
org.apache.xerces.xni.parser.XMLComponent, org.apache.xerces.xni.parser.XMLEntityResolver

public class XMLEntityManager
extends java.lang.Object
implements org.apache.xerces.xni.parser.XMLComponent, org.apache.xerces.xni.parser.XMLEntityResolver

Will keep track of current entity. The entity manager handles the registration of general and parameter entities; resolves entities; and starts entities. The entity manager is a central component in a standard parser configuration and this class works directly with the entity scanner to manage the underlying xni.

This component requires the following features and properties from the component manager that uses it:

Version:
$Id: XMLEntityManager.java,v 1.1 2006/03/31 03:17:08 jeffsuttor Exp $
Author:
Andy Clark, IBM, Arnaud Le Hors, IBM, K.Venugopal SUN Microsystems, Neeraj Bajaj SUN Microsystems

Nested Class Summary
protected  class XMLEntityManager.RewindableInputStream
           
 
Field Summary
protected static java.lang.String ALLOW_JAVA_ENCODINGS
          Feature identifier: allow Java encodings.
protected static java.lang.String BUFFER_SIZE
          property identifier: buffer size.
static int DEFAULT_BUFFER_SIZE
          Default buffer size (2048).
static int DEFAULT_INTERNAL_BUFFER_SIZE
          Default internal entity buffer size (1024).
static int DEFAULT_XMLDECL_BUFFER_SIZE
          Default buffer size before we've finished with the XMLDecl:
protected  java.lang.Object[] defaultEncoding
           
protected static java.lang.String ENTITY_RESOLVER
          Property identifier: entity resolver.
protected static java.lang.String ERROR_REPORTER
          Property identifier: error reporter.
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  boolean fAllowJavaEncodings
          Allow Java encoding names.
protected  int fBufferSize
          Buffer size.
protected  Entity.ScannedEntity fCurrentEntity
          Current entity.
protected  java.util.Hashtable fDeclaredEntities
          Shared declared entities.
protected  java.util.Hashtable fEntities
          Entities.
protected  XMLEntityHandler fEntityHandler
          Entity handler.
protected  XMLEntityReaderImpl fEntityReader
           
protected  org.apache.xerces.xni.parser.XMLEntityResolver fEntityResolver
          Entity resolver.
protected  java.util.Stack fEntityStack
          Entity stack.
protected  XMLEntityStorage fEntityStorage
           
protected  XMLErrorReporter fErrorReporter
          Error reporter.
protected  boolean fExternalGeneralEntities
          External general entities.
protected  boolean fExternalParameterEntities
          External parameter entities.
protected  boolean fInExternalSubset
           
protected  java.util.Vector fOwnReaders
           
protected  PropertyManager fPropertyManager
           
protected  boolean fStandalone
          True if the document entity is standalone.
protected  StaxEntityResolverWrapper fStaxEntityResolver
           
protected  org.apache.xerces.util.SymbolTable fSymbolTable
          Symbol table.
protected  boolean fValidation
          Validation.
protected static java.lang.String STAX_ENTITY_RESOLVER
           
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 VALIDATION_MANAGER
           
protected static java.lang.String WARN_ON_DUPLICATE_ENTITYDEF
          Feature identifier: warn on duplicate EntityDef
 
Constructor Summary
XMLEntityManager()
          If this constructor is used to create the object, reset() should be invoked on this object
XMLEntityManager(PropertyManager propertyManager)
          Default constructor.
 
Method Summary
 void closeReaders()
          Close all opened InputStreams and Readers opened by this parser.
protected  java.io.Reader createReader(java.io.InputStream inputStream, java.lang.String encoding, java.lang.Boolean isBigEndian)
          Creates a reader capable of reading the given input stream in the specified encoding.
 void endEntity()
           
 void endExternalSubset()
           
static java.lang.String expandSystemId(java.lang.String systemId)
          Expands a system id and returns the system id as a URI, if it can be expanded.
static java.lang.String expandSystemId(java.lang.String systemId, java.lang.String baseSystemId)
          Expands a system id and returns the system id as a URI, if it can be expanded.
protected static java.lang.String fixURI(java.lang.String str)
          Fixes a platform dependent filename to standard URI form.
 int getColumnNumber()
          Return the column number where the current document event ends.
 Entity.ScannedEntity getCurrentEntity()
          Return the current entity being scanned.
protected  java.lang.Object[] getEncodingName(byte[] b4, int count)
          Returns the IANA encoding name that is auto-detected from the bytes specified, with the endian-ness of that encoding where appropriate.
 XMLEntityReader getEntityReader()
          return the entity responsible for reading the entity
 XMLEntityStorage getEntityStore()
          get the entity storage object from entity manager
 java.lang.String getExpandedSystemId()
          Return the expanded system identifier for the current document event.
 java.lang.Boolean getFeatureDefault(java.lang.String featureId)
          Returns the default state for a feature, or null if this component does not want to report a default value for this feature.
 int getLineNumber()
          Return the line number where the current document event ends.
 java.lang.String getLiteralSystemId()
          Return the literal system identifier for the current document event.
 java.lang.Object getPropertyDefault(java.lang.String propertyId)
          Returns the default state for a property, or null if this component does not want to report a default value for this property.
 java.lang.String getPublicId()
          Return the public identifier for the current document event.
 java.lang.String[] getRecognizedFeatures()
          Returns a list of feature identifiers that are recognized by this component.
 java.lang.String[] getRecognizedProperties()
          Returns a list of property identifiers that are recognized by this component.
 boolean isStandalone()
          Returns true if the document entity is standalone.
 void reset(PropertyManager propertyManager)
           
 void reset(org.apache.xerces.xni.parser.XMLComponentManager componentManager)
          Resets the component.
 org.apache.xerces.xni.parser.XMLInputSource resolveEntity(org.apache.xerces.xni.XMLResourceIdentifier resourceIdentifier)
          Resolves the specified public and system identifiers.
 StaxXMLInputSource resolveEntityAsPerStax(org.apache.xerces.xni.XMLResourceIdentifier resourceIdentifier)
           
 void setEntityHandler(XMLEntityHandler entityHandler)
          Sets the entity handler.
 void setFeature(java.lang.String featureId, boolean state)
          Sets the state of a feature.
 void setProperty(java.lang.String name, java.lang.Object value)
          Sets the value of a property.
 void setStandalone(boolean standalone)
          Sets whether the document entity is standalone.
 void startDocumentEntity(org.apache.xerces.xni.parser.XMLInputSource xmlInputSource)
          Starts the document entity.
 void startDTDEntity(org.apache.xerces.xni.parser.XMLInputSource xmlInputSource)
          Starts the DTD entity.
 void startEntity(java.lang.String entityName, boolean literal)
          Starts a named entity.
 void startEntity(java.lang.String name, org.apache.xerces.xni.parser.XMLInputSource xmlInputSource, boolean literal, boolean isExternal)
          Starts an entity.
 void startExternalSubset()
           
 void test()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_BUFFER_SIZE

public static final int DEFAULT_BUFFER_SIZE
Default buffer size (2048).

See Also:
Constant Field Values

DEFAULT_XMLDECL_BUFFER_SIZE

public static final int DEFAULT_XMLDECL_BUFFER_SIZE
Default buffer size before we've finished with the XMLDecl:

See Also:
Constant Field Values

DEFAULT_INTERNAL_BUFFER_SIZE

public static final int DEFAULT_INTERNAL_BUFFER_SIZE
Default internal entity buffer size (1024).

See Also:
Constant Field Values

VALIDATION

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

See Also:
Constant Field Values

EXTERNAL_GENERAL_ENTITIES

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

See Also:
Constant Field Values

EXTERNAL_PARAMETER_ENTITIES

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

See Also:
Constant Field Values

ALLOW_JAVA_ENCODINGS

protected static final java.lang.String ALLOW_JAVA_ENCODINGS
Feature identifier: allow Java encodings.

See Also:
Constant Field Values

WARN_ON_DUPLICATE_ENTITYDEF

protected static final java.lang.String WARN_ON_DUPLICATE_ENTITYDEF
Feature identifier: warn on duplicate EntityDef

See Also:
Constant Field Values

SYMBOL_TABLE

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

See Also:
Constant Field Values

ERROR_REPORTER

protected static final java.lang.String ERROR_REPORTER
Property identifier: error reporter.

See Also:
Constant Field Values

ENTITY_RESOLVER

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

See Also:
Constant Field Values

STAX_ENTITY_RESOLVER

protected static final java.lang.String STAX_ENTITY_RESOLVER
See Also:
Constant Field Values

VALIDATION_MANAGER

protected static final java.lang.String VALIDATION_MANAGER
See Also:
Constant Field Values

BUFFER_SIZE

protected static final java.lang.String BUFFER_SIZE
property identifier: buffer size.

See Also:
Constant Field Values

fValidation

protected boolean fValidation
Validation. This feature identifier is: http://xml.org/sax/features/validation


fExternalGeneralEntities

protected boolean fExternalGeneralEntities
External general entities. This feature identifier is: http://xml.org/sax/features/external-general-entities


fExternalParameterEntities

protected boolean fExternalParameterEntities
External parameter entities. This feature identifier is: http://xml.org/sax/features/external-parameter-entities


fAllowJavaEncodings

protected boolean fAllowJavaEncodings
Allow Java encoding names. This feature identifier is: http://apache.org/xml/features/allow-java-encodings


fSymbolTable

protected org.apache.xerces.util.SymbolTable fSymbolTable
Symbol table. This property identifier is: http://apache.org/xml/properties/internal/symbol-table


fErrorReporter

protected XMLErrorReporter fErrorReporter
Error reporter. This property identifier is: http://apache.org/xml/properties/internal/error-reporter


fEntityResolver

protected org.apache.xerces.xni.parser.XMLEntityResolver fEntityResolver
Entity resolver. This property identifier is: http://apache.org/xml/properties/internal/entity-resolver


fStaxEntityResolver

protected StaxEntityResolverWrapper fStaxEntityResolver

fPropertyManager

protected PropertyManager fPropertyManager

fBufferSize

protected int fBufferSize
Buffer size. We get this value from a property. The default size is used if the input buffer size property is not specified. REVISIT: do we need a property for internal entity buffer size?


fStandalone

protected boolean fStandalone
True if the document entity is standalone. This should really only be set by the document source (e.g. XMLDocumentScanner).


fInExternalSubset

protected boolean fInExternalSubset

fEntityHandler

protected XMLEntityHandler fEntityHandler
Entity handler.


fEntityReader

protected XMLEntityReaderImpl fEntityReader

fEntities

protected java.util.Hashtable fEntities
Entities.


fEntityStack

protected java.util.Stack fEntityStack
Entity stack.


fCurrentEntity

protected Entity.ScannedEntity fCurrentEntity
Current entity.


fDeclaredEntities

protected java.util.Hashtable fDeclaredEntities
Shared declared entities. XXX understand it more deeply, why are we doing this ?? Is it really required ?


fEntityStorage

protected XMLEntityStorage fEntityStorage

defaultEncoding

protected final java.lang.Object[] defaultEncoding

fOwnReaders

protected java.util.Vector fOwnReaders
Constructor Detail

XMLEntityManager

public XMLEntityManager()
If this constructor is used to create the object, reset() should be invoked on this object


XMLEntityManager

public XMLEntityManager(PropertyManager propertyManager)
Default constructor.

Method Detail

getEntityStore

public XMLEntityStorage getEntityStore()
get the entity storage object from entity manager


getEntityReader

public XMLEntityReader getEntityReader()
return the entity responsible for reading the entity


setStandalone

public void setStandalone(boolean standalone)
Sets whether the document entity is standalone.

Parameters:
standalone - True if document entity is standalone.

isStandalone

public boolean isStandalone()
Returns true if the document entity is standalone.


setEntityHandler

public void setEntityHandler(XMLEntityHandler entityHandler)
Sets the entity handler. When an entity starts and ends, the entity handler is notified of the change.

Parameters:
entityHandler - The new entity handler.

resolveEntityAsPerStax

public StaxXMLInputSource resolveEntityAsPerStax(org.apache.xerces.xni.XMLResourceIdentifier resourceIdentifier)
                                          throws java.io.IOException
Throws:
java.io.IOException

resolveEntity

public org.apache.xerces.xni.parser.XMLInputSource resolveEntity(org.apache.xerces.xni.XMLResourceIdentifier resourceIdentifier)
                                                          throws java.io.IOException,
                                                                 org.apache.xerces.xni.XNIException
Resolves the specified public and system identifiers. This method first attempts to resolve the entity based on the EntityResolver registered by the application. If no entity resolver is registered or if the registered entity handler is unable to resolve the entity, then default entity resolution will occur.

Specified by:
resolveEntity in interface org.apache.xerces.xni.parser.XMLEntityResolver
Parameters:
publicId - The public identifier of the entity.
systemId - The system identifier of the entity.
baseSystemId - The base system identifier of the entity. This is the system identifier of the current entity and is used to expand the system identifier when the system identifier is a relative URI.
Returns:
Returns an input source that wraps the resolved entity. This method will never return null.
Throws:
java.io.IOException - Thrown on i/o error.
org.apache.xerces.xni.XNIException - Thrown by entity resolver to signal an error.
See Also:
XMLResourceIdentifier

startEntity

public void startEntity(java.lang.String entityName,
                        boolean literal)
                 throws java.io.IOException,
                        org.apache.xerces.xni.XNIException
Starts a named entity.

Parameters:
entityName - The name of the entity to start.
literal - True if this entity is started within a literal value.
Throws:
java.io.IOException - Thrown on i/o error.
org.apache.xerces.xni.XNIException - Thrown by entity handler to signal an error.

startDocumentEntity

public void startDocumentEntity(org.apache.xerces.xni.parser.XMLInputSource xmlInputSource)
                         throws java.io.IOException,
                                org.apache.xerces.xni.XNIException
Starts the document entity. The document entity has the "[xml]" pseudo-name.

Parameters:
xmlInputSource - The input source of the document entity.
Throws:
java.io.IOException - Thrown on i/o error.
org.apache.xerces.xni.XNIException - Thrown by entity handler to signal an error.

startDTDEntity

public void startDTDEntity(org.apache.xerces.xni.parser.XMLInputSource xmlInputSource)
                    throws java.io.IOException,
                           org.apache.xerces.xni.XNIException
Starts the DTD entity. The DTD entity has the "[dtd]" pseudo-name.

Parameters:
xmlInputSource - The input source of the DTD entity.
Throws:
java.io.IOException - Thrown on i/o error.
org.apache.xerces.xni.XNIException - Thrown by entity handler to signal an error.

startExternalSubset

public void startExternalSubset()

endExternalSubset

public void endExternalSubset()

startEntity

public void startEntity(java.lang.String name,
                        org.apache.xerces.xni.parser.XMLInputSource xmlInputSource,
                        boolean literal,
                        boolean isExternal)
                 throws java.io.IOException,
                        org.apache.xerces.xni.XNIException
Starts an entity.

This method can be used to insert an application defined XML entity stream into the parsing stream.

Parameters:
name - The name of the entity.
xmlInputSource - The input source of the entity.
literal - True if this entity is started within a literal value.
isExternal - whether this entity should be treated as an internal or external entity.
Throws:
java.io.IOException - Thrown on i/o error.
org.apache.xerces.xni.XNIException - Thrown by entity handler to signal an error.

getCurrentEntity

public Entity.ScannedEntity getCurrentEntity()
Return the current entity being scanned. Current entity is SET using startEntity function.

Returns:
Entity.ScannedEntity

closeReaders

public void closeReaders()
Close all opened InputStreams and Readers opened by this parser.


endEntity

public void endEntity()
               throws java.io.IOException,
                      org.apache.xerces.xni.XNIException
Throws:
java.io.IOException
org.apache.xerces.xni.XNIException

reset

public void reset(PropertyManager propertyManager)

reset

public void reset(org.apache.xerces.xni.parser.XMLComponentManager componentManager)
           throws org.apache.xerces.xni.parser.XMLConfigurationException
Resets the component. The component can query the component manager about any features and properties that affect the operation of the component.

Specified by:
reset in interface org.apache.xerces.xni.parser.XMLComponent
Parameters:
componentManager - The component manager.
Throws:
SAXException - Thrown by component on initialization error. For example, if a feature or property is required for the operation of the component, the component manager may throw a SAXNotRecognizedException or a SAXNotSupportedException.
org.apache.xerces.xni.parser.XMLConfigurationException

getRecognizedFeatures

public java.lang.String[] getRecognizedFeatures()
Returns a list of feature identifiers that are recognized by this component. This method may return null if no features are recognized by this component.

Specified by:
getRecognizedFeatures in interface org.apache.xerces.xni.parser.XMLComponent

setFeature

public void setFeature(java.lang.String featureId,
                       boolean state)
                throws org.apache.xerces.xni.parser.XMLConfigurationException
Sets the state of a feature. This method is called by the component manager any time after reset when a feature changes state.

Note: Components should silently ignore features that do not affect the operation of the component.

Specified by:
setFeature in interface org.apache.xerces.xni.parser.XMLComponent
Parameters:
featureId - The feature identifier.
state - The state of the feature.
Throws:
SAXNotRecognizedException - The component should not throw this exception.
SAXNotSupportedException - The component should not throw this exception.
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.

setProperty

public void setProperty(java.lang.String name,
                        java.lang.Object value)
Description copied from interface: org.apache.xerces.xni.parser.XMLComponent
Sets the value of a property. This method is called by the component manager any time after reset when a property changes value.

Note: Components should silently ignore properties that do not affect the operation of the component.

Specified by:
setProperty in interface org.apache.xerces.xni.parser.XMLComponent
Parameters:
name - The property identifier.
value - The value of the property.

getRecognizedProperties

public java.lang.String[] getRecognizedProperties()
Returns a list of property identifiers that are recognized by this component. This method may return null if no properties are recognized by this component.

Specified by:
getRecognizedProperties in interface org.apache.xerces.xni.parser.XMLComponent

getFeatureDefault

public java.lang.Boolean getFeatureDefault(java.lang.String featureId)
Returns the default state for a feature, or null if this component does not want to report a default value for this feature.

Specified by:
getFeatureDefault in interface org.apache.xerces.xni.parser.XMLComponent
Parameters:
featureId - The feature identifier.
Since:
Xerces 2.2.0

getPropertyDefault

public java.lang.Object getPropertyDefault(java.lang.String propertyId)
Returns the default state for a property, or null if this component does not want to report a default value for this property.

Specified by:
getPropertyDefault in interface org.apache.xerces.xni.parser.XMLComponent
Parameters:
propertyId - The property identifier.
Since:
Xerces 2.2.0

expandSystemId

public static java.lang.String expandSystemId(java.lang.String systemId)
Expands a system id and returns the system id as a URI, if it can be expanded. A return value of null means that the identifier is already expanded. An exception thrown indicates a failure to expand the id.

Parameters:
systemId - The systemId to be expanded.
Returns:
Returns the URI string representing the expanded system identifier. A null value indicates that the given system identifier is already expanded.

expandSystemId

public static java.lang.String expandSystemId(java.lang.String systemId,
                                              java.lang.String baseSystemId)
Expands a system id and returns the system id as a URI, if it can be expanded. A return value of null means that the identifier is already expanded. An exception thrown indicates a failure to expand the id.

Parameters:
systemId - The systemId to be expanded.
Returns:
Returns the URI string representing the expanded system identifier. A null value indicates that the given system identifier is already expanded.

getEncodingName

protected java.lang.Object[] getEncodingName(byte[] b4,
                                             int count)
Returns the IANA encoding name that is auto-detected from the bytes specified, with the endian-ness of that encoding where appropriate.

Parameters:
b4 - The first four bytes of the input.
count - The number of bytes actually read.
Returns:
a 2-element array: the first element, an IANA-encoding string, the second element a Boolean which is true iff the document is big endian, false if it's little-endian, and null if the distinction isn't relevant.

createReader

protected java.io.Reader createReader(java.io.InputStream inputStream,
                                      java.lang.String encoding,
                                      java.lang.Boolean isBigEndian)
                               throws java.io.IOException
Creates a reader capable of reading the given input stream in the specified encoding.

Parameters:
inputStream - The input stream.
encoding - The encoding name that the input stream is encoded using. If the user has specified that Java encoding names are allowed, then the encoding name may be a Java encoding name; otherwise, it is an ianaEncoding name.
isBigEndian - For encodings (like uCS-4), whose names cannot specify a byte order, this tells whether the order is bigEndian. null menas unknown or not relevant.
Returns:
Returns a reader.
Throws:
java.io.IOException

getPublicId

public java.lang.String getPublicId()
Return the public identifier for the current document event.

The return value is the public identifier of the document entity or of the external parsed entity in which the markup triggering the event appears.

Returns:
A string containing the public identifier, or null if none is available.

getExpandedSystemId

public java.lang.String getExpandedSystemId()
Return the expanded system identifier for the current document event.

The return value is the expanded system identifier of the document entity or of the external parsed entity in which the markup triggering the event appears.

If the system identifier is a URL, the parser must resolve it fully before passing it to the application.

Returns:
A string containing the expanded system identifier, or null if none is available.

getLiteralSystemId

public java.lang.String getLiteralSystemId()
Return the literal system identifier for the current document event.

The return value is the literal system identifier of the document entity or of the external parsed entity in which the markup triggering the event appears.

Returns:
A string containing the literal system identifier, or null if none is available.

getLineNumber

public int getLineNumber()
Return the line number where the current document event ends.

Warning: The return value from the method is intended only as an approximation for the sake of error reporting; it is not intended to provide sufficient information to edit the character content of the original XML document.

The return value is an approximation of the line number in the document entity or external parsed entity where the markup triggering the event appears.

If possible, the SAX driver should provide the line position of the first character after the text associated with the document event. The first line in the document is line 1.

Returns:
The line number, or -1 if none is available.

getColumnNumber

public int getColumnNumber()
Return the column number where the current document event ends.

Warning: The return value from the method is intended only as an approximation for the sake of error reporting; it is not intended to provide sufficient information to edit the character content of the original XML document.

The return value is an approximation of the column number in the document entity or external parsed entity where the markup triggering the event appears.

If possible, the SAX driver should provide the line position of the first character after the text associated with the document event.

If possible, the SAX driver should provide the line position of the first character after the text associated with the document event. The first column in each line is column 1.

Returns:
The column number, or -1 if none is available.

fixURI

protected static java.lang.String fixURI(java.lang.String str)
Fixes a platform dependent filename to standard URI form.

Parameters:
str - The string to fix.
Returns:
Returns the fixed URI string.

test

public void test()


Copyright ? 2002-2003 Apache XML Project. All Rights Reserved.