📄 xmlentitymanager.java
字号:
/** Property Manager. This is used from Stax */ protected PropertyManager fPropertyManager ; // settings /** * Validation manager. This property identifier is: * http://apache.org/xml/properties/internal/validation-manager */ protected ValidationManager fValidationManager; // settings /** * 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 int fBufferSize = DEFAULT_BUFFER_SIZE; // stores defaults for entity expansion limit if it has // been set on the configuration. protected SecurityManager fSecurityManager = null; /** * True if the document entity is standalone. This should really * only be set by the document source (e.g. XMLDocumentScanner). */ protected boolean fStandalone; // are the entities being parsed in the external subset? // NOTE: this *is not* the same as whether they're external entities! protected boolean fInExternalSubset = false; // handlers /** Entity handler. */ protected XMLEntityHandler fEntityHandler; /** Current entity scanner */ protected XMLEntityScanner fEntityScanner ; /** XML 1.0 entity scanner. */ protected XMLEntityScanner fXML10EntityScanner; /** XML 1.1 entity scanner. */ protected XMLEntityScanner fXML11EntityScanner; /** entity expansion limit (contains useful data if and only if fSecurityManager is non-null) */ protected int fEntityExpansionLimit = 0; /** count of entities expanded: */ protected int fEntityExpansionCount = 0; // entities /** Entities. */ protected Hashtable fEntities = new Hashtable(); /** Entity stack. */ protected Stack fEntityStack = new Stack(); /** Current entity. */ protected Entity.ScannedEntity fCurrentEntity = null; // shared context /** Shared declared entities. * XXX understand it more deeply, why are we doing this ?? Is it really required ? */ protected Hashtable fDeclaredEntities; protected XMLEntityStorage fEntityStorage ; protected final Object [] defaultEncoding = new Object[]{"UTF-8", null}; // temp vars /** Resource identifer. */ private final XMLResourceIdentifierImpl fResourceIdentifier = new XMLResourceIdentifierImpl(); /** Augmentations for entities. */ private final Augmentations fEntityAugs = new AugmentationsImpl(); /** Pool of character buffers. */ private CharacterBufferPool fBufferPool = new CharacterBufferPool(fBufferSize, DEFAULT_INTERNAL_BUFFER_SIZE); // // Constructors // /** * If this constructor is used to create the object, reset() should be invoked on this object */ public XMLEntityManager() { fEntityStorage = new XMLEntityStorage(this) ; setScannerVersion(Constants.XML_VERSION_1_0); } // <init>() /** Default constructor. */ public XMLEntityManager(PropertyManager propertyManager) { fPropertyManager = propertyManager ; //pass a reference to current entity being scanned //fEntityStorage = new XMLEntityStorage(fCurrentEntity) ; fEntityStorage = new XMLEntityStorage(this) ; fEntityScanner = new XMLEntityScanner(propertyManager, this) ; reset(propertyManager); } // <init>() /** * Constructs an entity manager that shares the specified entity * declarations during each parse. * <p> * <strong>REVISIT:</strong> 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. */ public XMLEntityManager(XMLEntityManager entityManager) { // save shared entity declarations fDeclaredEntities = entityManager != null ? entityManager.getEntityStore().getDeclaredEntities() : null; setScannerVersion(Constants.XML_VERSION_1_0); } // <init>(XMLEntityManager) /** * Adds an internal entity declaration. * <p> * <strong>Note:</strong> This method ignores subsequent entity * declarations. * <p> * <strong>Note:</strong> The name should be a unique symbol. The * SymbolTable can be used for this purpose. * * @param name The name of the entity. * @param text The text of the entity. * * @see SymbolTable */ public void addInternalEntity(String name, String text) { if (!fEntities.containsKey(name)) { Entity entity = new Entity.InternalEntity(name, text, fInExternalSubset); fEntities.put(name, entity); } else{ if(fWarnDuplicateEntityDef){ fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, "MSG_DUPLICATE_ENTITY_DEFINITION", new Object[]{ name }, XMLErrorReporter.SEVERITY_WARNING ); } } } // addInternalEntity(String,String) /** * Adds an external entity declaration. * <p> * <strong>Note:</strong> This method ignores subsequent entity * declarations. * <p> * <strong>Note:</strong> The name should be a unique symbol. The * SymbolTable can be used for this purpose. * * @param name The name of the entity. * @param publicId The public identifier of the entity. * @param literalSystemId The system identifier of the entity. * @param baseSystemId The base system identifier of the entity. * This is the system identifier of the entity * where <em>the entity being added</em> 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. * * @see SymbolTable */ public void addExternalEntity(String name, String publicId, String literalSystemId, String baseSystemId) throws IOException { if (!fEntities.containsKey(name)) { if (baseSystemId == null) { // search for the first external entity on the stack int size = fEntityStack.size(); if (size == 0 && fCurrentEntity != null && fCurrentEntity.entityLocation != null) { baseSystemId = fCurrentEntity.entityLocation.getExpandedSystemId(); } for (int i = size - 1; i >= 0 ; i--) { Entity.ScannedEntity externalEntity = (Entity.ScannedEntity)fEntityStack.elementAt(i); if (externalEntity.entityLocation != null && externalEntity.entityLocation.getExpandedSystemId() != null) { baseSystemId = externalEntity.entityLocation.getExpandedSystemId(); break; } } } Entity entity = new Entity.ExternalEntity(name, new XMLEntityDescriptionImpl(name, publicId, literalSystemId, baseSystemId, expandSystemId(literalSystemId, baseSystemId, false)), null, fInExternalSubset); fEntities.put(name, entity); } else{ if(fWarnDuplicateEntityDef){ fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, "MSG_DUPLICATE_ENTITY_DEFINITION", new Object[]{ name }, XMLErrorReporter.SEVERITY_WARNING ); } } } // addExternalEntity(String,String,String,String) /** * Adds an unparsed entity declaration. * <p> * <strong>Note:</strong> This method ignores subsequent entity * declarations. * <p> * <strong>Note:</strong> The name should be a unique symbol. The * SymbolTable can be used for this purpose. * * @param name The name of the entity. * @param publicId The public identifier of the entity. * @param systemId The system identifier of the entity. * @param notation The name of the notation. * * @see SymbolTable */ public void addUnparsedEntity(String name, String publicId, String systemId, String baseSystemId, String notation) { if (!fEntities.containsKey(name)) { Entity.ExternalEntity entity = new Entity.ExternalEntity(name, new XMLEntityDescriptionImpl(name, publicId, systemId, baseSystemId, null), notation, fInExternalSubset); fEntities.put(name, entity); } else{ if(fWarnDuplicateEntityDef){ fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, "MSG_DUPLICATE_ENTITY_DEFINITION", new Object[]{ name }, XMLErrorReporter.SEVERITY_WARNING ); } } } // addUnparsedEntity(String,String,String,String) /** get the entity storage object from entity manager */ public XMLEntityStorage getEntityStore(){ return fEntityStorage ; } /** return the entity responsible for reading the entity */ public XMLEntityScanner getEntityScanner(){ if(fEntityScanner == null) { // default to 1.0 if(fXML10EntityScanner == null) { fXML10EntityScanner = new XMLEntityScanner(); } fXML10EntityScanner.reset(fSymbolTable, this, fErrorReporter); fEntityScanner = fXML10EntityScanner; } return fEntityScanner; } public void setScannerVersion(short version) { if(version == Constants.XML_VERSION_1_0) { if(fXML10EntityScanner == null) { fXML10EntityScanner = new XMLEntityScanner(); } fXML10EntityScanner.reset(fSymbolTable, this, fErrorReporter); fEntityScanner = fXML10EntityScanner; fEntityScanner.setCurrentEntity(fCurrentEntity); } else { if(fXML11EntityScanner == null) { fXML11EntityScanner = new XML11EntityScanner(); } fXML11EntityScanner.reset(fSymbolTable, this, fErrorReporter); fEntityScanner = fXML11EntityScanner; fEntityScanner.setCurrentEntity(fCurrentEntity); } } /** * This method uses the passed-in XMLInputSource to make * fCurrentEntity usable for reading. * @param name name of the entity (XML is it's the document entity) * @param xmlInputSource the input source, with sufficient information * to begin scanning characters. * @param literal True if this entity is started within a * literal value. * @param isExternal whether this entity should be treated as an internal or external entity. * @throws IOException if anything can't be read * XNIException If any parser-specific goes wrong. * @return the encoding of the new entity or null if a character stream was employed */ public String setupCurrentEntity(String name, XMLInputSource xmlInputSource, boolean literal, boolean isExternal) throws IOException, XNIException { // get information final String publicId = xmlInputSource.getPublicId(); String literalSystemId = xmlInputSource.getSystemId(); String baseSystemId = xmlInputSource.getBaseSystemId(); String encoding = xmlInputSource.getEncoding(); final boolean encodingExternallySpecified = (encoding != null); Boolean isBigEndian = null; // create reader InputStream stream = null; Reader reader = xmlInputSource.getCharacterStream(); // First chance checking strict URI
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -