elementschemepointer.java
来自「JAVA 所有包」· Java 代码 · 共 874 行 · 第 1/3 页
JAVA
874 行
} fTokenCount++; } /** * Resets the current position to the head of the token list. */ private void rewind() { fCurrentTokenIndex = 0; } /** * Returns true if the {@link #getNextToken()} method * returns a valid token. */ private boolean hasMore() { return fCurrentTokenIndex < fTokenCount; } /** * Obtains the token at the current position, then advance * the current position by one. * * If there's no such next token, this method throws * <tt>new XNIException("InvalidXPointerExpression");</tt>. */ private int nextToken() throws XNIException { if (fCurrentTokenIndex == fTokenCount) reportError("XPointerElementSchemeProcessingError", null); return fTokens[fCurrentTokenIndex++]; } /** * Obtains the token at the current position, without advancing * the current position. * * If there's no such next token, this method throws * <tt>new XNIException("InvalidXPointerExpression");</tt>. */ private int peekToken() throws XNIException { if (fCurrentTokenIndex == fTokenCount) reportError("XPointerElementSchemeProcessingError", null); return fTokens[fCurrentTokenIndex]; } /** * Obtains the token at the current position as a String. * * If there's no current token or if the current token * is not a string token, this method throws * If there's no such next token, this method throws * <tt>new XNIException("InvalidXPointerExpression");</tt>. */ private String nextTokenAsString() throws XNIException { String s = getTokenString(nextToken()); if (s == null) reportError("XPointerElementSchemeProcessingError", null); return s; } /** * Returns the number of tokens. * */ private int getTokenCount() { return fTokenCount; } } /** * * The XPointer expression scanner. Scans the XPointer framework expression. * * @xerces.internal * * @version $Id: ElementSchemePointer.java,v 1.1.4.1 2005/09/08 05:25:43 sunithareddy Exp $ */ private class Scanner { /** * 7-bit ASCII subset * * 0 1 2 3 4 5 6 7 8 9 A B C D E F * 0, 0, 0, 0, 0, 0, 0, 0, 0, HT, LF, 0, 0, CR, 0, 0, // 0 * 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 1 * SP, !, ", #, $, %, &, ', (, ), *, +, ,, -, ., /, // 2 * 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, :, ;, <, =, >, ?, // 3 * @, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, // 4 * P, Q, R, S, T, U, V, W, X, Y, Z, [, \, ], ^, _, // 5 * `, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, // 6 * p, q, r, s, t, u, v, w, x, y, z, {, |, }, ~, DEL // 7 */ private static final byte CHARTYPE_INVALID = 0, // invalid XML characters, control characters and 7F CHARTYPE_OTHER = 1, // A valid XML character (possibly invalid NCNameChar) that does not fall in one of the other categories CHARTYPE_MINUS = 2, // '-' (0x2D) CHARTYPE_PERIOD = 3, // '.' (0x2E) CHARTYPE_SLASH = 4, // '/' (0x2F) CHARTYPE_DIGIT = 5, // '0'-'9' (0x30 to 0x39) CHARTYPE_LETTER = 6, // 'A'-'Z' or 'a'-'z' (0x41 to 0x5A and 0x61 to 0x7A) CHARTYPE_UNDERSCORE = 7, // '_' (0x5F) CHARTYPE_NONASCII = 8; // Non-ASCII Unicode codepoint (>= 0x80) private final byte[] fASCIICharMap = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 1, 1, 1, 1, 1, 1, 1, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 1, 1, 1, 1, 7, 1, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 1, 1, 1, 1, 1 }; /** * Symbol literals */ // // Data // /** Symbol table. */ private SymbolTable fSymbolTable; // // Constructors // /** * Constructs an XPath expression scanner. * * @param symbolTable SymbolTable */ private Scanner(SymbolTable symbolTable) { // save pool and tokens fSymbolTable = symbolTable; } // <init>(SymbolTable) /** * Scans the XPointer Expression * */ private boolean scanExpr(SymbolTable symbolTable, Tokens tokens, String data, int currentOffset, int endOffset) throws XNIException { int ch; int nameOffset; String nameHandle = null; while (true) { if (currentOffset == endOffset) { break; } ch = data.charAt(currentOffset); byte chartype = (ch >= 0x80) ? CHARTYPE_NONASCII : fASCIICharMap[ch]; // // [1] ElementSchemeData ::= (NCName ChildSequence?) | ChildSequence // [2] ChildSequence ::= ('/' [1-9] [0-9]*)+ // switch (chartype) { case CHARTYPE_SLASH: // if last character is '/', break and report an error if (++currentOffset == endOffset) { return false; } addToken(tokens, Tokens.XPTRTOKEN_ELEM_CHILD); ch = data.charAt(currentOffset); // ChildSequence ::= ('/' [1-9] [0-9]*)+ int child = 0; while (ch >= '0' && ch <= '9') { child = (child * 10) + (ch - '0'); if (++currentOffset == endOffset) { break; } ch = data.charAt(currentOffset); } // An invalid child sequence character if (child == 0) { reportError("InvalidChildSequenceCharacter", new Object[] { new Character((char) ch) }); return false; } tokens.addToken(child); break; case CHARTYPE_DIGIT: case CHARTYPE_LETTER: case CHARTYPE_MINUS: case CHARTYPE_NONASCII: case CHARTYPE_OTHER: case CHARTYPE_PERIOD: case CHARTYPE_UNDERSCORE: // Scan the ShortHand Pointer NCName nameOffset = currentOffset; currentOffset = scanNCName(data, endOffset, currentOffset); if (currentOffset == nameOffset) { //return false; reportError("InvalidNCNameInElementSchemeData", new Object[] { data }); return false; } if (currentOffset < endOffset) { ch = data.charAt(currentOffset); } else { ch = -1; } nameHandle = symbolTable.addSymbol(data.substring( nameOffset, currentOffset)); addToken(tokens, Tokens.XPTRTOKEN_ELEM_NCNAME); tokens.addToken(nameHandle); break; } } return true; } /** * Scans a NCName. * From Namespaces in XML * [5] NCName ::= (Letter | '_') (NCNameChar)* * [6] NCNameChar ::= Letter | Digit | '.' | '-' | '_' | CombiningChar | Extender * * @param data A String containing the XPointer expression * @param endOffset The int XPointer expression length * @param currentOffset An int representing the current position of the XPointer expression pointer */ private int scanNCName(String data, int endOffset, int currentOffset) { int ch = data.charAt(currentOffset); if (ch >= 0x80) { if (!XMLChar.isNameStart(ch)) { return currentOffset; } } else { byte chartype = fASCIICharMap[ch]; if (chartype != CHARTYPE_LETTER && chartype != CHARTYPE_UNDERSCORE) { return currentOffset; } } while (++currentOffset < endOffset) { ch = data.charAt(currentOffset); if (ch >= 0x80) { if (!XMLChar.isName(ch)) { break; } } else { byte chartype = fASCIICharMap[ch]; if (chartype != CHARTYPE_LETTER && chartype != CHARTYPE_DIGIT && chartype != CHARTYPE_PERIOD && chartype != CHARTYPE_MINUS && chartype != CHARTYPE_UNDERSCORE) { break; } } } return currentOffset; } // // Protected methods // /** * This method adds the specified token to the token list. By * default, this method allows all tokens. However, subclasses * of the XPathExprScanner can override this method in order * to disallow certain tokens from being used in the scanned * XPath expression. This is a convenient way of allowing only * a subset of XPath. */ protected void addToken(Tokens tokens, int token) throws XNIException { tokens.addToken(token); } // addToken(int) } // class Scanner}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?