⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xmlentitymanager.java

📁 java1.6众多例子参考
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
    // indicate start of external subset so that    // location of entity decls can be tracked    public void startExternalSubset() {        fInExternalSubset = true;    }        public void endExternalSubset() {        fInExternalSubset = false;    }        /**     * Starts an entity.     * <p>     * This method can be used to insert an application defined XML     * entity stream into the parsing stream.     *     * @param name           The name of the entity.     * @param xmlInputSource The input source of the entity.     * @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  Thrown on i/o error.     * @throws XNIException Thrown by entity handler to signal an error.     */    public void startEntity(String name,            XMLInputSource xmlInputSource,            boolean literal, boolean isExternal)            throws IOException, XNIException {               String encoding = setupCurrentEntity(name, xmlInputSource, literal, isExternal);                //when entity expansion limit is set by the Application, we need to        //check for the entity expansion limit set by the parser, if number of entity        //expansions exceeds the entity expansion limit, parser will throw fatal error.        // Note that this represents the nesting level of open entities.        fEntityExpansionCount++;        if( fSecurityManager != null && fEntityExpansionCount > fEntityExpansionLimit ){            fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN,                                             "EntityExpansionLimitExceeded",                                             new Object[]{new Integer(fEntityExpansionLimit) },                                             XMLErrorReporter.SEVERITY_FATAL_ERROR );            // is there anything better to do than reset the counter?            // at least one can envision debugging applications where this might            // be useful...            fEntityExpansionCount = 0;        }        // call handler        if (fEntityHandler != null) {            fEntityHandler.startEntity(name, fResourceIdentifier, encoding, null);        }            } // startEntity(String,XMLInputSource)        /**     * Return the current entity being scanned. Current entity is SET using startEntity function.     * @return Entity.ScannedEntity     */        public Entity.ScannedEntity getCurrentEntity(){        return fCurrentEntity ;    }        /**     * Return the top level entity handled by this manager, or null     * if no entity was added.     */    public Entity.ScannedEntity getTopLevelEntity() {        return (Entity.ScannedEntity)             (fEntityStack.empty() ? null : fEntityStack.elementAt(0));    }        // a list of Readers ever seen    protected Vector fOwnReaders = new Vector();        /**     * Close all opened InputStreams and Readers opened by this parser.     */    public void closeReaders() {        // close all readers        for (int i = fOwnReaders.size()-1; i >= 0; i--) {            try {                ((Reader)fOwnReaders.elementAt(i)).close();            } catch (IOException e) {                // ignore            }        }        // and clear the list        fOwnReaders.removeAllElements();    }        public void endEntity() throws IOException, XNIException {                // call handler        if (DEBUG_BUFFER) {            System.out.print("(endEntity: ");            print();            System.out.println();        }                        //pop the entity from the stack         Entity.ScannedEntity entity = fEntityStack.size() > 0 ? (Entity.ScannedEntity)fEntityStack.pop() : null ;                if (fEntityHandler != null) {            //so this is the last opened entity, signal it to current fEntityHandler using Augmentation            if(entity == null){                fEntityAugs.removeAllItems();                fEntityAugs.putItem(Constants.LAST_ENTITY, Boolean.TRUE);                fEntityHandler.endEntity(fCurrentEntity.name, fEntityAugs);                fEntityAugs.removeAllItems();            }else{                fEntityHandler.endEntity(fCurrentEntity.name, null);            }        }        //check if it is a document entity        boolean documentEntity = fCurrentEntity.name == XMLEntity;                //close the reader        if(fCurrentEntity != null){            //close the reader            try{                fCurrentEntity.reader.close();            }catch(IOException ex){                throw new XNIException(ex);            }        }                //set popped entity as current entity        fCurrentEntity = entity;        fEntityScanner.setCurrentEntity(fCurrentEntity);                //check if there are any entity left in the stack -- if there are        //no entries EOF has been reached.                // throw exception when it is the last entity but it is not a document entity                if(fCurrentEntity == null & !documentEntity){            throw new EOFException() ;        }                 if (DEBUG_BUFFER) {            System.out.print(")endEntity: ");            print();            System.out.println();        }            } // endEntity()            //    // XMLComponent methods    //    public void reset(PropertyManager propertyManager){        //reset fEntityStorage        fEntityStorage.reset(propertyManager);        //reset XMLEntityReaderImpl        fEntityScanner.reset(propertyManager);        // xerces properties        fSymbolTable = (SymbolTable)propertyManager.getProperty(Constants.XERCES_PROPERTY_PREFIX + Constants.SYMBOL_TABLE_PROPERTY);        fErrorReporter = (XMLErrorReporter)propertyManager.getProperty(Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_REPORTER_PROPERTY);        try {            fStaxEntityResolver = (StaxEntityResolverWrapper)propertyManager.getProperty(STAX_ENTITY_RESOLVER);        } catch (XMLConfigurationException e) {            fStaxEntityResolver = null;        }                // initialize state        //fStandalone = false;        fEntities.clear();        fEntityStack.removeAllElements();        fCurrentEntity = null;        fValidation = false;        fExternalGeneralEntities = true;        fExternalParameterEntities = true;        fAllowJavaEncodings = true ;                //test();    }        /**     * Resets the component. The component can query the component manager     * about any features and properties that affect the operation of the     * component.     *     * @param componentManager The component manager.     *     * @throws 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.     */    public void reset(XMLComponentManager componentManager)    throws XMLConfigurationException {        boolean parser_settings;        try {                parser_settings = componentManager.getFeature(PARSER_SETTINGS);        } catch (XMLConfigurationException e) {                parser_settings = true;        }        if (!parser_settings) {            // parser settings have not been changed            reset();            if(fEntityScanner != null){                fEntityScanner.reset(componentManager);            }            if(fEntityStorage != null){                fEntityStorage.reset(componentManager);                        }            return;        }                // sax features        try {            fValidation = componentManager.getFeature(VALIDATION);        } catch (XMLConfigurationException e) {            fValidation = false;        }        try {            fExternalGeneralEntities = componentManager.getFeature(EXTERNAL_GENERAL_ENTITIES);        } catch (XMLConfigurationException e) {            fExternalGeneralEntities = true;        }        try {            fExternalParameterEntities = componentManager.getFeature(EXTERNAL_PARAMETER_ENTITIES);        } catch (XMLConfigurationException e) {            fExternalParameterEntities = true;        }                // xerces features        try {            fAllowJavaEncodings = componentManager.getFeature(ALLOW_JAVA_ENCODINGS);        } catch (XMLConfigurationException e) {            fAllowJavaEncodings = false;        }                try {            fWarnDuplicateEntityDef = componentManager.getFeature(WARN_ON_DUPLICATE_ENTITYDEF);        } catch (XMLConfigurationException e) {            fWarnDuplicateEntityDef = false;        }        try {            fStrictURI = componentManager.getFeature(STANDARD_URI_CONFORMANT);        } catch (XMLConfigurationException e) {            fStrictURI = false;        }                // xerces properties        fSymbolTable = (SymbolTable)componentManager.getProperty(SYMBOL_TABLE);        fErrorReporter = (XMLErrorReporter)componentManager.getProperty(ERROR_REPORTER);        try {            fEntityResolver = (XMLEntityResolver)componentManager.getProperty(ENTITY_RESOLVER);        } catch (XMLConfigurationException e) {            fEntityResolver = null;        }                try {            fStaxEntityResolver = (StaxEntityResolverWrapper)componentManager.getProperty(STAX_ENTITY_RESOLVER);        } catch (XMLConfigurationException e) {            fStaxEntityResolver = null;        }                try {            fValidationManager = (ValidationManager)componentManager.getProperty(VALIDATION_MANAGER);        }        catch (XMLConfigurationException e) {            fValidationManager = null;        }        try {            fSecurityManager = (SecurityManager)componentManager.getProperty(SECURITY_MANAGER);        }        catch (XMLConfigurationException e) {            fSecurityManager = null;        }        //reset general state        reset();                fEntityScanner.reset(componentManager);        fEntityStorage.reset(componentManager);            } // reset(XMLComponentManager)        // reset general state.  Should not be called other than by    // a class acting as a component manager but not    // implementing that interface for whatever reason.    public void reset() {        fEntityExpansionLimit = (fSecurityManager != null)?fSecurityManager.getEntityExpansionLimit():0;                        // initialize state        fStandalone = false;        fEntities.clear();        fEntityStack.removeAllElements();        fEntityExpansionCount = 0;        fCurrentEntity = null;        // reset scanner        if(fXML10EntityScanner != null){            fXML10EntityScanner.reset(fSymbolTable, this, fErrorReporter);        }        if(fXML11EntityScanner != null) {            fXML11EntityScanner.reset(fSymbolTable, this, fErrorReporter);        }        // DEBUG        if (DEBUG_ENTITIES) {            addInternalEntity("text", "Hello, World.");            addInternalEntity("empty-element", "<foo/>");            addInternalEntity("balanced-element", "<foo></foo>");            addInternalEntity("balanced-element-with-text", "<foo>Hello, World</foo>");            addInternalEntity("balanced-element-with-entity", "<foo>&text;</foo>");            addInternalEntity("unbalanced-entity", "<foo>");            addInternalEntity("recursive-entity", "<foo>&recursive-entity2;</foo>");            addInternalEntity("recursive-entity2", "<bar>&recursive-entity3;</bar>");            addInternalEntity("recursive-entity3", "<baz>&recursive-entity;</baz>");            try {                addExternalEntity("external-text", null, "external-text.ent", "test/external-text.xml");                addExternalEnti

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -