Top Description Inners Fields Constructors Methods
org.apache.xerces.impl

public Class XMLEntityManager

extends Object
implements XMLComponent, XMLEntityResolver
Class Inheritance
All Implemented Interfaces
org.apache.xerces.xni.parser.XMLEntityResolver, org.apache.xerces.xni.parser.XMLComponent
Imports
java.io.File, .FileOutputStream, .IOException, .InputStream, .InputStreamReader, .OutputStream, .Reader, .StringReader, java.net.HttpURLConnection, .URL, .URLConnection, java.security.AccessController, .PrivilegedAction, java.util.Hashtable, .Iterator, .Locale, .Map, .Stack, .StringTokenizer, org.apache.xerces.impl.io.ASCIIReader, .Latin1Reader, .UCSReader, .UTF16Reader, .UTF8Reader, org.apache.xerces.impl.msg.XMLMessageFormatter, org.apache.xerces.impl.validation.ValidationManager, org.apache.xerces.util.AugmentationsImpl, .EncodingMap, .HTTPInputSource, .SecurityManager, .SymbolTable, .URI, .XMLChar, .XMLEntityDescriptionImpl, .XMLResourceIdentifierImpl, org.apache.xerces.xni.Augmentations, .XMLResourceIdentifier, .XNIException, org.apache.xerces.xni.parser.XMLComponent, .XMLComponentManager, .XMLConfigurationException, .XMLEntityResolver, .XMLInputSource

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:

Authors
Andy Clark, IBM, Arnaud Le Hors, IBM
Version
$Id: XMLEntityManager.java 1513559 2013-08-13 15:42:35Z mrglavas $

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
XMLEntityManager.ByteBufferPool

Pool of byte buffers for the java.io.Readers.

private static class
XMLEntityManager.CharacterBuffer

Buffer used in entity manager to reuse character arrays instead of creating new ones every time.

private static class
XMLEntityManager.CharacterBufferPool

Stores a number of character buffers and provides it to the entity manager to use when an entity is seen.

private static class
XMLEntityManager.EncodingInfo

Information about auto-detectable encodings.

public abstract static class
XMLEntityManager.Entity

Entity information.

protected static class
protected static class
protected class
XMLEntityManager.RewindableInputStream

This class wraps the byte inputstreams we're presented with.

public class

Field Summary

Modifier and TypeField and Description
protected static final String
ALLOW_JAVA_ENCODINGS

Feature identifier: allow Java encodings.

protected static final String
BUFFER_SIZE

property identifier: buffer size.

private static final boolean
DEBUG_BUFFER

Debug printing of buffer.

private static final boolean
DEBUG_ENCODINGS

Debug switching readers for encodings.

private static final boolean
DEBUG_ENTITIES

Debug some basic entities.

private static final boolean
public static final int
DEFAULT_BUFFER_SIZE

Default buffer size (2048).

public static final int
DEFAULT_INTERNAL_BUFFER_SIZE

Default internal entity buffer size (512).

public static final int
DEFAULT_XMLDECL_BUFFER_SIZE

Default buffer size before we've finished with the XMLDecl:

private static final String
protected static final String
ENTITY_RESOLVER

Property identifier: entity resolver.

protected static final String
ERROR_REPORTER

Property identifier: error reporter.

protected static final String
EXTERNAL_GENERAL_ENTITIES

Feature identifier: external general entities.

protected static final String
EXTERNAL_PARAMETER_ENTITIES

Feature identifier: external parameter entities.

protected boolean
fAllowJavaEncodings

Allow Java encoding names.

protected int
fBufferSize

Buffer size.

private final XMLEntityManager.CharacterBufferPool
fCharacterBufferPool

Pool of character buffers.

protected XMLEntityManager.ScannedEntity
fCurrentEntity

Current entity.

protected Hashtable<K, V>
fDeclaredEntities

Shared declared entities.

private static final Boolean[]
FEATURE_DEFAULTS

Feature defaults.

protected final Hashtable<K, V>
fEntities

Entities.

private final Augmentations
fEntityAugs

Augmentations for entities.

protected int
protected int
protected XMLEntityHandler
fEntityHandler

Entity handler.

protected XMLEntityResolver
fEntityResolver

Entity resolver.

protected XMLEntityScanner
fEntityScanner

Current entity scanner.

protected final Stack<E>
fEntityStack

Entity stack.

protected XMLErrorReporter
fErrorReporter

Error reporter.

protected boolean
fExternalGeneralEntities

External general entities.

protected boolean
fExternalParameterEntities

External parameter entities.

protected boolean
fHasPEReferences

True if the current document contains parameter entity references.

protected boolean
private final XMLEntityManager.ByteBufferPool
fLargeByteBufferPool

Pool of byte buffers for 2-byte encodings, such as UTF-16.

protected Stack<E>
private final XMLResourceIdentifierImpl
fResourceIdentifier

Resource identifier.

protected SecurityManager
private final XMLEntityManager.ByteBufferPool
fSmallByteBufferPool

Pool of byte buffers for single byte and variable width encodings, such as US-ASCII and UTF-8.

protected boolean
fStandalone

True if the document entity is standalone.

protected boolean
fStrictURI

standard uri conformant (strict uri).

protected SymbolTable
fSymbolTable

Symbol table.

private byte[]
fTempByteBuffer

Temporary storage for the current entity's byte buffer.

protected boolean
fValidation

Validation.

protected ValidationManager
fValidationManager

Validation manager.

protected boolean
fWarnDuplicateEntityDef

warn on duplicate Entity declaration.

protected XMLEntityScanner
fXML10EntityScanner

XML 1.0 entity scanner.

protected XMLEntityScanner
fXML11EntityScanner

XML 1.1 entity scanner.

private static final char[]
private static final char[]
private static PrivilegedAction<T>
private static final char[]
private static final boolean[]
private static String
private static URI
protected static final String
private static final Object[]
PROPERTY_DEFAULTS

Property defaults.

private static final String[]
RECOGNIZED_FEATURES

Recognized features.

private static final String[]
RECOGNIZED_PROPERTIES

Recognized properties.

protected static final String
SECURITY_MANAGER

property identifier: security manager.

protected static final String
STANDARD_URI_CONFORMANT

Feature identifier: standard uri conformant

protected static final String
SYMBOL_TABLE

Property identifier: symbol table.

protected static final String
VALIDATION

Feature identifier: validation.

protected static final String
protected static final String
WARN_ON_DUPLICATE_ENTITYDEF

Feature identifier: warn on duplicate EntityDef

private static final String

Constructor Summary

AccessConstructor and Description
public
XMLEntityManager()

Default constructor.

public
XMLEntityManager(XMLEntityManager entityManager)

Constructs an entity manager that shares the specified entity declarations during each parse.

Method Summary

Modifier and TypeMethod and Description
public static void
absolutizeAgainstUserDir(URI
the URI to absolutize
uri
)

Absolutizes a URI using the current value of the "user.dir" property as the base URI.

public void
addExternalEntity(String
The name of the entity.
name
,
String
The public identifier of the entity.
publicId
,
String
The system identifier of the entity.
literalSystemId
,
String
The base system identifier of the entity. This is the system identifier of the entity where the entity being added and is used to expand the system identifier when the system identifier is a relative URI. When null the system identifier of the first external entity on the stack is used instead.
baseSystemId
)

Adds an external entity declaration.

public void
addInternalEntity(String
The name of the entity.
name
,
String
The text of the entity.
text
,
int
Count of direct and indirect references to parameter entities in the value of the entity.
paramEntityRefs
)

Adds an internal entity declaration.

public void
addInternalEntity(String
The name of the entity.
name
,
String
The text of the entity.
text
)

Adds an internal entity declaration.

public void
addUnparsedEntity(String
The name of the entity.
name
,
String
The public identifier of the entity.
publicId
,
String
The system identifier of the entity.
systemId
,
String baseSystemId, String
The name of the notation.
notation
)

Adds an unparsed entity declaration.

public void
closeReaders()

Close all opened InputStreams and Readers opened by this parser.

private Reader
createASCIIReader(InputStream stream)

Create a new ASCII reader from the InputStream.

private Reader
createLatin1Reader(InputStream stream)

Create a new ISO-8859-1 reader from the InputStream.

public static OutputStream
protected Reader

Returns:

Returns a reader.
createReader
(InputStream
The input stream.
inputStream
,
String
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.
encoding
,
Boolean
For encodings (like uCS-4), whose names cannot specify a byte order, this tells whether the order is bigEndian. Null means unknown or not relevant.
isBigEndian
)

Creates a reader capable of reading the given input stream in the specified encoding.

private Reader
createUTF16Reader(InputStream stream, boolean isBigEndian)

Create a new UTF-16 reader from the InputStream.

private Reader
createUTF8Reader(InputStream stream)

Create a new UTF-8 reader from the InputStream.

pack-priv void
endEntity()

Ends an entity.

public void
public static String

Returns:

Returns the URI string representing the expanded system identifier. A null value indicates that the given system identifier is already expanded.
expandSystemId
(String
The systemId to be expanded.
systemId
,
String baseSystemId, boolean strict)

Expands a system id and returns the system id as a URI, if it can be expanded.

private static String
expandSystemIdStrictOff(String systemId, String baseSystemId)

Helper method for expandSystemId(String,String,boolean):String

private static String
expandSystemIdStrictOn(String systemId, String baseSystemId)

Helper method for expandSystemId(String,String,boolean):String

protected static String

Returns:

Returns the fixed URI string.
fixURI
(String
The string to fix.
str
)

Fixes a platform dependent filename to standard URI form.

public XMLEntityManager.ScannedEntity
public XMLResourceIdentifier
pack-priv Hashtable<K, V>
getDeclaredEntities()

Returns the hashtable of declared entities.

protected XMLEntityManager.EncodingInfo

Returns:

an instance of EncodingInfo which represents the auto-detected encoding.
getEncodingInfo
(byte[]
The first four bytes of the input.
b4
,
int
The number of bytes actually read.
count
)

Returns the IANA encoding name that is auto-detected from the bytes specified, with the endian-ness of that encoding where appropriate.

public XMLEntityScanner
getEntityScanner()

Returns the entity scanner.

public Boolean
getFeatureDefault(String
The feature identifier.
featureId
)

Implements org.apache.xerces.xni.parser.XMLComponent.getFeatureDefault.

Returns the default state for a feature, or null if this component does not want to report a default value for this feature.
public int

Returns:

Count of direct and indirect references to parameter entities in the value of the entity
getParamEntityRefCount
(String
The name of the entity to check.
entityName
)

Returns the number of direct and indirect references to parameter entities in the value of the entity.

private static String
public Object
getPropertyDefault(String
The property identifier.
propertyId
)

Implements org.apache.xerces.xni.parser.XMLComponent.getPropertyDefault.

Returns the default state for a property, or null if this component does not want to report a default value for this property.
public String[]
getRecognizedFeatures()

Implements org.apache.xerces.xni.parser.XMLComponent.getRecognizedFeatures.

Returns a list of feature identifiers that are recognized by this component.
public String[]
getRecognizedProperties()

Implements org.apache.xerces.xni.parser.XMLComponent.getRecognizedProperties.

Returns a list of property identifiers that are recognized by this component.
private static synchronized URI
pack-priv final boolean
hasPEReferences()

Returns true if the document contains parameter entity references.

public boolean

Returns:

True if the entity is declared, false otherwise.
isDeclaredEntity
(String
The name of the entity to check.
entityName
)

Checks whether an entity given by name is declared.

public boolean

Returns:

True if the entity was declared in the external subset, false otherwise (including when the entity is not declared).
isEntityDeclInExternalSubset
(String
The name of the entity to check.
entityName
)

Checks whether the declaration of an entity given by name is // in the external subset.

public boolean

Returns:

True if the entity is external, false otherwise (including when the entity is not declared).
isExternalEntity
(String
The name of the entity to check.
entityName
)

Checks whether an entity given by name is external.

public boolean
isStandalone()

Returns true if the document entity is standalone.

public boolean

Returns:

True if the entity is unparsed, false otherwise (including when the entity is not declared).
isUnparsedEntity
(String
The name of the entity to check.
entityName
)

Checks whether an entity given by name is unparsed.

pack-priv final void
notifyHasPEReferences()

Notifies the entity manager that the current document being processed contains parameter entity references.

public void
reset(XMLComponentManager
The component manager.
componentManager
)

Implements org.apache.xerces.xni.parser.XMLComponent.reset.

Resets the component.
public void
public XMLInputSource

Returns:

Returns an input source that wraps the resolved entity. This method will never return null.
resolveEntity
(XMLResourceIdentifier
The XMLResourceIdentifier for the resource to resolve.
resourceIdentifier
)

Implements org.apache.xerces.xni.parser.XMLEntityResolver.resolveEntity.

Resolves the specified public and system identifiers.
public void
setEntityHandler(XMLEntityHandler
The new entity handler.
entityHandler
)

Sets the entity handler.

public void
setFeature(String
The feature identifier.
featureId
,
boolean
The state of the feature.
state
)

Implements org.apache.xerces.xni.parser.XMLComponent.setFeature.

Sets the state of a feature.
public void
setProperty(String
The property identifier.
propertyId
,
Object
The value of the property.
value
)

Implements org.apache.xerces.xni.parser.XMLComponent.setProperty.

Sets the value of a property.
public void
setScannerVersion(short version)

public void
setStandalone(boolean
True if document entity is standalone.
standalone
)

Sets whether the document entity is standalone.

public String

Returns:

the encoding of the new entity or null if a character stream was employed
setupCurrentEntity
(String
name of the entity (XML is it's the document entity)
name
,
XMLInputSource
the input source, with sufficient information to begin scanning characters.
xmlInputSource
,
boolean
True if this entity is started within a literal value.
literal
,
boolean
whether this entity should be treated as an internal or external entity.
isExternal
)

This method uses the passed-in XMLInputSource to make fCurrentEntity usable for reading.

public void
startDocumentEntity(XMLInputSource
The input source of the document entity.
xmlInputSource
)

Starts the document entity.

public void
startDTDEntity(XMLInputSource
The input source of the DTD entity.
xmlInputSource
)

Starts the DTD entity.

public void
startEntity(String
The name of the entity to start.
entityName
,
boolean
True if this entity is started within a literal value.
literal
)

Starts a named entity.

public void
startEntity(String
The name of the entity.
name
,
XMLInputSource
The input source of the entity.
xmlInputSource
,
boolean
True if this entity is started within a literal value.
literal
,
boolean
whether this entity should be treated as an internal or external entity.
isExternal
)

Starts an entity.

public void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait