ElementSchemePointer.java revision 286
325N/A * reserved comment block 325N/A * DO NOT REMOVE OR ALTER! 325N/A * Copyright 2005 The Apache Software Foundation. 325N/A * Licensed under the Apache License, Version 2.0 (the "License"); 325N/A * you may not use this file except in compliance with the License. 325N/A * You may obtain a copy of the License at 325N/A * Unless required by applicable law or agreed to in writing, software 325N/A * distributed under the License is distributed on an "AS IS" BASIS, 325N/A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 325N/A * See the License for the specific language governing permissions and 325N/A * limitations under the License. 325N/A * Implements the XPointerPart interface for element() scheme specific processing. 325N/A // The Scheme Name i.e element 325N/A // The scheme Data & child sequence 325N/A // Should we attempt to resolve the ChildSequence from the 325N/A // current element position. If a ShortHand Pointer is present 325N/A // attempt to resolve relative to the short hand pointer. 325N/A // Has the element been found // Was only an empty element found // If a shorthand pointer is present and resolved // The depth at which the element was found // The XPointer element child sequence // The current child position // The current child depth // The current element's child sequence // Stores if the Fragment was resolved by the pointer // Stores if the Fragment was resolved by the pointer // The XPointer Error reporter // The XPointer Error Handler // ************************************************************************ // ************************************************************************ // ************************************************************************ // XPointerPart implementation // ************************************************************************ * Parses the XPointer expression and tokenizes it into Strings * delimited by whitespace. * @see com.sun.org.apache.xerces.internal.xpointer.XPointerProcessor#parseXPointer(java.lang.String) // scan the element() XPointer expression // Initialize a temp arrays to the size of token count which should // be atleast twice the size of child sequence, to hold the ChildSequence. // Traverse the scanned tokens // Note: Only a single ShortHand pointer can be present // Create a new ShortHandPointer // Initialize the arrays to the number of elements in the ChildSequence. * Returns the scheme name i.e element * @see com.sun.org.apache.xerces.internal.xpointer.XPointerPart#getSchemeName() * Returns the scheme data * @see com.sun.org.apache.xerces.internal.xpointer.XPointerPart#getSchemeData() * @see com.sun.org.apache.xerces.internal.xpointer.XPointerPart#setSchemeName(java.lang.String) * @see com.sun.org.apache.xerces.internal.xpointer.XPointerPart#setSchemeData(java.lang.String) * Responsible for resolving the element() scheme XPointer. If a ShortHand * Pointer is present and it is successfully resolved and if a child * sequence is present, the child sequence is resolved relative to it. * @see com.sun.org.apache.xerces.internal.xpointer.XPointerProcessor#resolveXPointer(com.sun.org.apache.xerces.internal.xni.QName, com.sun.org.apache.xerces.internal.xni.XMLAttributes, com.sun.org.apache.xerces.internal.xni.Augmentations, int event) // if a ChildSequence exisits, resolve child elements // if an element name exists // resolve ShortHand Pointer // Added here to skip the ShortHand pointer corresponding to // an element if one exisits and start searching from its child // if only a resolved shorthand pointer exists * Matches the current element position in the document tree with the * element position specified in the element XPointer scheme. * @return boolean - true if the current element position in the document * tree matches theelement position specified in the element XPointer // need to resize fCurrentChildSequence // Increase the size by a factor of 2 (?) // reset the current child position //if (!fSchemeNameFound) { // reset array position of last child // Donot check for empty elements if the empty element is // a child of a found parent element //if (!fIsElementFound) { * Matches the current position of the element being visited by checking * its position and previous elements against the element XPointer expression. * If a match is found it return true else false. // If the number of elements in the ChildSequence is greater than the // current child depth, there is not point in checking further // If a shorthand pointer is not present traverse the children // If a shorthand pointer is present traverse the children // ignoring the first element of the CurrenChildSequence which // contains the ShortHand pointer element and compare // ensure fCurrentChildSequence is large enough // ignore the first element of fCurrentChildSequence * Returns true if the node matches or is a child of a matching element() * @see com.sun.org.apache.xerces.internal.xpointer.XPointerProcessor#isFragmentResolved() // Return true if the Fragment was resolved and the current Node depth // is greater than or equal to the depth at which the element was found * Returns true if the XPointer expression resolves to a non-element child * of the current resource fragment. * @see com.sun.org.apache.xerces.internal.xpointer.XPointerPart#isChildFragmentResolved() // if only a shorthand pointer was present * Reports an XPointer error /*fErrorReporter.reportError(XPointerMessageFormatter.XPOINTER_DOMAIN, key, arguments, XMLErrorReporter.SEVERITY_ERROR); * Initializes error handling objects * Initializes the element scheme processor // ************************************************************************ // element() Scheme expression scanner // ************************************************************************ * List of XPointer Framework tokens. * @author Neil Delima, IBM * XPointer element() scheme * [1] ElementSchemeData ::= (NCName ChildSequence?) | ChildSequence * [2] ChildSequence ::= ('/' [1-9] [0-9]*)+ "XPTRTOKEN_ELEM_CHILD" };
// Current token position * @param symbolTable SymbolTable "XPTRTOKEN_ELEM_NCNAME");
* Returns the token String * @param token The index of the token * @return String The token string * Returns the token String * @param token The index of the token * @return String The token string * Add the specified string as a token * @param token The token string * Add the specified int token * @param token The int specifying the token * Resets the current position to the head of the token list. * Returns true if the {@link #getNextToken()} method * 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>. * Obtains the token at the current position, without advancing * If there's no such next token, this method throws * <tt>new XNIException("InvalidXPointerExpression");</tt>. * 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>. * Returns the number of tokens. * The XPointer expression scanner. Scans the XPointer framework expression. * 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 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 };
* Constructs an XPath expression scanner. * @param symbolTable SymbolTable * Scans the XPointer Expression // [1] ElementSchemeData ::= (NCName ChildSequence?) | ChildSequence // [2] ChildSequence ::= ('/' [1-9] [0-9]*)+ // if last character is '/', break and report an error // ChildSequence ::= ('/' [1-9] [0-9]*)+ while (
ch >=
'0' &&
ch <=
'9') {
// An invalid child sequence character // Scan the ShortHand Pointer NCName * [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 * 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