xmlentityscanner.java

来自「JAVA 所有包」· Java 代码 · 共 1,674 行 · 第 1/5 页

JAVA
1,674
字号
     * @see com.sun.org.apache.xerces.internal.xni.XMLResourceIdentifier#setExpandedSystemId(String)     */    public void setExpandedSystemId(String systemId) {        //no-op    }        /** Returns the literal system identifier.  */    public String getLiteralSystemId() {        return (fCurrentEntity != null && fCurrentEntity.entityLocation != null) ? fCurrentEntity.entityLocation.getLiteralSystemId() : null;    }        /**     * @see com.sun.org.apache.xerces.internal.xni.XMLResourceIdentifier#setLiteralSystemId(String)     */    public void setLiteralSystemId(String systemId) {        //no-op    }        /** Returns the public identifier.  */    public String getPublicId() {        return (fCurrentEntity != null && fCurrentEntity.entityLocation != null) ? fCurrentEntity.entityLocation.getPublicId() : null;    }        /**     * @see com.sun.org.apache.xerces.internal.xni.XMLResourceIdentifier#setPublicId(String)     */    public void setPublicId(String publicId) {        //no-op    }        ///////////////// Locator methods finished.        /** the version of the current entity being scanned */    public void setVersion(String version){        fCurrentEntity.version = version;    }        public String getVersion(){        return fCurrentEntity.version ;    }        public String getEncoding(){        return fCurrentEntity.encoding ;    }    /**     * Sets the encoding of the scanner. This method is used by the     * scanners if the XMLDecl or TextDecl line contains an encoding     * pseudo-attribute.     * <p>     * <strong>Note:</strong> The underlying character reader on the     * current entity will be changed to accomodate the new encoding.     * However, the new encoding is ignored if the current reader was     * not constructed from an input stream (e.g. an external entity     * that is resolved directly to the appropriate java.io.Reader     * object).     *     * @param encoding The IANA encoding name of the new encoding.     *     * @throws IOException Thrown if the new encoding is not supported.     *     * @see com.sun.org.apache.xerces.internal.util.EncodingMap     */    public void setEncoding(String encoding) throws IOException {                if (DEBUG_ENCODINGS) {            System.out.println("$$$ setEncoding: "+encoding);        }                if (fCurrentEntity.stream != null) {            // if the encoding is the same, don't change the reader and            // re-use the original reader used by the OneCharReader            // NOTE: Besides saving an object, this overcomes deficiencies            //       in the UTF-16 reader supplied with the standard Java            //       distribution (up to and including 1.3). The UTF-16            //       decoder buffers 8K blocks even when only asked to read            //       a single char! -Ac            if (fCurrentEntity.encoding == null ||                    !fCurrentEntity.encoding.equals(encoding)) {                // UTF-16 is a bit of a special case.  If the encoding is UTF-16,                // and we know the endian-ness, we shouldn't change readers.                // If it's ISO-10646-UCS-(2|4), then we'll have to deduce                // the endian-ness from the encoding we presently have.                if(fCurrentEntity.encoding != null && fCurrentEntity.encoding.startsWith("UTF-16")) {                    String ENCODING = encoding.toUpperCase(Locale.ENGLISH);                    if(ENCODING.equals("UTF-16")) return;                    if(ENCODING.equals("ISO-10646-UCS-4")) {                        if(fCurrentEntity.encoding.equals("UTF-16BE")) {                            fCurrentEntity.reader = new UCSReader(fCurrentEntity.stream, UCSReader.UCS4BE);                        } else {                            fCurrentEntity.reader = new UCSReader(fCurrentEntity.stream, UCSReader.UCS4LE);                        }                        return;                    }                    if(ENCODING.equals("ISO-10646-UCS-2")) {                        if(fCurrentEntity.encoding.equals("UTF-16BE")) {                            fCurrentEntity.reader = new UCSReader(fCurrentEntity.stream, UCSReader.UCS2BE);                        } else {                            fCurrentEntity.reader = new UCSReader(fCurrentEntity.stream, UCSReader.UCS2LE);                        }                        return;                    }                }                // wrap a new reader around the input stream, changing                // the encoding                if (DEBUG_ENCODINGS) {                    System.out.println("$$$ creating new reader from stream: "+                            fCurrentEntity.stream);                }                //fCurrentEntity.stream.reset();                fCurrentEntity.reader = createReader(fCurrentEntity.stream, encoding, null);                fCurrentEntity.encoding = encoding;                                 } else {                if (DEBUG_ENCODINGS)                    System.out.println("$$$ reusing old reader on stream");            }        }            } // setEncoding(String)        /** Returns true if the current entity being scanned is external. */    public boolean isExternal() {        return fCurrentEntity.isExternal();    } // isExternal():boolean        public int getChar(int relative) throws IOException{        if(arrangeCapacity(relative + 1, false)){            return fCurrentEntity.ch[fCurrentEntity.position + relative];        }else{            return -1;        }    }//getChar()        /**     * Returns the next character on the input.     * <p>     * <strong>Note:</strong> The character is <em>not</em> consumed.     *     * @throws IOException  Thrown if i/o error occurs.     * @throws EOFException Thrown on end of file.     */    public int peekChar() throws IOException {        if (DEBUG_BUFFER) {            System.out.print("(peekChar: ");            print();            System.out.println();        }                // load more characters, if needed        if (fCurrentEntity.position == fCurrentEntity.count) {            invokeListeners(0);            load(0, true);        }                // peek at character        int c = fCurrentEntity.ch[fCurrentEntity.position];                // return peeked character        if (DEBUG_BUFFER) {            System.out.print(")peekChar: ");            print();            if (isExternal) {                System.out.println(" -> '"+(c!='\r'?(char)c:'\n')+"'");            } else {                System.out.println(" -> '"+(char)c+"'");            }        }        if (isExternal) {            return c != '\r' ? c : '\n';        } else {            return c;        }            } // peekChar():int        /**     * Returns the next character on the input.     * <p>     * <strong>Note:</strong> The character is consumed.     *     * @throws IOException  Thrown if i/o error occurs.     * @throws EOFException Thrown on end of file.     */    public int scanChar() throws IOException {        if (DEBUG_BUFFER) {            System.out.print("(scanChar: ");            print();            System.out.println();        }                // load more characters, if needed        if (fCurrentEntity.position == fCurrentEntity.count) {            invokeListeners(0);            load(0, true);        }                // scan character        int c = fCurrentEntity.ch[fCurrentEntity.position++];        if (c == '\n' ||                (c == '\r' && isExternal)) {            fCurrentEntity.lineNumber++;            fCurrentEntity.columnNumber = 1;            if (fCurrentEntity.position == fCurrentEntity.count) {                invokeListeners(1);                fCurrentEntity.ch[0] = (char)c;                load(1, false);            }            if (c == '\r' && isExternal) {                if (fCurrentEntity.ch[fCurrentEntity.position++] != '\n') {                    fCurrentEntity.position--;                }                c = '\n';            }        }                // return character that was scanned        if (DEBUG_BUFFER) {            System.out.print(")scanChar: ");            print();            System.out.println(" -> '"+(char)c+"'");        }        fCurrentEntity.columnNumber++;        return c;            } // scanChar():int        /**     * Returns a string matching the NMTOKEN production appearing immediately     * on the input as a symbol, or null if NMTOKEN Name string is present.     * <p>     * <strong>Note:</strong> The NMTOKEN characters are consumed.     * <p>     * <strong>Note:</strong> The string returned must be a symbol. The     * SymbolTable can be used for this purpose.     *     * @throws IOException  Thrown if i/o error occurs.     * @throws EOFException Thrown on end of file.     *     * @see com.sun.org.apache.xerces.internal.util.SymbolTable     * @see com.sun.org.apache.xerces.internal.util.XMLChar#isName     */    public String scanNmtoken() throws IOException {        if (DEBUG_BUFFER) {            System.out.print("(scanNmtoken: ");            print();            System.out.println();        }                // load more characters, if needed        if (fCurrentEntity.position == fCurrentEntity.count) {            invokeListeners(0);            load(0, true);        }                // scan nmtoken        int offset = fCurrentEntity.position;        boolean vc = false;        char c;        while (true){            //while (XMLChar.isName(fCurrentEntity.ch[fCurrentEntity.position])) {            c = fCurrentEntity.ch[fCurrentEntity.position];            if(c < 127){                vc = VALID_NAMES[c];            }else{                vc = XMLChar.isName(c);            }            if(!vc)break;                        if (++fCurrentEntity.position == fCurrentEntity.count) {                int length = fCurrentEntity.position - offset;                invokeListeners(length);                if (length == fCurrentEntity.fBufferSize) {                    // bad luck we have to resize our buffer                    char[] tmp = new char[fCurrentEntity.fBufferSize * 2];                    System.arraycopy(fCurrentEntity.ch, offset,                            tmp, 0, length);                    fCurrentEntity.ch = tmp;                    fCurrentEntity.fBufferSize *= 2;                } else {                    System.arraycopy(fCurrentEntity.ch, offset,                            fCurrentEntity.ch, 0, length);                }                offset = 0;                if (load(length, false)) {                    break;                }            }        }        int length = fCurrentEntity.position - offset;        fCurrentEntity.columnNumber += length;                // return nmtoken        String symbol = null;        if (length > 0) {            symbol = fSymbolTable.addSymbol(fCurrentEntity.ch, offset, length);        }        if (DEBUG_BUFFER) {            System.out.print(")scanNmtoken: ");            print();            System.out.println(" -> "+String.valueOf(symbol));        }        return symbol;            } // scanNmtoken():String        /**     * Returns a string matching the Name production appearing immediately     * on the input as a symbol, or null if no Name string is present.     * <p>     * <strong>Note:</strong> The Name characters are consumed.     * <p>     * <strong>Note:</strong> The string returned must be a symbol. The     * SymbolTable can be used for this purpose.     *     * @throws IOException  Thrown if i/o error occurs.     * @throws EOFException Thrown on end of file.     *     * @see com.sun.org.apache.xerces.internal.util.SymbolTable     * @see com.sun.org.apache.xerces.internal.util.XMLChar#isName     * @see com.sun.org.apache.xerces.internal.util.XMLChar#isNameStart     */    public String scanName() throws IOException {        if (DEBUG_BUFFER) {            System.out.print("(scanName: ");            print();            System.out.println();        }                // load more characters, if needed        if (fCurrentEntity.position == fCurrentEntity.count) {            invokeListeners(0);            load(0, true);        }                // scan name

⌨️ 快捷键说明

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