Class XMLEntityManager
- All Implemented Interfaces:
org.apache.xerces.xni.parser.XMLComponent
,org.apache.xerces.xni.parser.XMLEntityResolver
This component requires the following features and properties from the component manager that uses it:
- http://xml.org/sax/features/validation
- http://xml.org/sax/features/external-general-entities
- http://xml.org/sax/features/external-parameter-entities
- http://apache.org/xml/features/allow-java-encodings
- http://apache.org/xml/properties/internal/symbol-table
- http://apache.org/xml/properties/internal/error-reporter
- http://apache.org/xml/properties/internal/entity-resolver
INTERNAL:
- Usage of this class is not supported. It may be altered or removed at any time.
- Version:
- $Id: XMLEntityManager.java 1513559 2013-08-13 15:42:35Z mrglavas $
- Author:
- Andy Clark, IBM, Arnaud Le Hors, IBM
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Entity information.protected static class
External entity.protected static class
Internal entity.protected final class
This class wraps the byte inputstreams we're presented with.class
Entity state. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final String
Feature identifier: allow Java encodings.protected static final String
property identifier: buffer size.static final int
Default buffer size (2048).static final int
Default internal entity buffer size (512).static final int
Default buffer size before we've finished with the XMLDecl:protected static final String
Property identifier: entity resolver.protected static final String
Property identifier: error reporter.protected static final String
Feature identifier: external general entities.protected static final String
Feature identifier: external parameter entities.protected boolean
Allow Java encoding names.protected int
Buffer size.protected XMLEntityManager.ScannedEntity
Current entity.protected Hashtable
Shared declared entities.protected final Hashtable
Entities.protected int
protected int
protected XMLEntityHandler
Entity handler.protected org.apache.xerces.xni.parser.XMLEntityResolver
Entity resolver.protected XMLEntityScanner
Current entity scanner.protected final Stack
Entity stack.protected XMLErrorReporter
Error reporter.protected boolean
External general entities.protected boolean
External parameter entities.protected boolean
True if the current document contains parameter entity references.protected boolean
protected Stack
protected SecurityManager
protected boolean
True if the document entity is standalone.protected boolean
standard uri conformant (strict uri).protected SymbolTable
Symbol table.protected boolean
Validation.protected ValidationManager
Validation manager.protected boolean
warn on duplicate Entity declaration.protected XMLEntityScanner
XML 1.0 entity scanner.protected XMLEntityScanner
XML 1.1 entity scanner.protected static final String
protected static final String
property identifier: security manager.protected static final String
Feature identifier: standard uri conformantprotected static final String
Property identifier: symbol table.protected static final String
Feature identifier: validation.protected static final String
protected static final String
Feature identifier: warn on duplicate EntityDef -
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor.XMLEntityManager
(XMLEntityManager entityManager) Constructs an entity manager that shares the specified entity declarations during each parse. -
Method Summary
Modifier and TypeMethodDescriptionstatic void
Absolutizes a URI using the current value of the "user.dir" property as the base URI.void
addExternalEntity
(String name, String publicId, String literalSystemId, String baseSystemId) Adds an external entity declaration.void
addInternalEntity
(String name, String text) Adds an internal entity declaration.void
addInternalEntity
(String name, String text, int paramEntityRefs) Adds an internal entity declaration.void
addUnparsedEntity
(String name, String publicId, String systemId, String baseSystemId, String notation) Adds an unparsed entity declaration.void
Close all opened InputStreams and Readers opened by this parser.static OutputStream
createOutputStream
(String uri) protected Reader
createReader
(InputStream inputStream, String encoding, Boolean isBigEndian) Creates a reader capable of reading the given input stream in the specified encoding.void
static String
expandSystemId
(String systemId, String baseSystemId, boolean strict) Expands a system id and returns the system id as a URI, if it can be expanded.protected static String
Fixes a platform dependent filename to standard URI form.org.apache.xerces.xni.XMLResourceIdentifier
protected org.apache.xerces.impl.XMLEntityManager.EncodingInfo
getEncodingInfo
(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.Returns the entity scanner.getFeatureDefault
(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
getParamEntityRefCount
(String entityName) Returns the number of direct and indirect references to parameter entities in the value of the entity.getPropertyDefault
(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.String[]
Returns a list of feature identifiers that are recognized by this component.String[]
Returns a list of property identifiers that are recognized by this component.boolean
isDeclaredEntity
(String entityName) Checks whether an entity given by name is declared.boolean
isEntityDeclInExternalSubset
(String entityName) Checks whether the declaration of an entity given by name is // in the external subset.boolean
isExternalEntity
(String entityName) Checks whether an entity given by name is external.boolean
Returns true if the document entity is standalone.boolean
isUnparsedEntity
(String entityName) Checks whether an entity given by name is unparsed.void
reset()
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.void
setEntityHandler
(XMLEntityHandler entityHandler) Sets the entity handler.void
setFeature
(String featureId, boolean state) Sets the state of a feature.void
setProperty
(String propertyId, Object value) Sets the value of a property.void
setScannerVersion
(short version) void
setStandalone
(boolean standalone) Sets whether the document entity is standalone.setupCurrentEntity
(String name, org.apache.xerces.xni.parser.XMLInputSource xmlInputSource, boolean literal, boolean isExternal) This method uses the passed-in XMLInputSource to make fCurrentEntity usable for reading.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
(String entityName, boolean literal) Starts a named entity.void
startEntity
(String name, org.apache.xerces.xni.parser.XMLInputSource xmlInputSource, boolean literal, boolean isExternal) Starts an entity.void
-
Field Details
-
DEFAULT_BUFFER_SIZE
public static final int DEFAULT_BUFFER_SIZEDefault buffer size (2048).- See Also:
-
DEFAULT_XMLDECL_BUFFER_SIZE
public static final int DEFAULT_XMLDECL_BUFFER_SIZEDefault buffer size before we've finished with the XMLDecl:- See Also:
-
DEFAULT_INTERNAL_BUFFER_SIZE
public static final int DEFAULT_INTERNAL_BUFFER_SIZEDefault internal entity buffer size (512).- See Also:
-
VALIDATION
Feature identifier: validation.- See Also:
-
EXTERNAL_GENERAL_ENTITIES
Feature identifier: external general entities.- See Also:
-
EXTERNAL_PARAMETER_ENTITIES
Feature identifier: external parameter entities.- See Also:
-
ALLOW_JAVA_ENCODINGS
Feature identifier: allow Java encodings.- See Also:
-
WARN_ON_DUPLICATE_ENTITYDEF
Feature identifier: warn on duplicate EntityDef- See Also:
-
STANDARD_URI_CONFORMANT
Feature identifier: standard uri conformant- See Also:
-
PARSER_SETTINGS
- See Also:
-
SYMBOL_TABLE
Property identifier: symbol table.- See Also:
-
ERROR_REPORTER
Property identifier: error reporter.- See Also:
-
ENTITY_RESOLVER
Property identifier: entity resolver.- See Also:
-
VALIDATION_MANAGER
- See Also:
-
BUFFER_SIZE
property identifier: buffer size.- See Also:
-
SECURITY_MANAGER
property identifier: security manager.- See Also:
-
fValidation
protected boolean fValidationValidation. This feature identifier is: http://xml.org/sax/features/validation -
fExternalGeneralEntities
protected boolean fExternalGeneralEntitiesExternal general entities. This feature identifier is: http://xml.org/sax/features/external-general-entities -
fExternalParameterEntities
protected boolean fExternalParameterEntitiesExternal parameter entities. This feature identifier is: http://xml.org/sax/features/external-parameter-entities -
fAllowJavaEncodings
protected boolean fAllowJavaEncodingsAllow Java encoding names. This feature identifier is: http://apache.org/xml/features/allow-java-encodings -
fWarnDuplicateEntityDef
protected boolean fWarnDuplicateEntityDefwarn on duplicate Entity declaration. http://apache.org/xml/features/warn-on-duplicate-entitydef -
fStrictURI
protected boolean fStrictURIstandard uri conformant (strict uri). http://apache.org/xml/features/standard-uri-conformant -
fSymbolTable
Symbol table. This property identifier is: http://apache.org/xml/properties/internal/symbol-table -
fErrorReporter
Error reporter. This property identifier is: http://apache.org/xml/properties/internal/error-reporter -
fEntityResolver
protected org.apache.xerces.xni.parser.XMLEntityResolver fEntityResolverEntity resolver. This property identifier is: http://apache.org/xml/properties/internal/entity-resolver -
fValidationManager
Validation manager. This property identifier is: http://apache.org/xml/properties/internal/validation-manager -
fBufferSize
protected int fBufferSizeBuffer 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? -
fSecurityManager
-
fStandalone
protected boolean fStandaloneTrue if the document entity is standalone. This should really only be set by the document source (e.g. XMLDocumentScanner). -
fHasPEReferences
protected boolean fHasPEReferencesTrue if the current document contains parameter entity references. -
fInExternalSubset
protected boolean fInExternalSubset -
fEntityHandler
Entity handler. -
fEntityScanner
Current entity scanner. -
fXML10EntityScanner
XML 1.0 entity scanner. -
fXML11EntityScanner
XML 1.1 entity scanner. -
fEntityExpansionLimit
protected int fEntityExpansionLimit -
fEntityExpansionCount
protected int fEntityExpansionCount -
fEntities
Entities. -
fEntityStack
Entity stack. -
fCurrentEntity
Current entity. -
fDeclaredEntities
Shared declared entities. -
fReaderStack
-
-
Constructor Details
-
XMLEntityManager
public XMLEntityManager()Default constructor. -
XMLEntityManager
Constructs an entity manager that shares the specified entity declarations during each parse.REVISIT: We might want to think about the "right" way to expose the list of declared entities. For now, the knowledge how to access the entity declarations is implicit.
-
-
Method Details
-
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
Sets the entity handler. When an entity starts and ends, the entity handler is notified of the change.- Parameters:
entityHandler
- The new entity handler.
-
getCurrentResourceIdentifier
public org.apache.xerces.xni.XMLResourceIdentifier getCurrentResourceIdentifier() -
getCurrentEntity
-
addInternalEntity
Adds an internal entity declaration.Note: This method ignores subsequent entity declarations.
Note: The name should be a unique symbol. The SymbolTable can be used for this purpose.
- Parameters:
name
- The name of the entity.text
- The text of the entity.paramEntityRefs
- Count of direct and indirect references to parameter entities in the value of the entity.- See Also:
-
addInternalEntity
Adds an internal entity declaration.Note: This method ignores subsequent entity declarations.
Note: The name should be a unique symbol. The SymbolTable can be used for this purpose.
- Parameters:
name
- The name of the entity.text
- The text of the entity.- See Also:
-
getParamEntityRefCount
Returns the number of direct and indirect references to parameter entities in the value of the entity. This value will only be non-zero for an internal parameter entity.- Parameters:
entityName
- The name of the entity to check.- Returns:
- Count of direct and indirect references to parameter entities in the value of the entity
-
addExternalEntity
public void addExternalEntity(String name, String publicId, String literalSystemId, String baseSystemId) throws IOException Adds an external entity declaration.Note: This method ignores subsequent entity declarations.
Note: The name should be a unique symbol. The SymbolTable can be used for this purpose.
- Parameters:
name
- The name of the entity.publicId
- The public identifier of the entity.literalSystemId
- The system identifier of the entity.baseSystemId
- 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.- Throws:
IOException
- See Also:
-
isExternalEntity
Checks whether an entity given by name is external.- Parameters:
entityName
- The name of the entity to check.- Returns:
- True if the entity is external, false otherwise (including when the entity is not declared).
-
isEntityDeclInExternalSubset
Checks whether the declaration of an entity given by name is // in the external subset.- Parameters:
entityName
- The name of the entity to check.- Returns:
- True if the entity was declared in the external subset, false otherwise (including when the entity is not declared).
-
addUnparsedEntity
public void addUnparsedEntity(String name, String publicId, String systemId, String baseSystemId, String notation) Adds an unparsed entity declaration.Note: This method ignores subsequent entity declarations.
Note: The name should be a unique symbol. The SymbolTable can be used for this purpose.
- Parameters:
name
- The name of the entity.publicId
- The public identifier of the entity.systemId
- The system identifier of the entity.notation
- The name of the notation.- See Also:
-
isUnparsedEntity
Checks whether an entity given by name is unparsed.- Parameters:
entityName
- The name of the entity to check.- Returns:
- True if the entity is unparsed, false otherwise (including when the entity is not declared).
-
isDeclaredEntity
Checks whether an entity given by name is declared.- Parameters:
entityName
- The name of the entity to check.- Returns:
- True if the entity is declared, false otherwise.
-
resolveEntity
public org.apache.xerces.xni.parser.XMLInputSource resolveEntity(org.apache.xerces.xni.XMLResourceIdentifier resourceIdentifier) throws 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 interfaceorg.apache.xerces.xni.parser.XMLEntityResolver
- Parameters:
resourceIdentifier
- The XMLResourceIdentifier for the resource to resolve.- Returns:
- Returns an input source that wraps the resolved entity. This method will never return null.
- Throws:
IOException
- Thrown on i/o error.org.apache.xerces.xni.XNIException
- Thrown by entity resolver to signal an error.- See Also:
-
startEntity
public void startEntity(String entityName, boolean literal) throws 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:
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 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:
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 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:
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(String name, org.apache.xerces.xni.parser.XMLInputSource xmlInputSource, boolean literal, boolean isExternal) throws 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:
IOException
- Thrown on i/o error.org.apache.xerces.xni.XNIException
- Thrown by entity handler to signal an error.
-
setupCurrentEntity
public String setupCurrentEntity(String name, org.apache.xerces.xni.parser.XMLInputSource xmlInputSource, boolean literal, boolean isExternal) throws IOException, org.apache.xerces.xni.XNIException This method uses the passed-in XMLInputSource to make fCurrentEntity usable for reading.- Parameters:
name
- name of the entity (XML is it's the document entity)xmlInputSource
- the input source, with sufficient information to begin scanning characters.literal
- True if this entity is started within a literal value.isExternal
- whether this entity should be treated as an internal or external entity.- Returns:
- the encoding of the new entity or null if a character stream was employed
- Throws:
IOException
- if anything can't be read XNIException If any parser-specific goes wrong.org.apache.xerces.xni.XNIException
-
setScannerVersion
public void setScannerVersion(short version) -
getEntityScanner
Returns the entity scanner. -
closeReaders
public void closeReaders()Close all opened InputStreams and Readers opened by this parser. -
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 interfaceorg.apache.xerces.xni.parser.XMLComponent
- Parameters:
componentManager
- The component manager.
-
reset
public void reset() -
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 interfaceorg.apache.xerces.xni.parser.XMLComponent
-
setFeature
public void setFeature(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 interfaceorg.apache.xerces.xni.parser.XMLComponent
- Parameters:
featureId
- The feature identifier.state
- The state of the feature.
-
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 interfaceorg.apache.xerces.xni.parser.XMLComponent
-
setProperty
public void setProperty(String propertyId, Object value) throws org.apache.xerces.xni.parser.XMLConfigurationException 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 interfaceorg.apache.xerces.xni.parser.XMLComponent
- Parameters:
propertyId
- The property identifier.value
- The value of the property.
-
getFeatureDefault
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 interfaceorg.apache.xerces.xni.parser.XMLComponent
- Parameters:
featureId
- The feature identifier.- Since:
- Xerces 2.2.0
-
getPropertyDefault
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 interfaceorg.apache.xerces.xni.parser.XMLComponent
- Parameters:
propertyId
- The property identifier.- Since:
- Xerces 2.2.0
-
absolutizeAgainstUserDir
Absolutizes a URI using the current value of the "user.dir" property as the base URI. If the URI is already absolute, this is a no-op.- Parameters:
uri
- the URI to absolutize- Throws:
URI.MalformedURIException
-
expandSystemId
public static String expandSystemId(String systemId, String baseSystemId, boolean strict) throws URI.MalformedURIException 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.
- Throws:
URI.MalformedURIException
-
createOutputStream
- Throws:
IOException
-
getEncodingInfo
protected org.apache.xerces.impl.XMLEntityManager.EncodingInfo getEncodingInfo(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:
- an instance of EncodingInfo which represents the auto-detected encoding.
-
createReader
protected Reader createReader(InputStream inputStream, String encoding, Boolean isBigEndian) throws 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 means unknown or not relevant.- Returns:
- Returns a reader.
- Throws:
IOException
-
fixURI
Fixes a platform dependent filename to standard URI form.- Parameters:
str
- The string to fix.- Returns:
- Returns the fixed URI string.
-