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

📄 xmldocumentscannerimpl.java

📁 java1.6众多例子参考
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
                //throw e;            }                        // cleanup            finally {                fEntityManager.setEntityHandler(XMLDocumentScannerImpl.this);            }                        return true;                    }                // dispatch(boolean):boolean            } // class DTDDriver        /**     * Driver to handle content scanning.     *     * @author Andy Clark, IBM     * @author Eric Ye, IBM     */    protected class ContentDriver            extends FragmentContentDriver {                //        // Protected methods        //                // hooks                // NOTE: These hook methods are added so that the full document        //       scanner can share the majority of code with this class.                /**         * Scan for DOCTYPE hook. This method is a hook for subclasses         * to add code to handle scanning for a the "DOCTYPE" string         * after the string "<!" has been scanned.         *         * @return True if the "DOCTYPE" was scanned; false if "DOCTYPE"         *          was not scanned.         */        protected boolean scanForDoctypeHook()        throws IOException, XNIException {                        if (fEntityScanner.skipString(DOCTYPE)) {                setScannerState(SCANNER_STATE_DOCTYPE);                //                fEntityScanner.markStartOfDTD();                return true;            }            return false;                    } // scanForDoctypeHook():boolean                /**         * Element depth iz zero. This methos is a hook for subclasses         * to add code to handle when the element depth hits zero. When         * scanning a document fragment, an element depth of zero is         * normal. However, when scanning a full XML document, the         * scanner must handle the trailing miscellanous section of         * the document after the end of the document's root element.         *         * @return True if the caller should stop and return true which         *          allows the scanner to switch to a new scanning         *          driver. A return value of false indicates that         *          the content driver should continue as normal.         */        protected boolean elementDepthIsZeroHook()        throws IOException, XNIException {                        setScannerState(SCANNER_STATE_TRAILING_MISC);            setDriver(fTrailingMiscDriver);            return true;                    } // elementDepthIsZeroHook():boolean                /**         * Scan for root element hook. This method is a hook for         * subclasses to add code that handles scanning for the root         * element. When scanning a document fragment, there is no         * "root" element. However, when scanning a full XML document,         * the scanner must handle the root element specially.         *         * @return True if the caller should stop and return true which         *          allows the scanner to switch to a new scanning         *          driver. A return value of false indicates that         *          the content driver should continue as normal.         */        protected boolean scanRootElementHook()        throws IOException, XNIException {                        if (scanStartElement()) {                setScannerState(SCANNER_STATE_TRAILING_MISC);                setDriver(fTrailingMiscDriver);                return true;            }            return false;                    } // scanRootElementHook():boolean                /**         * End of file hook. This method is a hook for subclasses to         * add code that handles the end of file. The end of file in         * a document fragment is OK if the markup depth is zero.         * However, when scanning a full XML document, an end of file         * is always premature.         */        protected void endOfFileHook(EOFException e)        throws IOException, XNIException {                        reportFatalError("PrematureEOF", null);            // in case continue-after-fatal-error set, should not do this...            //throw e;                    } // endOfFileHook()                protected void resolveExternalSubsetAndRead()        throws IOException, XNIException {                        fDTDDescription.setValues(null, null, fEntityManager.getCurrentResourceIdentifier().getExpandedSystemId(), null);            fDTDDescription.setRootName(fElementQName.rawname);                        XMLInputSource src = fExternalSubsetResolver.getExternalSubset(fDTDDescription);                        if (src != null) {                fDoctypeName = fElementQName.rawname;                fDoctypePublicId = src.getPublicId();                fDoctypeSystemId = src.getSystemId();                // call document handler                if (fDocumentHandler != null) {                    // This inserts a doctypeDecl event into the stream though no                    // DOCTYPE existed in the instance document.                    fDocumentHandler.doctypeDecl(fDoctypeName, fDoctypePublicId, fDoctypeSystemId, null);                }                try {                    fDTDScanner.setInputSource(src);                    while (fDTDScanner.scanDTDExternalSubset(true));                } finally {                    fEntityManager.setEntityHandler(XMLDocumentScannerImpl.this);                }            }        } // resolveExternalSubsetAndRead()                            } // class ContentDriver        /**     * Driver to handle trailing miscellaneous section scanning.     *     * @author Andy Clark, IBM     * @author Eric Ye, IBM     */    protected final class TrailingMiscDriver            implements Driver {                //        // Driver methods        //        public int next() throws IOException, XNIException{            //this could for cases like <foo/>            //look at scanRootElementHook            if(fEmptyElement){                fEmptyElement = false;                return XMLEvent.END_ELEMENT;            }                        try {                if(fScannerState == SCANNER_STATE_TERMINATED){                    return XMLEvent.END_DOCUMENT ;}                do {                    switch (fScannerState) {                        case SCANNER_STATE_TRAILING_MISC: {                                                        fEntityScanner.skipSpaces();                            //we should have reached the end of the document in                            //most cases.                            if(fScannerState == SCANNER_STATE_TERMINATED ){                                return XMLEvent.END_DOCUMENT ;                            }                            if (fEntityScanner.skipChar('<')) {                                setScannerState(SCANNER_STATE_START_OF_MARKUP);                            } else {                                setScannerState(SCANNER_STATE_CONTENT);                            }                            break;                        }                        case SCANNER_STATE_START_OF_MARKUP: {                            fMarkupDepth++;                            if (fEntityScanner.skipChar('?')) {                                setScannerState(SCANNER_STATE_PI);                            } else if (fEntityScanner.skipChar('!')) {                                setScannerState(SCANNER_STATE_COMMENT);                            } else if (fEntityScanner.skipChar('/')) {                                reportFatalError("MarkupNotRecognizedInMisc",                                        null);                            } else if (XMLChar.isNameStart(fEntityScanner.peekChar())) {                                reportFatalError("MarkupNotRecognizedInMisc",                                        null);                                scanStartElement();                                setScannerState(SCANNER_STATE_CONTENT);                            } else {                                reportFatalError("MarkupNotRecognizedInMisc",                                        null);                            }                            break;                        }                    }                }while(fScannerState == SCANNER_STATE_START_OF_MARKUP || fScannerState == SCANNER_STATE_TRAILING_MISC);                if(DEBUG_NEXT){                    System.out.println("State set by deciding while loop [TrailingMiscellaneous] is = " + getScannerStateName(fScannerState));                }                switch (fScannerState){                    case SCANNER_STATE_PI: {                        fContentBuffer.clear();                        scanPI(fContentBuffer);                        setScannerState(SCANNER_STATE_TRAILING_MISC);                        return XMLEvent.PROCESSING_INSTRUCTION ;                    }                    case SCANNER_STATE_COMMENT: {                        if (!fEntityScanner.skipString(COMMENTSTRING)) {                            reportFatalError("InvalidCommentStart", null);                        }                        scanComment();                        setScannerState(SCANNER_STATE_TRAILING_MISC);                        return XMLEvent.COMMENT;                    }                    case SCANNER_STATE_CONTENT: {                        int ch = fEntityScanner.peekChar();                        if (ch == -1) {                            setScannerState(SCANNER_STATE_TERMINATED);                            return XMLEvent.END_DOCUMENT ;                        } else{                            reportFatalError("ContentIllegalInTrailingMisc",                                    null);                            fEntityScanner.scanChar();                            setScannerState(SCANNER_STATE_TRAILING_MISC);                            return XMLEvent.CHARACTERS;                        }                                            }                    case SCANNER_STATE_REFERENCE: {                        reportFatalError("ReferenceIllegalInTrailingMisc",                                null);                        setScannerState(SCANNER_STATE_TRAILING_MISC);                        return XMLEvent.ENTITY_REFERENCE ;                    }                    case SCANNER_STATE_TERMINATED: {                        //there can't be any element after SCANNER_STATE_TERMINATED or when the parser                        //has reached the end of document                        setScannerState(SCANNER_STATE_NO_SUCH_ELEMENT_EXCEPTION);                        //xxx what to do when the scanner has reached the terminating state.                        return XMLEvent.END_DOCUMENT ;                    }                    case SCANNER_STATE_NO_SUCH_ELEMENT_EXCEPTION:{                        throw new java.util.NoSuchElementException("No more events to be parsed");                    }                    default: throw new XNIException("Scanner State " + fScannerState + " not Recognized ");                }//switch                            } catch (EOFException e) {                // NOTE: This is the only place we're allowed to reach                //       the real end of the document stream. Unless the                //       end of file was reached prematurely.                if (fMarkupDepth != 0) {                    reportFatalError("PrematureEOF", null);                    return -1;                    //throw e;                }                System.out.println("EOFException thrown") ;                setScannerState(SCANNER_STATE_TERMINATED);            }                        return XMLEvent.END_DOCUMENT;                    }//next            } // class TrailingMiscDriver        /**     * Implements XMLBufferListener interface.     */        /**     * receives callbacks from {@link XMLEntityReader } when buffer     * is being changed.     * @param refreshPosition     */    public void refresh(int refreshPosition){        super.refresh(refreshPosition);        if(fReadingDTD){            Entity entity = fEntityScanner.getCurrentEntity();            if(entity instanceof Entity.ScannedEntity){                fEndPos=((Entity.ScannedEntity)entity).position;            }            fDTDDecl.append(((Entity.ScannedEntity)entity).ch,fStartPos , fEndPos-fStartPos);            fStartPos = refreshPosition;        }    }    } // class XMLDocumentScannerImpl

⌨️ 快捷键说明

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