elementschemepointer.java
来自「JAVA 所有包」· Java 代码 · 共 874 行 · 第 1/3 页
JAVA
874 行
0, fCurrentChildSequence.length); // Increase the size by a factor of 2 (?) fCurrentChildSequence = new int[fCurrentChildDepth * 2]; System.arraycopy(tmpCurrentChildSequence, 0, fCurrentChildSequence, 0, tmpCurrentChildSequence.length); } // if (fIsResolveElement) { // start if (event == XPointerPart.EVENT_ELEMENT_START) { fCurrentChildSequence[fCurrentChildDepth] = fCurrentChildPosition; fCurrentChildDepth++; // reset the current child position fCurrentChildPosition = 1; //if (!fSchemeNameFound) { if ((fCurrentChildDepth <= fFoundDepth) || (fFoundDepth == 0)) { if (checkMatch()) { fIsElementFound = true; fFoundDepth = fCurrentChildDepth; } else { fIsElementFound = false; fFoundDepth = 0; } } } else if (event == XPointerPart.EVENT_ELEMENT_END) { if (fCurrentChildDepth == fFoundDepth) { fIsElementFound = true; } else if (((fCurrentChildDepth < fFoundDepth) && (fFoundDepth != 0)) || ((fCurrentChildDepth > fFoundDepth) // or empty element found && (fFoundDepth == 0))) { fIsElementFound = false; } // reset array position of last child fCurrentChildSequence[fCurrentChildDepth] = 0; fCurrentChildDepth--; fCurrentChildPosition = fCurrentChildSequence[fCurrentChildDepth] + 1; } else if (event == XPointerPart.EVENT_ELEMENT_EMPTY) { fCurrentChildSequence[fCurrentChildDepth] = fCurrentChildPosition; fCurrentChildPosition++; // Donot check for empty elements if the empty element is // a child of a found parent element //if (!fIsElementFound) { if (checkMatch()) { fIsElementFound = true; fWasOnlyEmptyElementFound = true; } else { fIsElementFound = false; } //} } } return 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. * * @return boolean */ protected boolean checkMatch() { // If the number of elements in the ChildSequence is greater than the // current child depth, there is not point in checking further if (!fIsShortHand) { // If a shorthand pointer is not present traverse the children // and compare if (fChildSequence.length <= fCurrentChildDepth + 1) { for (int i = 0; i < fChildSequence.length; i++) { if (fChildSequence[i] != fCurrentChildSequence[i]) { return false; } } } else { return false; } } else { // If a shorthand pointer is present traverse the children // ignoring the first element of the CurrenChildSequence which // contains the ShortHand pointer element and compare if (fChildSequence.length <= fCurrentChildDepth + 1) { for (int i = 0; i < fChildSequence.length; i++) { // ensure fCurrentChildSequence is large enough if (fCurrentChildSequence.length < i + 2) { return false; } // ignore the first element of fCurrentChildSequence if (fChildSequence[i] != fCurrentChildSequence[i + 1]) { return false; } } } else { return false; } } return true; } /** * Returns true if the node matches or is a child of a matching element() * scheme XPointer. * * @see com.sun.org.apache.xerces.internal.xpointer.XPointerProcessor#isFragmentResolved() */ public boolean isFragmentResolved() throws XNIException { // 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 return fIsFragmentResolved ; } /** * 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() * */ public boolean isChildFragmentResolved() { // if only a shorthand pointer was present if (fIsShortHand && fShortHandPointer != null && fChildSequence.length <= 0) { return fShortHandPointer.isChildFragmentResolved(); } else { return fWasOnlyEmptyElementFound ? !fWasOnlyEmptyElementFound : (fIsFragmentResolved && (fCurrentChildDepth >= fFoundDepth)); } } /** * Reports an XPointer error */ protected void reportError(String key, Object[] arguments) throws XNIException { /*fErrorReporter.reportError(XPointerMessageFormatter.XPOINTER_DOMAIN, key, arguments, XMLErrorReporter.SEVERITY_ERROR); */ throw new XNIException((fErrorReporter .getMessageFormatter(XPointerMessageFormatter.XPOINTER_DOMAIN)) .formatMessage(fErrorReporter.getLocale(), key, arguments)); } /** * Initializes error handling objects */ protected void initErrorReporter() { if (fErrorReporter == null) { fErrorReporter = new XMLErrorReporter(); } if (fErrorHandler == null) { fErrorHandler = new XPointerErrorHandler(); } fErrorReporter.putMessageFormatter( XPointerMessageFormatter.XPOINTER_DOMAIN, new XPointerMessageFormatter()); } /** * Initializes the element scheme processor */ protected void init() { fSchemeName = null; fSchemeData = null; fShortHandPointerName = null; fIsResolveElement = false; fIsElementFound = false; fWasOnlyEmptyElementFound = false; fFoundDepth = 0; fCurrentChildPosition = 1; fCurrentChildDepth = 0; fIsFragmentResolved = false; fShortHandPointer = null; initErrorReporter(); } // ************************************************************************ // element() Scheme expression scanner // ************************************************************************ /** * List of XPointer Framework tokens. * * @xerces.internal * * @author Neil Delima, IBM * @version $Id: ElementSchemePointer.java,v 1.1.4.1 2005/09/08 05:25:43 sunithareddy Exp $ * */ private final class Tokens { /** * XPointer element() scheme * [1] ElementSchemeData ::= (NCName ChildSequence?) | ChildSequence * [2] ChildSequence ::= ('/' [1-9] [0-9]*)+ */ private static final int XPTRTOKEN_ELEM_NCNAME = 0; private static final int XPTRTOKEN_ELEM_CHILD = 1; // Token names private final String[] fgTokenNames = { "XPTRTOKEN_ELEM_NCNAME", "XPTRTOKEN_ELEM_CHILD" }; // Token count private static final int INITIAL_TOKEN_COUNT = 1 << 8; private int[] fTokens = new int[INITIAL_TOKEN_COUNT]; private int fTokenCount = 0; // Current token position private int fCurrentTokenIndex; private SymbolTable fSymbolTable; private Hashtable fTokenNames = new Hashtable(); /** * Constructor * * @param symbolTable SymbolTable */ private Tokens(SymbolTable symbolTable) { fSymbolTable = symbolTable; fTokenNames.put(new Integer(XPTRTOKEN_ELEM_NCNAME), "XPTRTOKEN_ELEM_NCNAME"); fTokenNames.put(new Integer(XPTRTOKEN_ELEM_CHILD), "XPTRTOKEN_ELEM_CHILD"); } /* * Returns the token String * @param token The index of the token * @return String The token string */ private String getTokenString(int token) { return (String) fTokenNames.get(new Integer(token)); } /** * Returns the token String * @param token The index of the token * @return String The token string */ private Integer getToken(int token) { return (Integer) fTokenNames.get(new Integer(token)); } /** * Add the specified string as a token * * @param token The token string */ private void addToken(String tokenStr) { Integer tokenInt = (Integer) fTokenNames.get(tokenStr); if (tokenInt == null) { tokenInt = new Integer(fTokenNames.size()); fTokenNames.put(tokenInt, tokenStr); } addToken(tokenInt.intValue()); } /** * Add the specified int token * * @param token The int specifying the token */ private void addToken(int token) { try { fTokens[fTokenCount] = token; } catch (ArrayIndexOutOfBoundsException ex) { int[] oldList = fTokens; fTokens = new int[fTokenCount << 1]; System.arraycopy(oldList, 0, fTokens, 0, fTokenCount); fTokens[fTokenCount] = token;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?