public class XMLEntityManager extends Object implements XMLComponent, XMLEntityResolver
This component requires the following features and properties from the component manager that uses it:
| Modifier and Type | Class and Description |
|---|---|
protected class |
XMLEntityManager.RewindableInputStream
This class wraps the byte inputstreams we're presented with.
|
| Modifier and Type | Field and Description |
|---|---|
protected static String |
ALLOW_JAVA_ENCODINGS
Feature identifier: allow Java encodings.
|
protected static 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 Object[] |
defaultEncoding |
protected static String |
ENTITY_RESOLVER
Property identifier: entity resolver.
|
protected int |
entityExpansionIndex |
protected static String |
ERROR_REPORTER
Property identifier: error reporter.
|
protected static String |
EXTERNAL_GENERAL_ENTITIES
Feature identifier: external general entities.
|
protected static String |
EXTERNAL_PARAMETER_ENTITIES
Feature identifier: external parameter entities.
|
protected String |
fAccessExternalDTD
used to restrict external access
|
protected boolean |
fAllowJavaEncodings
Allow Java encoding names.
|
protected int |
fBufferSize
Buffer size.
|
protected Entity.ScannedEntity |
fCurrentEntity
Current entity.
|
protected Hashtable |
fEntities
Entities.
|
protected int |
fEntityExpansionCount
count of entities expanded:
|
protected XMLEntityHandler |
fEntityHandler
Entity handler.
|
protected XMLEntityResolver |
fEntityResolver
Entity resolver.
|
protected XMLEntityScanner |
fEntityScanner
Current entity scanner
|
protected 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 XMLLimitAnalyzer |
fLimitAnalyzer |
protected boolean |
fLoadExternalDTD
Load external DTD.
|
protected PropertyManager |
fPropertyManager
Property Manager.
|
protected XMLSecurityManager |
fSecurityManager
Security Manager
|
protected boolean |
fStandalone
True if the document entity is standalone.
|
protected StaxEntityResolverWrapper |
fStaxEntityResolver
Stax Entity Resolver.
|
protected boolean |
fStrictURI
standard uri conformant (strict uri).
|
protected SymbolTable |
fSymbolTable
Symbol table.
|
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.
|
protected static String |
LOAD_EXTERNAL_DTD
Feature identifier: load external DTD.
|
protected static String |
PARSER_SETTINGS |
protected static String |
SECURITY_MANAGER
property identifier: security manager.
|
protected static String |
STANDARD_URI_CONFORMANT
Feature identifier: standard uri conformant
|
protected static String |
STAX_ENTITY_RESOLVER |
protected static String |
SYMBOL_TABLE
Property identifier: symbol table.
|
protected static String |
VALIDATION
Feature identifier: validation.
|
protected static String |
VALIDATION_MANAGER |
protected static String |
WARN_ON_DUPLICATE_ENTITYDEF
Feature identifier: warn on duplicate EntityDef
|
| Constructor and Description |
|---|
XMLEntityManager()
If this constructor is used to create the object, reset() should be invoked on this object
|
XMLEntityManager(PropertyManager propertyManager)
Default constructor.
|
| Modifier and Type | Method and Description |
|---|---|
static void |
absolutizeAgainstUserDir(URI uri)
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 |
addUnparsedEntity(String name,
String publicId,
String systemId,
String baseSystemId,
String notation)
Adds an unparsed entity declaration.
|
void |
closeReaders()
Close all opened InputStreams and Readers opened by this parser.
|
protected Reader |
createReader(InputStream inputStream,
String encoding,
Boolean isBigEndian)
Creates a reader capable of reading the given input stream in
the specified encoding.
|
void |
endEntity() |
void |
endExternalSubset() |
static String |
expandSystemId(String systemId)
Expands a system id and returns the system id as a URI, if
it can be expanded.
|
static String |
expandSystemId(String systemId,
String baseSystemId)
Expands a system id and returns the system id as a URI, if
it can be expanded.
|
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 |
fixURI(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.
|
XMLResourceIdentifier |
getCurrentResourceIdentifier() |
protected 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.
|
XMLEntityScanner |
getEntityScanner()
return the entity responsible for reading the entity
|
XMLEntityStorage |
getEntityStore()
get the entity storage object from entity manager
|
String |
getExpandedSystemId()
Return the expanded system identifier for the current document event.
|
Boolean |
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 |
getLineNumber()
Return the line number where the current document event ends.
|
String |
getLiteralSystemId()
Return the literal system identifier for the current document event.
|
Object |
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 |
getPublicId()
Return the public identifier for the current document event.
|
String[] |
getRecognizedFeatures()
Returns a list of feature identifiers that are recognized by
this component.
|
String[] |
getRecognizedProperties()
Returns a list of property identifiers that are recognized by
this component.
|
Entity.ScannedEntity |
getTopLevelEntity()
Return the top level entity handled by this manager, or null
if no entity was added.
|
boolean |
isDeclaredEntity(String entityName) |
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 |
isStandalone()
Returns true if the document entity is standalone.
|
boolean |
isUnparsedEntity(String entityName) |
void |
reset() |
void |
reset(PropertyManager propertyManager) |
void |
reset(XMLComponentManager componentManager)
Resets the component.
|
XMLInputSource |
resolveEntity(XMLResourceIdentifier resourceIdentifier)
Resolves the specified public and system identifiers.
|
StaxXMLInputSource |
resolveEntityAsPerStax(XMLResourceIdentifier resourceIdentifier) |
void |
setEntityHandler(XMLEntityHandler entityHandler)
Sets the entity handler.
|
void |
setFeature(String featureId,
boolean state)
Sets the state of a feature.
|
static void |
setInstanceFollowRedirects(HttpURLConnection urlCon,
boolean followRedirects)
Attempt to set whether redirects will be followed for an
HttpURLConnection. |
void |
setLimitAnalyzer(XMLLimitAnalyzer fLimitAnalyzer) |
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.
|
String |
setupCurrentEntity(String name,
XMLInputSource xmlInputSource,
boolean literal,
boolean isExternal)
This method uses the passed-in XMLInputSource to make
fCurrentEntity usable for reading.
|
void |
startDocumentEntity(XMLInputSource xmlInputSource)
Starts the document entity.
|
void |
startDTDEntity(XMLInputSource xmlInputSource)
Starts the DTD entity.
|
void |
startEntity(String entityName,
boolean literal)
Starts a named entity.
|
void |
startEntity(String name,
XMLInputSource xmlInputSource,
boolean literal,
boolean isExternal)
Starts an entity.
|
void |
startExternalSubset() |
void |
test() |
public static final int DEFAULT_BUFFER_SIZE
public static final int DEFAULT_XMLDECL_BUFFER_SIZE
public static final int DEFAULT_INTERNAL_BUFFER_SIZE
protected static final String VALIDATION
protected boolean fStrictURI
protected static final String EXTERNAL_GENERAL_ENTITIES
protected static final String EXTERNAL_PARAMETER_ENTITIES
protected static final String ALLOW_JAVA_ENCODINGS
protected static final String WARN_ON_DUPLICATE_ENTITYDEF
protected static final String LOAD_EXTERNAL_DTD
protected static final String SYMBOL_TABLE
protected static final String ERROR_REPORTER
protected static final String STANDARD_URI_CONFORMANT
protected static final String ENTITY_RESOLVER
protected static final String STAX_ENTITY_RESOLVER
protected static final String VALIDATION_MANAGER
protected static final String BUFFER_SIZE
protected static final String SECURITY_MANAGER
protected static final String PARSER_SETTINGS
protected boolean fWarnDuplicateEntityDef
protected boolean fValidation
protected boolean fExternalGeneralEntities
protected boolean fExternalParameterEntities
protected boolean fAllowJavaEncodings
protected boolean fLoadExternalDTD
protected SymbolTable fSymbolTable
protected XMLErrorReporter fErrorReporter
protected XMLEntityResolver fEntityResolver
protected StaxEntityResolverWrapper fStaxEntityResolver
protected PropertyManager fPropertyManager
protected String fAccessExternalDTD
protected ValidationManager fValidationManager
protected int fBufferSize
protected XMLSecurityManager fSecurityManager
protected XMLLimitAnalyzer fLimitAnalyzer
protected int entityExpansionIndex
protected boolean fStandalone
protected boolean fInExternalSubset
protected XMLEntityHandler fEntityHandler
protected XMLEntityScanner fEntityScanner
protected XMLEntityScanner fXML10EntityScanner
protected XMLEntityScanner fXML11EntityScanner
protected int fEntityExpansionCount
protected Hashtable fEntities
protected Stack fEntityStack
protected Entity.ScannedEntity fCurrentEntity
protected XMLEntityStorage fEntityStorage
protected final Object[] defaultEncoding
public XMLEntityManager()
public XMLEntityManager(PropertyManager propertyManager)
public void addInternalEntity(String name, String text)
Note: This method ignores subsequent entity declarations.
Note: The name should be a unique symbol. The SymbolTable can be used for this purpose.
name - The name of the entity.text - The text of the entity.SymbolTablepublic void addExternalEntity(String name, String publicId, String literalSystemId, String baseSystemId) throws IOException
Note: This method ignores subsequent entity declarations.
Note: The name should be a unique symbol. The SymbolTable can be used for this purpose.
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.IOExceptionSymbolTablepublic void addUnparsedEntity(String name, String publicId, String systemId, String baseSystemId, String notation)
Note: This method ignores subsequent entity declarations.
Note: The name should be a unique symbol. The SymbolTable can be used for this purpose.
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.SymbolTablepublic XMLEntityStorage getEntityStore()
public XMLEntityScanner getEntityScanner()
public void setScannerVersion(short version)
public String setupCurrentEntity(String name, XMLInputSource xmlInputSource, boolean literal, boolean isExternal) throws IOException, XNIException
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.IOException - if anything can't be read
XNIException If any parser-specific goes wrong.XNIExceptionpublic boolean isExternalEntity(String entityName)
entityName - The name of the entity to check.public boolean isEntityDeclInExternalSubset(String entityName)
entityName - The name of the entity to check.public void setStandalone(boolean standalone)
standalone - True if document entity is standalone.public boolean isStandalone()
public boolean isDeclaredEntity(String entityName)
public boolean isUnparsedEntity(String entityName)
public XMLResourceIdentifier getCurrentResourceIdentifier()
public void setEntityHandler(XMLEntityHandler entityHandler)
entityHandler - The new entity handler.public StaxXMLInputSource resolveEntityAsPerStax(XMLResourceIdentifier resourceIdentifier) throws IOException
IOExceptionpublic XMLInputSource resolveEntity(XMLResourceIdentifier resourceIdentifier) throws IOException, XNIException
resolveEntity in interface XMLEntityResolverpublicId - 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.IOException - Thrown on i/o error.XNIException - Thrown by entity resolver to signal an error.XMLResourceIdentifierpublic void startEntity(String entityName, boolean literal) throws IOException, XNIException
entityName - The name of the entity to start.literal - True if this entity is started within a literal
value.IOException - Thrown on i/o error.XNIException - Thrown by entity handler to signal an error.public void startDocumentEntity(XMLInputSource xmlInputSource) throws IOException, XNIException
xmlInputSource - The input source of the document entity.IOException - Thrown on i/o error.XNIException - Thrown by entity handler to signal an error.public void startDTDEntity(XMLInputSource xmlInputSource) throws IOException, XNIException
xmlInputSource - The input source of the DTD entity.IOException - Thrown on i/o error.XNIException - Thrown by entity handler to signal an error.public void startExternalSubset()
public void endExternalSubset()
public void startEntity(String name, XMLInputSource xmlInputSource, boolean literal, boolean isExternal) throws IOException, XNIException
This method can be used to insert an application defined XML entity stream into the parsing stream.
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.IOException - Thrown on i/o error.XNIException - Thrown by entity handler to signal an error.public Entity.ScannedEntity getCurrentEntity()
public Entity.ScannedEntity getTopLevelEntity()
public void closeReaders()
public void endEntity()
throws IOException,
XNIException
IOExceptionXNIExceptionpublic void reset(PropertyManager propertyManager)
public void reset(XMLComponentManager componentManager) throws XMLConfigurationException
reset in interface XMLComponentcomponentManager - The component manager.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.XMLConfigurationExceptionpublic void reset()
public String[] getRecognizedFeatures()
getRecognizedFeatures in interface XMLComponentpublic void setFeature(String featureId, boolean state) throws XMLConfigurationException
Note: Components should silently ignore features that do not affect the operation of the component.
setFeature in interface XMLComponentfeatureId - The feature identifier.state - The state of the feature.SAXNotRecognizedException - The component should not throw
this exception.SAXNotSupportedException - The component should not throw
this exception.XMLConfigurationException - Thrown for configuration error.
In general, components should
only throw this exception if
it is really
a critical error.public void setProperty(String propertyId, Object value)
Note: Components should silently ignore properties that do not affect the operation of the component.
setProperty in interface XMLComponentpropertyId - The property identifier.value - The value of the property.SAXNotRecognizedException - The component should not throw
this exception.SAXNotSupportedException - The component should not throw
this exception.public void setLimitAnalyzer(XMLLimitAnalyzer fLimitAnalyzer)
public String[] getRecognizedProperties()
getRecognizedProperties in interface XMLComponentpublic Boolean getFeatureDefault(String featureId)
getFeatureDefault in interface XMLComponentfeatureId - The feature identifier.public Object getPropertyDefault(String propertyId)
getPropertyDefault in interface XMLComponentpropertyId - The property identifier.public static String expandSystemId(String systemId)
systemId - The systemId to be expanded.public static void absolutizeAgainstUserDir(URI uri) throws URI.MalformedURIException
uri - the URI to absolutizeURI.MalformedURIExceptionpublic static String expandSystemId(String systemId, String baseSystemId)
systemId - The systemId to be expanded.public static String expandSystemId(String systemId, String baseSystemId, boolean strict) throws URI.MalformedURIException
systemId - The systemId to be expanded.URI.MalformedURIExceptionpublic static void setInstanceFollowRedirects(HttpURLConnection urlCon, boolean followRedirects)
HttpURLConnection.
This may fail on earlier JDKs which do not support setting this preference.protected Object[] getEncodingName(byte[] b4, int count)
b4 - The first four bytes of the input.count - The number of bytes actually read.protected Reader createReader(InputStream inputStream, String encoding, Boolean isBigEndian) throws IOException
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.IOExceptionpublic String getPublicId()
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.
public String getExpandedSystemId()
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.
public String getLiteralSystemId()
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.
public int getLineNumber()
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.
public int getColumnNumber()
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.
protected static String fixURI(String str)
str - The string to fix.public void test()
Copyright © 2018–2021 mhoffrogge. All rights reserved.