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

📄 xmlscanner.java

📁 java1.6众多例子参考
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
    protected boolean scanPubidLiteral(XMLString literal)    throws IOException, XNIException {        int quote = fEntityScanner.scanChar();        if (quote != '\'' && quote != '"') {            reportFatalError("QuoteRequiredInPublicID", null);            return false;        }                fStringBuffer.clear();        // skip leading whitespace        boolean skipSpace = true;        boolean dataok = true;        while (true) {            int c = fEntityScanner.scanChar();            if (c == ' ' || c == '\n' || c == '\r') {                if (!skipSpace) {                    // take the first whitespace as a space and skip the others                    fStringBuffer.append(' ');                    skipSpace = true;                }            } else if (c == quote) {                if (skipSpace) {                    // if we finished on a space let's trim it                    fStringBuffer.length--;                }                literal.setValues(fStringBuffer);                break;            } else if (XMLChar.isPubid(c)) {                fStringBuffer.append((char)c);                skipSpace = false;            } else if (c == -1) {                reportFatalError("PublicIDUnterminated", null);                return false;            } else {                dataok = false;                reportFatalError("InvalidCharInPublicID",                        new Object[]{Integer.toHexString(c)});            }        }        return dataok;    }            /**     * Normalize whitespace in an XMLString converting all whitespace     * characters to space characters.     */    protected void normalizeWhitespace(XMLString value) {        int i=0;        int j=0;        int [] buff = fEntityScanner.whiteSpaceLookup;        int buffLen = fEntityScanner.whiteSpaceLen;        int end = value.offset + value.length;        while(i < buffLen){            j = buff[i];            if(j < end ){                value.ch[j] = ' ';            }            i++;        }    }        //    // XMLEntityHandler methods    //        /**     * This method notifies of the start of an entity. The document entity     * has the pseudo-name of "[xml]" the DTD has the pseudo-name of "[dtd]"     * parameter entity names start with '%'; and general entities are just     * specified by their name.     *     * @param name     The name of the entity.     * @param identifier The resource identifier.     * @param encoding The auto-detected IANA encoding name of the entity     *                 stream. This value will be null in those situations     *                 where the entity encoding is not auto-detected (e.g.     *                 internal entities or a document entity that is     *                 parsed from a java.io.Reader).     *     * @throws XNIException Thrown by handler to signal an error.     */    public void startEntity(String name,            XMLResourceIdentifier identifier,            String encoding, Augmentations augs) throws XNIException {                // keep track of the entity depth        fEntityDepth++;        // must reset entity scanner        fEntityScanner = fEntityManager.getEntityScanner();        fEntityStore = fEntityManager.getEntityStore() ;    } // startEntity(String,XMLResourceIdentifier,String)        /**     * This method notifies the end of an entity. The document entity has     * the pseudo-name of "[xml]" the DTD has the pseudo-name of "[dtd]"     * parameter entity names start with '%'; and general entities are just     * specified by their name.     *     * @param name The name of the entity.     *     * @throws XNIException Thrown by handler to signal an error.     */    public void endEntity(String name, Augmentations augs) throws IOException, XNIException {                // keep track of the entity depth        fEntityDepth--;            } // endEntity(String)        /**     * Scans a character reference and append the corresponding chars to the     * specified buffer.     *     * <p>     * <pre>     * [66] CharRef ::= '&#' [0-9]+ ';' | '&#x' [0-9a-fA-F]+ ';'     * </pre>     *     * <strong>Note:</strong> This method uses fStringBuffer, anything in it     * at the time of calling is lost.     *     * @param buf the character buffer to append chars to     * @param buf2 the character buffer to append non-normalized chars to     *     * @return the character value or (-1) on conversion failure     */    protected int scanCharReferenceValue(XMLStringBuffer buf, XMLStringBuffer buf2)    throws IOException, XNIException {        // scan hexadecimal value        boolean hex = false;        if (fEntityScanner.skipChar('x')) {            if (buf2 != null) { buf2.append('x'); }            hex = true;            fStringBuffer3.clear();            boolean digit = true;                        int c = fEntityScanner.peekChar();            digit = (c >= '0' && c <= '9') ||                    (c >= 'a' && c <= 'f') ||                    (c >= 'A' && c <= 'F');            if (digit) {                if (buf2 != null) { buf2.append((char)c); }                fEntityScanner.scanChar();                fStringBuffer3.append((char)c);                                do {                    c = fEntityScanner.peekChar();                    digit = (c >= '0' && c <= '9') ||                            (c >= 'a' && c <= 'f') ||                            (c >= 'A' && c <= 'F');                    if (digit) {                        if (buf2 != null) { buf2.append((char)c); }                        fEntityScanner.scanChar();                        fStringBuffer3.append((char)c);                    }                } while (digit);            } else {                reportFatalError("HexdigitRequiredInCharRef", null);            }        }                // scan decimal value        else {            fStringBuffer3.clear();            boolean digit = true;                        int c = fEntityScanner.peekChar();            digit = c >= '0' && c <= '9';            if (digit) {                if (buf2 != null) { buf2.append((char)c); }                fEntityScanner.scanChar();                fStringBuffer3.append((char)c);                                do {                    c = fEntityScanner.peekChar();                    digit = c >= '0' && c <= '9';                    if (digit) {                        if (buf2 != null) { buf2.append((char)c); }                        fEntityScanner.scanChar();                        fStringBuffer3.append((char)c);                    }                } while (digit);            } else {                reportFatalError("DigitRequiredInCharRef", null);            }        }                // end        if (!fEntityScanner.skipChar(';')) {            reportFatalError("SemicolonRequiredInCharRef", null);        }        if (buf2 != null) { buf2.append(';'); }                // convert string to number        int value = -1;        try {            value = Integer.parseInt(fStringBuffer3.toString(),                    hex ? 16 : 10);                        // character reference must be a valid XML character            if (isInvalid(value)) {                StringBuffer errorBuf = new StringBuffer(fStringBuffer3.length + 1);                if (hex) errorBuf.append('x');                errorBuf.append(fStringBuffer3.ch, fStringBuffer3.offset, fStringBuffer3.length);                reportFatalError("InvalidCharRef",                        new Object[]{errorBuf.toString()});            }        } catch (NumberFormatException e) {            // Conversion failed, let -1 value drop through.            // If we end up here, the character reference was invalid.            StringBuffer errorBuf = new StringBuffer(fStringBuffer3.length + 1);            if (hex) errorBuf.append('x');            errorBuf.append(fStringBuffer3.ch, fStringBuffer3.offset, fStringBuffer3.length);            reportFatalError("InvalidCharRef",                    new Object[]{errorBuf.toString()});        }                // append corresponding chars to the given buffer        if (!XMLChar.isSupplemental(value)) {            buf.append((char) value);        } else {            // character is supplemental, split it into surrogate chars            buf.append(XMLChar.highSurrogate(value));            buf.append(XMLChar.lowSurrogate(value));        }                // char refs notification code        if (fNotifyCharRefs && value != -1) {            String literal = "#" + (hex ? "x" : "") + fStringBuffer3.toString();            if (!fScanningAttribute) {                fCharRefLiteral = literal;            }        }                return value;    }    // returns true if the given character is not    // valid with respect to the version of    // XML understood by this scanner.    protected boolean isInvalid(int value) {        return (XMLChar.isInvalid(value));    } // isInvalid(int):  boolean        // returns true if the given character is not    // valid or may not be used outside a character reference    // with respect to the version of XML understood by this scanner.    protected boolean isInvalidLiteral(int value) {        return (XMLChar.isInvalid(value));    } // isInvalidLiteral(int):  boolean        // returns true if the given character is    // a valid nameChar with respect to the version of    // XML understood by this scanner.    protected boolean isValidNameChar(int value) {        return (XMLChar.isName(value));    } // isValidNameChar(int):  boolean        // returns true if the given character is    // a valid NCName character with respect to the version of    // XML understood by this scanner.    protected boolean isValidNCName(int value) {        return (XMLChar.isNCName(value));    } // isValidNCName(int):  boolean        // returns true if the given character is    // a valid nameStartChar with respect to the version of    // XML understood by this scanner.    protected boolean isValidNameStartChar(int value) {        return (XMLChar.isNameStart(value));    } // isValidNameStartChar(int):  boolean        protected boolean versionSupported(String version ) {        return version.equals("1.0") || version.equals("1.1");    } // version Supported        /**     * Scans surrogates and append them to the specified buffer.     * <p>     * <strong>Note:</strong> This assumes the current char has already been     * identified as a high surrogate.     *     * @param buf The StringBuffer to append the read surrogates to.     * @return True if it succeeded.     */    protected boolean scanSurrogates(XMLStringBuffer buf)    throws IOException, XNIException {                int high = fEntityScanner.scanChar();        int low = fEntityScanner.peekChar();        if (!XMLChar.isLowSurrogate(low)) {            reportFatalError("InvalidCharInContent",                    new Object[] {Integer.toString(high, 16)});                    return false;        }        fEntityScanner.scanChar();                // convert surrogates to supplemental character        int c = XMLChar.supplemental((char)high, (char)low);                // supplemental character must be a valid XML character        if (isInvalid(c)) {            reportFatalError("InvalidCharInContent",                    new Object[]{Integer.toString(c, 16)});                    return false;        }                // fill in the buffer        buf.append((char)high);        buf.append((char)low);                return true;            } // scanSurrogates():boolean            /**     * Convenience function used in all XML scanners.     */    protected void reportFatalError(String msgId, Object[] args)    throws XNIException {        fErrorReporter.reportError(fEntityScanner, XMLMessageFormatter.XML_DOMAIN,                msgId, args,                XMLErrorReporter.SEVERITY_FATAL_ERROR);    }        // private methods    private void init() {        // initialize scanner        fEntityScanner = null;                // initialize vars        fEntityDepth = 0;        fReportEntity = true;        fResourceIdentifier.clear();        if(!fAttributeCacheInitDone){            for(int i = 0; i < initialCacheCount; i++){                attributeValueCache.add(new XMLString());                stringBufferCache.add(new XMLStringBuffer());            }            fAttributeCacheInitDone = true;        }        fStringBufferIndex = 0;        fAttributeCacheUsedCount = 0;            }        XMLStringBuffer getStringBuffer(){        if((fStringBufferIndex < initialCacheCount )|| (fStringBufferIndex < stringBufferCache.size())){            return (XMLStringBuffer)stringBufferCache.get(fStringBufferIndex++);        }else{            XMLStringBuffer tmpObj = new XMLStringBuffer();            stringBufferCache.add(fStringBufferIndex, tmpObj);            return tmpObj;        }    }        } // class XMLScanner

⌨️ 快捷键说明

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