Save This Page
Home » openjdk-7 » com.sun.org.apache.xerces.internal » impl » [javadoc | source]
com.sun.org.apache.xerces.internal.impl
public class: XMLEntityManager [javadoc | source]
java.lang.Object
   com.sun.org.apache.xerces.internal.impl.XMLEntityManager

All Implemented Interfaces:
    XMLComponent, 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:

Nested Class Summary:
protected final class  XMLEntityManager.RewindableInputStream  This class wraps the byte inputstreams we're presented with. We need it because java.io.InputStreams don't provide functionality to reread processed bytes, and they have a habit of reading more than one character when you call their read() methods. This means that, once we discover the true (declared) encoding of a document, we can neither backtrack to read the whole doc again nor start reading where we are with a new reader. This class allows rewinding an inputStream by allowing a mark to be set, and the stream reset to that position. The class assumes that it needs to read one character per invocation when it's read() method is inovked, but uses the underlying InputStream's read(char[], offset length) method--it won't buffer data read this way! 
Field Summary
public static final  int DEFAULT_BUFFER_SIZE    Default buffer size (2048). 
public static final  int DEFAULT_XMLDECL_BUFFER_SIZE    Default buffer size before we've finished with the XMLDecl: 
public static final  int DEFAULT_INTERNAL_BUFFER_SIZE    Default internal entity buffer size (1024). 
protected static final  String VALIDATION    Feature identifier: validation. 
protected  boolean fStrictURI    standard uri conformant (strict uri). http://apache.org/xml/features/standard-uri-conformant 
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 static final  String ALLOW_JAVA_ENCODINGS    Feature identifier: allow Java encodings. 
protected static final  String WARN_ON_DUPLICATE_ENTITYDEF    Feature identifier: warn on duplicate EntityDef 
protected static final  String SYMBOL_TABLE    Property identifier: symbol table. 
protected static final  String ERROR_REPORTER    Property identifier: error reporter. 
protected static final  String STANDARD_URI_CONFORMANT    Feature identifier: standard uri conformant 
protected static final  String ENTITY_RESOLVER    Property identifier: entity resolver. 
protected static final  String STAX_ENTITY_RESOLVER     
protected static final  String VALIDATION_MANAGER     
protected static final  String BUFFER_SIZE    property identifier: buffer size. 
protected static final  String SECURITY_MANAGER    property identifier: security manager. 
protected static final  String PARSER_SETTINGS     
protected  boolean fWarnDuplicateEntityDef    warn on duplicate Entity declaration. http://apache.org/xml/features/warn-on-duplicate-entitydef 
protected  boolean fValidation    Validation. This feature identifier is: http://xml.org/sax/features/validation 
protected  boolean fExternalGeneralEntities    External general entities. This feature identifier is: http://xml.org/sax/features/external-general-entities 
protected  boolean fExternalParameterEntities    External parameter entities. This feature identifier is: http://xml.org/sax/features/external-parameter-entities 
protected  boolean fAllowJavaEncodings    Allow Java encoding names. This feature identifier is: http://apache.org/xml/features/allow-java-encodings 
protected  SymbolTable fSymbolTable    Symbol table. This property identifier is: http://apache.org/xml/properties/internal/symbol-table 
protected  XMLErrorReporter fErrorReporter    Error reporter. This property identifier is: http://apache.org/xml/properties/internal/error-reporter 
protected  XMLEntityResolver fEntityResolver    Entity resolver. This property identifier is: http://apache.org/xml/properties/internal/entity-resolver 
protected  StaxEntityResolverWrapper fStaxEntityResolver    Stax Entity Resolver. This property identifier is XMLInputFactory.ENTITY_RESOLVER 
protected  PropertyManager fPropertyManager    Property Manager. This is used from Stax 
protected  ValidationManager fValidationManager    Validation manager. This property identifier is: http://apache.org/xml/properties/internal/validation-manager 
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? 
protected  SecurityManager fSecurityManager     
protected  boolean fStandalone    True if the document entity is standalone. This should really only be set by the document source (e.g. XMLDocumentScanner). 
protected  boolean fInExternalSubset     
protected  XMLEntityHandler fEntityHandler    Entity handler. 
protected  XMLEntityScanner fEntityScanner    Current entity scanner 
protected  XMLEntityScanner fXML10EntityScanner    XML 1.0 entity scanner. 
protected  XMLEntityScanner fXML11EntityScanner    XML 1.1 entity scanner. 
protected  int fEntityExpansionLimit    entity expansion limit (contains useful data if and only if fSecurityManager is non-null) 
protected  int fEntityExpansionCount    count of entities expanded: 
protected  Hashtable fEntities    Entities. 
protected  Stack fEntityStack    Entity stack. 
protected  Entity.ScannedEntity fCurrentEntity    Current entity. 
protected  Hashtable fDeclaredEntities    Shared declared entities. XXX understand it more deeply, why are we doing this ?? Is it really required ? 
protected  XMLEntityStorage fEntityStorage     
protected final  Object[] defaultEncoding     
protected  Vector fOwnReaders     
Constructor:
 public XMLEntityManager() 
 public XMLEntityManager(PropertyManager propertyManager) 
    Default constructor.
 public XMLEntityManager(XMLEntityManager entityManager) 
    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 from com.sun.org.apache.xerces.internal.impl.XMLEntityManager Summary:
absolutizeAgainstUserDir,   addExternalEntity,   addInternalEntity,   addUnparsedEntity,   closeReaders,   createReader,   endEntity,   endExternalSubset,   escapeNonUSAscii,   expandSystemId,   expandSystemId,   expandSystemId,   fixURI,   getColumnNumber,   getCurrentEntity,   getCurrentResourceIdentifier,   getEncodingName,   getEntityScanner,   getEntityStore,   getExpandedSystemId,   getFeatureDefault,   getLineNumber,   getLiteralSystemId,   getPropertyDefault,   getPublicId,   getRecognizedFeatures,   getRecognizedProperties,   getTopLevelEntity,   isDeclaredEntity,   isEntityDeclInExternalSubset,   isExternalEntity,   isStandalone,   isUnparsedEntity,   print,   reset,   reset,   reset,   resolveEntity,   resolveEntityAsPerStax,   setEntityHandler,   setFeature,   setInstanceFollowRedirects,   setProperty,   setScannerVersion,   setStandalone,   setupCurrentEntity,   startDTDEntity,   startDocumentEntity,   startEntity,   startEntity,   startExternalSubset,   test
Methods from java.lang.Object:
equals,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from com.sun.org.apache.xerces.internal.impl.XMLEntityManager Detail:
 public static  void absolutizeAgainstUserDir(URI uri) throws URI.MalformedURIException 
    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.
 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.

 public  void addInternalEntity(String name,
    String text) 
    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.

 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.

 public  void closeReaders() 
    Close all opened InputStreams and Readers opened by this parser.
 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.
 public  void endEntity() throws IOException, XNIException 
 public  void endExternalSubset() 
 protected static String escapeNonUSAscii(String str) 
    Escape invalid URI characters. Passed a URI that contains invalid characters (like spaces, non-ASCII Unicode characters, and the like), this function percent encodes the invalid characters per the URI specification (i.e., as a sequence of %-encoded UTF-8 octets). N.B. There are two problems. If the URI contains a '%' character, that might be an indication that the URI has already been escaped by the author, or it might be an invalid '%'. In the former case, it's important not to escape it, or we'll wind up with invalid, doubly-escaped '%'s. In the latter, the URI is broken if we don't encode it. Similarly, a '#' character might be the start of a fragment identifier or it might be an invalid '#'. Given that the former is vastly more likely than the latter in each case (most users are familiar with the magic status of '%' and '#' and they occur relatively infrequently in filenames, and if the user parses a proper Java File, we will already have %-escaped the URI), we simply assume that %'s and #'s are legit. Very rarely, we may be wrong. If so, tell the user to fix the clearly broken URI.
 public static String expandSystemId(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.
 public static String expandSystemId(String systemId,
    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.
 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.
 protected static String fixURI(String str) 
    Fixes a platform dependent filename to standard URI form.
 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.

 public Entity.ScannedEntity getCurrentEntity() 
    Return the current entity being scanned. Current entity is SET using startEntity function.
 public 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.
 public XMLEntityScanner getEntityScanner() 
    return the entity responsible for reading the entity
 public XMLEntityStorage getEntityStore() 
    get the entity storage object from entity manager
 public 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.

 public 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.
 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.

 public 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.

 public 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.
 public 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.

 public 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.
 public 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.
 public Entity.ScannedEntity getTopLevelEntity() 
    Return the top level entity handled by this manager, or null if no entity was added.
 public boolean isDeclaredEntity(String entityName) 
 public boolean isEntityDeclInExternalSubset(String entityName) 
    Checks whether the declaration of an entity given by name is // in the external subset.
 public boolean isExternalEntity(String entityName) 
    Checks whether an entity given by name is external.
 public boolean isStandalone() 
    Returns true if the document entity is standalone.
 public boolean isUnparsedEntity(String entityName) 
 final  void print() 
    Prints the contents of the buffer.
 public  void reset() 
 public  void reset(PropertyManager propertyManager) 
 public  void reset(XMLComponentManager componentManager) throws XMLConfigurationException 
    Resets the component. The component can query the component manager about any features and properties that affect the operation of the component.
 public XMLInputSource resolveEntity(XMLResourceIdentifier resourceIdentifier) throws IOException, 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.
 public StaxXMLInputSource resolveEntityAsPerStax(XMLResourceIdentifier resourceIdentifier) throws IOException 
 public  void setEntityHandler(XMLEntityHandler entityHandler) 
    Sets the entity handler. When an entity starts and ends, the entity handler is notified of the change.
 public  void setFeature(String featureId,
    boolean state) throws 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.

 public static  void setInstanceFollowRedirects(HttpURLConnection urlCon,
    boolean followRedirects) 
    Attempt to set whether redirects will be followed for an HttpURLConnection. This may fail on earlier JDKs which do not support setting this preference.
 public  void setProperty(String propertyId,
    Object value) 
    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.

 public  void setScannerVersion(short version) 
 public  void setStandalone(boolean standalone) 
    Sets whether the document entity is standalone.
 public String setupCurrentEntity(String name,
    XMLInputSource xmlInputSource,
    boolean literal,
    boolean isExternal) throws IOException, XNIException 
    This method uses the passed-in XMLInputSource to make fCurrentEntity usable for reading.
 public  void startDTDEntity(XMLInputSource xmlInputSource) throws IOException, XNIException 
    Starts the DTD entity. The DTD entity has the "[dtd]" pseudo-name.
 public  void startDocumentEntity(XMLInputSource xmlInputSource) throws IOException, XNIException 
    Starts the document entity. The document entity has the "[xml]" pseudo-name.
 public  void startEntity(String entityName,
    boolean literal) throws IOException, XNIException 
    Starts a named entity.
 public  void startEntity(String name,
    XMLInputSource xmlInputSource,
    boolean literal,
    boolean isExternal) throws IOException, XNIException 
    Starts an entity.

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

 public  void startExternalSubset() 
 public  void test()