xmlentityscanner.java
来自「JAVA的一些源码 JAVA2 STANDARD EDITION DEVELO」· Java 代码 · 共 1,660 行 · 第 1/5 页
JAVA
1,660 行
* characters. * <p> * <strong>Note:</strong> The characters are consumed only if they would * match non-terminal S before end of line normalization is performed. * * @return Returns true if at least one space character was skipped. * * @throws IOException Thrown if i/o error occurs. * @throws EOFException Thrown on end of file. * * @see com.sun.org.apache.xerces.internal.util.XMLChar#isSpace */ public boolean skipDeclSpaces() throws IOException { if (DEBUG_BUFFER) { System.out.print("(skipDeclSpaces: "); XMLEntityManager.print(fCurrentEntity); System.out.println(); } // load more characters, if needed if (fCurrentEntity.position == fCurrentEntity.count) { load(0, true); } // skip spaces int c = fCurrentEntity.ch[fCurrentEntity.position]; if (XMLChar.isSpace(c)) { boolean external = fCurrentEntity.isExternal(); do { boolean entityChanged = false; // handle newlines if (c == '\n' || (external && c == '\r')) { fCurrentEntity.lineNumber++; fCurrentEntity.columnNumber = 1; if (fCurrentEntity.position == fCurrentEntity.count - 1) { fCurrentEntity.ch[0] = (char)c; entityChanged = load(1, true); if (!entityChanged) // the load change the position to be 1, // need to restore it when entity not changed fCurrentEntity.position = 0; } if (c == '\r' && external) { // REVISIT: Does this need to be updated to fix the // #x0D ^#x0A newline normalization problem? -Ac if (fCurrentEntity.ch[++fCurrentEntity.position] != '\n') { fCurrentEntity.position--; } } /*** NEWLINE NORMALIZATION *** else { if (fCurrentEntity.ch[fCurrentEntity.position + 1] == '\r' && external) { fCurrentEntity.position++; } } /***/ } else { fCurrentEntity.columnNumber++; } // load more characters, if needed if (!entityChanged) fCurrentEntity.position++; if (fCurrentEntity.position == fCurrentEntity.count) { load(0, true); } } while (XMLChar.isSpace(c = fCurrentEntity.ch[fCurrentEntity.position])); if (DEBUG_BUFFER) { System.out.print(")skipDeclSpaces: "); XMLEntityManager.print(fCurrentEntity); System.out.println(" -> true"); } return true; } // no spaces were found if (DEBUG_BUFFER) { System.out.print(")skipDeclSpaces: "); XMLEntityManager.print(fCurrentEntity); System.out.println(" -> false"); } return false; } // skipDeclSpaces():boolean /** * Skips the specified string appearing immediately on the input. * <p> * <strong>Note:</strong> The characters are consumed only if they are * space characters. * * @param s The string to skip. * * @return Returns true if the string was skipped. * * @throws IOException Thrown if i/o error occurs. * @throws EOFException Thrown on end of file. */ public boolean skipString(String s) throws IOException { if (DEBUG_BUFFER) { System.out.print("(skipString, \""+s+"\": "); XMLEntityManager.print(fCurrentEntity); System.out.println(); } // load more characters, if needed if (fCurrentEntity.position == fCurrentEntity.count) { load(0, true); } // skip string final int length = s.length(); for (int i = 0; i < length; i++) { char c = fCurrentEntity.ch[fCurrentEntity.position++]; if (c != s.charAt(i)) { fCurrentEntity.position -= i + 1; if (DEBUG_BUFFER) { System.out.print(")skipString, \""+s+"\": "); XMLEntityManager.print(fCurrentEntity); System.out.println(" -> false"); } return false; } if (i < length - 1 && fCurrentEntity.position == fCurrentEntity.count) { System.arraycopy(fCurrentEntity.ch, fCurrentEntity.count - i - 1, fCurrentEntity.ch, 0, i + 1); // REVISIT: Can a string to be skipped cross an // entity boundary? -Ac if (load(i + 1, false)) { fCurrentEntity.position -= i + 1; if (DEBUG_BUFFER) { System.out.print(")skipString, \""+s+"\": "); XMLEntityManager.print(fCurrentEntity); System.out.println(" -> false"); } return false; } } } if (DEBUG_BUFFER) { System.out.print(")skipString, \""+s+"\": "); XMLEntityManager.print(fCurrentEntity); System.out.println(" -> true"); } fCurrentEntity.columnNumber += length; return true; } // skipString(String):boolean // // Locator methods // /** * Return the public identifier for the current document event. * <p> * The return value is the public identifier of the document * entity or of the external parsed entity in which the markup * triggering the event appears. * * @return A string containing the public identifier, or * null if none is available. */ public String getPublicId() { return (fCurrentEntity != null && fCurrentEntity.entityLocation != null) ? fCurrentEntity.entityLocation.getPublicId() : null; } // getPublicId():String /** * Return the expanded system identifier for the current document event. * <p> * The return value is the expanded system identifier of the document * entity or of the external parsed entity in which the markup * triggering the event appears. * <p> * If the system identifier is a URL, the parser must resolve it * fully before passing it to the application. * * @return A string containing the expanded system identifier, or null * if none is available. */ public String getExpandedSystemId() { if (fCurrentEntity != null) { if (fCurrentEntity.entityLocation != null && fCurrentEntity.entityLocation.getExpandedSystemId() != null ) { return fCurrentEntity.entityLocation.getExpandedSystemId(); } else { // get the current entity to return something appropriate: return fCurrentEntity.getExpandedSystemId(); } } return null; } // getExpandedSystemId():String /** * Return the literal system identifier for the current document event. * <p> * The return value is the literal system identifier of the document * entity or of the external parsed entity in which the markup * triggering the event appears. * <p> * @return A string containing the literal system identifier, or null * if none is available. */ public String getLiteralSystemId() { if (fCurrentEntity != null) { if (fCurrentEntity.entityLocation != null && fCurrentEntity.entityLocation.getLiteralSystemId() != null ) { return fCurrentEntity.entityLocation.getLiteralSystemId(); } else { // get the current entity to do it: return fCurrentEntity.getLiteralSystemId(); } } return null; } // getLiteralSystemId():String /** * Return the line number where the current document event ends. * <p> * <strong>Warning:</strong> The return value from the method * is intended only as an approximation for the sake of error * reporting; it is not intended to provide sufficient information * to edit the character content of the original XML document. * <p> * The return value is an approximation of the line number * in the document entity or external parsed entity where the * markup triggering the event appears. * <p> * If possible, the SAX driver should provide the line position * of the first character after the text associated with the document * event. The first line in the document is line 1. * * @return The line number, or -1 if none is available. */ public int getLineNumber() { if (fCurrentEntity != null) { if (fCurrentEntity.isExternal()) { return fCurrentEntity.lineNumber; } else { // ask the current entity to return something appropriate: return fCurrentEntity.getLineNumber(); } } return -1; } // getLineNumber():int /** * Return the column number where the current document event ends. * <p> * <strong>Warning:</strong> The return value from the method * is intended only as an approximation for the sake of error * reporting; it is not intended to provide sufficient information * to edit the character content of the original XML document. * <p> * The return value is an approximation of the column number * in the document entity or external parsed entity where the * markup triggering the event appears. * <p> * If possible, the SAX driver should provide the line position * of the first character after the text associated with the document * event. * <p> * If possible, the SAX driver should provide the line position * of the first character after the text associated with the document * event. The first column in each line is column 1. * * @return The column number, or -1 if none is available. */ public int getColumnNumber() { if (fCurrentEntity != null) { if (fCurrentEntity.isExternal()) { return fCurrentEntity.columnNumber; } else { // ask current entity to find appropriate column number return fCurrentEntity.getColumnNumber(); } } return -1; } // getColumnNumber():int /** Returns the encoding of the current entity. * Note that, for a given entity, this value can only be * considered final once the encoding declaration has been read (or once it * has been determined that there is no such declaration) since, no encoding * having been specified on the XMLInputSource, the parser * will make an initial "guess" which could be in error. */ public String getEncoding() { if (fCurrentEntity != null) { if (fCurrentEntity.isExternal()) { return fCurrentEntity.encoding; } else { // ask current entity to find appropriate column number return fCurrentEntity.getEncoding(); } } return null; } // getEncoding():String /** * @see com.sun.org.apache.xerces.internal.xni.XMLLocator#setColumnNumber(int) */ public void setColumnNumber(int col) { // no-op } /** * @see com.sun.org.apache.xerces.internal.xni.XMLLocator#setLineNumber(int) */ public void setLineNumber(int line) { //no-op } /** * @see com.sun.org.apache.xerces.internal.xni.XMLResourceIdentifier#setBaseSystemId(String) */ public void setBaseSystemId(String systemId) { //no-op } /** * @see com.sun.org.apache.xerces.internal.xni.XMLResourceIdentifier#setExpandedSystemId
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?