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

📄 xmldocumentscannerimpl.java

📁 java1.6众多例子参考
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
                                setDriver(fContentDriver);                                //from now onwards this would be handled by fContentDriver,in the same next() call                                return fContentDriver.next();                                                            } else {                                reportFatalError("MarkupNotRecognizedInProlog",                                        null);                            }                            break;                        }                    }                } while (fScannerState == SCANNER_STATE_PROLOG || fScannerState == SCANNER_STATE_START_OF_MARKUP );                                switch(fScannerState){                    /**                    //this part is handled by FragmentContentHandler                    case SCANNER_STATE_ROOT_ELEMENT: {                        //we have read '<' and beginning of reading the start element tag                        setScannerState(SCANNER_STATE_START_ELEMENT_TAG);                        setDriver(fContentDriver);                        //from now onwards this would be handled by fContentDriver,in the same next() call                        return fContentDriver.next();                    }                     */                    case SCANNER_STATE_COMMENT: {                        //this function fills the data..                        scanComment();                        setScannerState(SCANNER_STATE_PROLOG);                        return XMLEvent.COMMENT;                        //setScannerState(SCANNER_STATE_PROLOG);                        //break;                    }                    case SCANNER_STATE_PI: {                        fContentBuffer.clear() ;                        scanPI(fContentBuffer);                        setScannerState(SCANNER_STATE_PROLOG);                        return XMLEvent.PROCESSING_INSTRUCTION;                    }                    case SCANNER_STATE_DOCTYPE: {                                                if (fSeenDoctypeDecl) {                            reportFatalError("AlreadySeenDoctype", null);                        }                        fSeenDoctypeDecl = true;                                                // scanDoctypeDecl() sends XNI doctypeDecl event that                        // in SAX is converted to startDTD() event.                        if (scanDoctypeDecl(fDisallowDoctype)) {                            //allow parsing of entity decls to continue in order to stay well-formed                            setScannerState(SCANNER_STATE_DTD_INTERNAL_DECLS);                            fSeenInternalSubset = true;                            if(fDTDDriver == null){                                fDTDDriver = new DTDDriver();                            }                            setDriver(fContentDriver);                            //always return DTD event, the event however, will not contain any entities                            return fDTDDriver.next();                            // If no DTD support, ignore and continue parsing                            //return fDisallowDoctype ? next() : dtdEvent;                        }                                                /** xxx:check this part again                        if(fSeenDoctypeDecl){                            Entity entity = fEntityScanner.getCurrentEntity();                            if(entity instanceof Entity.ScannedEntity){                                fEndPos = ((Entity.ScannedEntity)entity).position;                            }                            fReadingDTD = false;                        }                         */                                                // handle external subset                        if (fDoctypeSystemId != null) {                            if (((fValidation || fLoadExternalDTD)                                 && (fValidationManager == null || !fValidationManager.isCachedDTD()))) {                                if (!fDisallowDoctype)                                    setScannerState(SCANNER_STATE_DTD_EXTERNAL);                                else                                    setScannerState(SCANNER_STATE_PROLOG);                                setDriver(fContentDriver);                                if(fDTDDriver == null)                                    fDTDDriver = new DTDDriver();                                return fDTDDriver.next();                                                            }                        }                        else if (fExternalSubsetSource != null) {                            if (((fValidation || fLoadExternalDTD)                                 && (fValidationManager == null || !fValidationManager.isCachedDTD()))) {                                // This handles the case of a DOCTYPE that had neither an internal subset or an external subset.                                fDTDScanner.setInputSource(fExternalSubsetSource);                                fExternalSubsetSource = null;                                if (!fDisallowDoctype)                                    setScannerState(SCANNER_STATE_DTD_EXTERNAL_DECLS);                                else                                    setScannerState(SCANNER_STATE_PROLOG);                                setDriver(fContentDriver);                                if(fDTDDriver == null)                                    fDTDDriver = new DTDDriver();                                return fDTDDriver.next();                            }                       	                        }                        // Send endDTD() call if:                         // a) systemId is null or if an external subset resolver could not locate an external subset.                        // b) "load-external-dtd" and validation are false                        // c) DTD grammar is cached                        // in XNI this results in 3 events:  doctypeDecl, startDTD, endDTD                        // in SAX this results in 2 events: startDTD, endDTD                        if (fDTDScanner != null) {                            fDTDScanner.setInputSource(null);                        }                        setScannerState(SCANNER_STATE_PROLOG);                        return XMLEvent.DTD;                    }                                        case SCANNER_STATE_CONTENT: {                        reportFatalError("ContentIllegalInProlog", null);                        fEntityScanner.scanChar();                    }                    case SCANNER_STATE_REFERENCE: {                        reportFatalError("ReferenceIllegalInProlog", null);                    }                                        /**                     * if (complete) {                     * if (fEntityScanner.scanChar() != '<') {                     * reportFatalError("RootElementRequired", null);                     * }                     * setScannerState(SCANNER_STATE_ROOT_ELEMENT);                     * setDriver(fContentDriver);                     * }                     */                }            }            // premature end of file            catch (EOFException e) {                reportFatalError("PrematureEOF", null);                //xxx  what should be returned here.... ???                return -1 ;                //throw e;            }            //xxx  what should be returned here.... ???            return -1;                    }                    } // class PrologDriver        /**     * Driver to handle the internal and external DTD subsets.     *     * @author Andy Clark, IBM     */    protected final class DTDDriver            implements Driver {                //        // Driver methods        //                public int next() throws IOException, XNIException{            // throw new XNIException("DTD Parsing is currently not supported");            if(DEBUG_NEXT){                System.out.println("Now in DTD Driver");            }                        dispatch(true);                        if(DEBUG_NEXT){                System.out.println("After calling dispatch(true) -- At this point whole DTD is read.");            }                        //xxx: remove this hack and align this with reusing DTD components            //currently this routine will only be executed from Stax            if(fPropertyManager != null){                dtdGrammarUtil =  new DTDGrammarUtil(((XMLDTDScannerImpl)fDTDScanner).getGrammar(),fSymbolTable, fNamespaceContext);            }                        return XMLEvent.DTD ;        }                /**         * Dispatch an XML "event".         *         * @param complete True if this driver is intended to scan         *                 and dispatch as much as possible.         *         * @return True if there is more to dispatch either from this         *          or a another driver.         *         * @throws IOException  Thrown on i/o error.         * @throws XNIException Thrown on parse error.         */        public boolean dispatch(boolean complete)        throws IOException, XNIException {            fEntityManager.setEntityHandler(null);            try {                boolean again;                XMLResourceIdentifierImpl resourceIdentifier = new XMLResourceIdentifierImpl();                if( fDTDScanner == null){                                        if (fEntityManager.getEntityScanner() instanceof XML11EntityScanner){                        fDTDScanner = new XML11DTDScannerImpl();                    } else                                        fDTDScanner = new XMLDTDScannerImpl();                                        ((XMLDTDScannerImpl)fDTDScanner).reset(fPropertyManager);                }                do {                    again = false;                    switch (fScannerState) {                        case SCANNER_STATE_DTD_INTERNAL_DECLS: {                            // REVISIT: Should there be a feature for                            //          the "complete" parameter?                            boolean completeDTD = true;                                                        boolean moreToScan = fDTDScanner.scanDTDInternalSubset(completeDTD, fStandalone, fHasExternalDTD && fLoadExternalDTD);                            Entity entity = fEntityScanner.getCurrentEntity();                            if(entity instanceof Entity.ScannedEntity){                                fEndPos=((Entity.ScannedEntity)entity).position;                            }                            fReadingDTD=false;                            if (!moreToScan) {                                // end doctype declaration                                if (!fEntityScanner.skipChar(']')) {                                    reportFatalError("EXPECTED_SQUARE_BRACKET_TO_CLOSE_INTERNAL_SUBSET",                                            null);                                }                                fEntityScanner.skipSpaces();                                if (!fEntityScanner.skipChar('>')) {                                    reportFatalError("DoctypedeclUnterminated", new Object[]{fDoctypeName});                                }                                fMarkupDepth--;                                                                if (fDisallowDoctype) {                                    //simply reset the entity store without having to mess around                                    //with the DTD Scanner code                                    fEntityStore = fEntityManager.getEntityStore();                                    fEntityStore.reset();                                } else {                                    // scan external subset next unless we are ignoring DTDs                                    if (fDoctypeSystemId != null && (fValidation || fLoadExternalDTD)) {                                        setScannerState(SCANNER_STATE_DTD_EXTERNAL);                                        break;                                    }                                }                                                                setEndDTDScanState();                                return true;                            }                            break;                        }                        case SCANNER_STATE_DTD_EXTERNAL: {                            /**                            fDTDDescription.setValues(fDoctypePublicId, fDoctypeSystemId, null, null);                            fDTDDescription.setRootName(fDoctypeName);                            XMLInputSource xmlInputSource =                                fEntityManager.resolveEntity(fDTDDescription);                            fDTDScanner.setInputSource(xmlInputSource);                            setScannerState(SCANNER_STATE_DTD_EXTERNAL_DECLS);                            again = true;                            break;                             */                                                        resourceIdentifier.setValues(fDoctypePublicId, fDoctypeSystemId, null, null);                            XMLInputSource xmlInputSource = null ;                            StaxXMLInputSource staxInputSource =  fEntityManager.resolveEntityAsPerStax(resourceIdentifier);                            xmlInputSource = staxInputSource.getXMLInputSource();                            fDTDScanner.setInputSource(xmlInputSource);                            setScannerState(SCANNER_STATE_DTD_EXTERNAL_DECLS);                            again = true;                            break;                        }                        case SCANNER_STATE_DTD_EXTERNAL_DECLS: {                            // REVISIT: Should there be a feature for                            //          the "complete" parameter?                            boolean completeDTD = true;                            boolean moreToScan = fDTDScanner.scanDTDExternalSubset(completeDTD);                            if (!moreToScan) {                                setEndDTDScanState();                                return true;                            }                            break;                        }                        case SCANNER_STATE_PROLOG : {                            // skip entity decls                            setEndDTDScanState();                            return true;                        }                        default: {                            throw new XNIException("DTDDriver#dispatch: scanner state="+fScannerState+" ("+getScannerStateName(fScannerState)+')');                        }                    }                } while (complete || again);            }                        // premature end of file            catch (EOFException e) {                e.printStackTrace();                reportFatalError("PrematureEOF", null);                return false;

⌨️ 快捷键说明

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