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

📄 xmldocumentscannerimpl.java

📁 java1.6众多例子参考
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
                //set the scanner set to SCANNER_STATE_TERMINATED                setScannerState(SCANNER_STATE_TERMINATED) ;            } else{                //else we have reached the end of document prematurely                //so throw EOFException.                throw new java.io.EOFException();            }                        //this is taken care in wrapper which generates XNI callbacks, There are no next events                        //if (fDocumentHandler != null) {                //fDocumentHandler.endDocument(null);            //}        }    } // endEntity(String)                public XMLStringBuffer getDTDDecl(){        Entity entity = fEntityScanner.getCurrentEntity();        fDTDDecl.append(((Entity.ScannedEntity)entity).ch,fStartPos , fEndPos-fStartPos);        if(fSeenInternalSubset)            fDTDDecl.append("]>");        return fDTDDecl;    }        public String getCharacterEncodingScheme(){        return fDeclaredEncoding;    }        /** return the next state on the input     *     * @return int     */        public int next() throws IOException, XNIException {        return fDriver.next();    }        //getNamespaceContext    public NamespaceContext getNamespaceContext(){        return fNamespaceContext ;    }        //    // Protected methods    //        // driver factory methods        /** Creates a content driver. */    protected Driver createContentDriver() {        return new ContentDriver();    } // createContentDriver():Driver        // scanning methods        /** Scans a doctype declaration. */    protected boolean scanDoctypeDecl(boolean ignore) throws IOException, XNIException {                // spaces        if (!fEntityScanner.skipSpaces()) {            reportFatalError("MSG_SPACE_REQUIRED_BEFORE_ROOT_ELEMENT_TYPE_IN_DOCTYPEDECL",                    null);        }                // root element name        fDoctypeName = fEntityScanner.scanName();        if (fDoctypeName == null) {            reportFatalError("MSG_ROOT_ELEMENT_TYPE_REQUIRED", null);        }                // external id        if (fEntityScanner.skipSpaces()) {            scanExternalID(fStrings, false);            fDoctypeSystemId = fStrings[0];            fDoctypePublicId = fStrings[1];            fEntityScanner.skipSpaces();        }                fHasExternalDTD = fDoctypeSystemId != null;                // Attempt to locate an external subset with an external subset resolver.        if (!ignore && !fHasExternalDTD && fExternalSubsetResolver != null) {            fDTDDescription.setValues(null, null, fEntityManager.getCurrentResourceIdentifier().getExpandedSystemId(), null);            fDTDDescription.setRootName(fDoctypeName);            fExternalSubsetSource = fExternalSubsetResolver.getExternalSubset(fDTDDescription);            fHasExternalDTD = fExternalSubsetSource != null;        }                // call handler        if (!ignore && fDocumentHandler != null) {            // NOTE: I don't like calling the doctypeDecl callback until            //       end of the *full* doctype line (including internal            //       subset) is parsed correctly but SAX2 requires that            //       it knows the root element name and public and system            //       identifier for the startDTD call. -Ac            if (fExternalSubsetSource == null) {                fDocumentHandler.doctypeDecl(fDoctypeName, fDoctypePublicId, fDoctypeSystemId, null);            }            else {                fDocumentHandler.doctypeDecl(fDoctypeName, fExternalSubsetSource.getPublicId(), fExternalSubsetSource.getSystemId(), null);            }                    }                // is there an internal subset?        boolean internalSubset = true;        if (!fEntityScanner.skipChar('[')) {            internalSubset = false;            fEntityScanner.skipSpaces();            if (!fEntityScanner.skipChar('>')) {                reportFatalError("DoctypedeclUnterminated", new Object[]{fDoctypeName});            }            fMarkupDepth--;        }        return internalSubset;            } // scanDoctypeDecl():boolean        //    // Private methods    //    /** Set the scanner state after scanning DTD */    protected void setEndDTDScanState() {        setScannerState(SCANNER_STATE_PROLOG);        setDriver(fPrologDriver);        fEntityManager.setEntityHandler(XMLDocumentScannerImpl.this);    }        /** Returns the scanner state name. */    protected String getScannerStateName(int state) {                switch (state) {            case SCANNER_STATE_XML_DECL: return "SCANNER_STATE_XML_DECL";            case SCANNER_STATE_PROLOG: return "SCANNER_STATE_PROLOG";            case SCANNER_STATE_TRAILING_MISC: return "SCANNER_STATE_TRAILING_MISC";            case SCANNER_STATE_DTD_INTERNAL_DECLS: return "SCANNER_STATE_DTD_INTERNAL_DECLS";            case SCANNER_STATE_DTD_EXTERNAL: return "SCANNER_STATE_DTD_EXTERNAL";            case SCANNER_STATE_DTD_EXTERNAL_DECLS: return "SCANNER_STATE_DTD_EXTERNAL_DECLS";        }        return super.getScannerStateName(state);            } // getScannerStateName(int):String        //    // Classes    //        /**     * Driver to handle XMLDecl scanning.     *     * This class has been modified as per the new design which is more suited to     * efficiently build pull parser. Lots of performance improvements have been done and     * the code has been added to support stax functionality/features.     *     * @author Neeraj Bajaj, Sun Microsystems.     *     * @author Andy Clark, IBM     */    protected final class XMLDeclDriver            implements Driver {                //        // Driver methods        //                        public int next() throws IOException, XNIException {            if(DEBUG_NEXT){                System.out.println("NOW IN XMLDeclDriver");            }                        // next driver is prolog regardless of whether there            // is an XMLDecl in this document            setScannerState(SCANNER_STATE_PROLOG);            setDriver(fPrologDriver);                        //System.out.println("fEntityScanner = " + fEntityScanner);            // scan XMLDecl            try {                if (fEntityScanner.skipString(xmlDecl)) {                    fMarkupDepth++;                    // NOTE: special case where document starts with a PI                    //       whose name starts with "xml" (e.g. "xmlfoo")                    if (XMLChar.isName(fEntityScanner.peekChar())) {                        fStringBuffer.clear();                        fStringBuffer.append("xml");                        while (XMLChar.isName(fEntityScanner.peekChar())) {                            fStringBuffer.append((char)fEntityScanner.scanChar());                        }                        String target = fSymbolTable.addSymbol(fStringBuffer.ch, fStringBuffer.offset, fStringBuffer.length);                        //this function should fill the data.. and set the fEvent object to this event.                        fStringBuffer.clear() ;                        scanPIData(target, fStringBuffer);                        //REVISIT:where else we can set this value to 'true'                        fEntityManager.fCurrentEntity.mayReadChunks = true;                        //return PI event since PI was encountered                        return XMLEvent.PROCESSING_INSTRUCTION ;                    }                    // standard XML declaration                    else {                        scanXMLDeclOrTextDecl(false);                        //REVISIT:where else we can set this value to 'true'                        fEntityManager.fCurrentEntity.mayReadChunks = true;                        return XMLEvent.START_DOCUMENT;                    }                } else{                    //REVISIT:where else we can set this value to 'true'                    fEntityManager.fCurrentEntity.mayReadChunks = true;                    //In both case return the START_DOCUMENT. ony difference is that first block will                    //cosume the XML declaration if any.                    return XMLEvent.START_DOCUMENT;                }                                                //START_OF_THE_DOCUMENT                                            }                        // premature end of file            catch (EOFException e) {                reportFatalError("PrematureEOF", null);                return -1;                //throw e;            }                    }    } // class XMLDeclDriver        /**     * Driver to handle prolog scanning.     *     * @author Andy Clark, IBM     */    protected final class PrologDriver            implements Driver {                /**         * Drives the parser to the next state/event on the input. Parser is guaranteed         * to stop at the next state/event.         *         * Internally XML document is divided into several states. Each state represents         * a sections of XML document. When this functions returns normally, it has read         * the section of XML document and returns the state corresponding to section of         * document which has been read. For optimizations, a particular driver         * can read ahead of the section of document (state returned) just read and         * can maintain a different internal state.         *         * @return state representing the section of document just read.         *         * @throws IOException  Thrown on i/o error.         * @throws XNIException Thrown on parse error.         */                public int next() throws IOException, XNIException {            //System.out.println("here in next");                        if(DEBUG_NEXT){                System.out.println("NOW IN PrologDriver");            }            try {                do {                    switch (fScannerState) {                        case SCANNER_STATE_PROLOG: {                            fEntityScanner.skipSpaces();                            if (fEntityScanner.skipChar('<')) {                                setScannerState(SCANNER_STATE_START_OF_MARKUP);                            } else if (fEntityScanner.skipChar('&')) {                                setScannerState(SCANNER_STATE_REFERENCE);                            } else {                                setScannerState(SCANNER_STATE_CONTENT);                            }                            break;                        }                                                case SCANNER_STATE_START_OF_MARKUP: {                            fMarkupDepth++;                                                        if (fEntityScanner.skipChar('?')) {                                setScannerState(SCANNER_STATE_PI);                            } else if (fEntityScanner.skipChar('!')) {                                if (fEntityScanner.skipChar('-')) {                                    if (!fEntityScanner.skipChar('-')) {                                        reportFatalError("InvalidCommentStart",                                                null);                                    }                                    setScannerState(SCANNER_STATE_COMMENT);                                } else if (fEntityScanner.skipString(DOCTYPE)) {                                    setScannerState(SCANNER_STATE_DOCTYPE);                                    Entity entity = fEntityScanner.getCurrentEntity();                                    if(entity instanceof Entity.ScannedEntity){                                        fStartPos=((Entity.ScannedEntity)entity).position;                                    }                                    fReadingDTD=true;                                    if(fDTDDecl == null)                                        fDTDDecl = new XMLStringBuffer();                                    fDTDDecl.append("<!DOCTYPE");                                                                    } else {                                    reportFatalError("MarkupNotRecognizedInProlog",                                            null);                                }                            } else if (XMLChar.isNameStart(fEntityScanner.peekChar())) {                                setScannerState(SCANNER_STATE_ROOT_ELEMENT);

⌨️ 快捷键说明

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