📄 nodefilterlocator.java
字号:
subQueryResults = addNode( subQueryResults, pos ); } } } Node nextNode = pos.getFirstChild(); while (null == nextNode) { if (context.equals( pos )) { break; } nextNode = pos.getNextSibling(); if (null == nextNode) { pos = pos.getParentNode(); if (context.equals( pos ) || pos == null) { nextNode = null; break; } } } pos = nextNode; } } } return subQueryResults; } /** need overwrite this method, to call traversal methods */ protected MutableNodeList findFollowing( XPath xpath, XPathSupport execContext, Node context, int opPos, int stepType, MutableNodeList subQueryResults, boolean isSimpleFollowing, boolean stopAtFirst ) throws org.xml.sax.SAXException { System.out.println( "findFollowing()" ); int argLen = xpath.getArgLengthOfStep( opPos ); opPos = xpath.getFirstChildPosOfStep( opPos ); // What fun... Document doc = context.getOwnerDocument(); // DOM2-Traversal // save the current walker node! Node savedNode = walker.getCurrentNode(); Node pos = savedNode; while (null != pos) { Node nextNode; if (pos != context) { if (XPath.MATCH_SCORE_NONE != nodeTest( xpath, execContext, pos, opPos, argLen, stepType )) { subQueryResults = addNodeInDocOrder( execContext, subQueryResults, pos ); } // DOM2-Traversal nextNode = walker.firstChild(); } else { nextNode = null; } while (null == nextNode) { // DOM2-Traversal nextNode = walker.nextSibling(); if (null == nextNode) { // DOM2-Traversal pos = walker.parentNode(); if (doc == pos || null == pos) { nextNode = null; break; } } } pos = nextNode; } // DOM2-Traversal // reset the current walker node! walker.setCurrentNode( savedNode ); return subQueryResults; } /** need overwrite this method, to call traversal methods */ protected MutableNodeList findFollowingSiblings( XPath xpath, XPathSupport execContext, Node context, int opPos, int stepType, MutableNodeList subQueryResults, boolean isSimpleFollowing, boolean stopAtFirst ) throws org.xml.sax.SAXException { System.out.println( "NodeFilterLocator.findFollowinSiblings ()" ); int argLen = xpath.getArgLengthOfStep( opPos ); opPos = xpath.getFirstChildPosOfStep( opPos ); // DOM2-Traversal // save the current walker node! Node savedNode = walker.getCurrentNode(); Node pos = walker.nextSibling(); while (null != pos) { if (XPath.MATCH_SCORE_NONE != nodeTest( xpath, execContext, pos, opPos, argLen, stepType )) { subQueryResults = addNode( subQueryResults, pos ); } // DOM2-Traversal pos = walker.nextSibling(); } // DOM2-Traversal // reset the current walker node! walker.setCurrentNode( savedNode ); return subQueryResults; } /** need overwrite this method, to call traversal methods */ protected MutableNodeList findPreceding( XPath xpath, XPathSupport execContext, Node context, int opPos, int stepType, MutableNodeList subQueryResults, boolean isSimpleFollowing, boolean stopAtFirst ) throws org.xml.sax.SAXException { System.out.println( "findPreceding()" ); return super.findPreceding( xpath, execContext, context, opPos, stepType, subQueryResults, isSimpleFollowing, stopAtFirst ); } /** need overwrite this method, to call traversal methods */ protected MutableNodeList findPrecedingSiblings( XPath xpath, XPathSupport execContext, Node context, int opPos, int stepType, MutableNodeList subQueryResults, boolean isSimpleFollowing, boolean stopAtFirst ) throws org.xml.sax.SAXException { System.out.println( "findPrecedingSiblings()" ); int argLen = xpath.getArgLengthOfStep( opPos ); opPos = xpath.getFirstChildPosOfStep( opPos ); // DOM2-Traversal // save the current walker node! Node savedNode = walker.getCurrentNode(); Node pos = walker.previousSibling(); while (null != pos) { if (XPath.MATCH_SCORE_NONE != nodeTest( xpath, execContext, pos, opPos, argLen, stepType )) { subQueryResults = addNode( subQueryResults, pos ); } // DOM2-Traversal pos = walker.previousSibling(); } // DOM2-Traversal // reset the current walker node! walker.setCurrentNode( savedNode ); return subQueryResults; } /** need overwrite this method, to call traversal methods */ protected Node stepPattern( XPath xpath, XPathSupport execContext, Node context, int opPos, double[] scoreHolder ) throws org.xml.sax.SAXException { System.out.println( "stepPattern()" ); return super.stepPattern( xpath, execContext, context, opPos, scoreHolder ); } /** need to implement this method again, b/c its private in my super class */ private final MutableNodeList addNode( MutableNodeList subQueryResults, Node node ) { if (null == subQueryResults) { subQueryResults = new MutableNodeListImpl( node ); } else { subQueryResults.addNode( node ); } return subQueryResults; } /** need to implement this method again, b/c its private in my super class */ private final MutableNodeList addNodeInDocOrder( XPathSupport execContext, MutableNodeList subQueryResults, Node node ) { if (null == subQueryResults) { subQueryResults = new MutableNodeListImpl( node ); } else { subQueryResults.addNodeInDocOrder( node, execContext ); } return subQueryResults; } }/** Override the createXLocatorHandler method. */class FilterXPath extends XPath { public FilterXPath() { super( new org.apache.xalan.xpath.xml.ProblemListenerDefault() ); } public XLocator createXLocatorHandler( XPath xpath ) { return new NodeFilterLocator(); } }/** Implement an XPath factory. */class NodeFilterLocatorFactory extends java.lang.Object implements XPathFactory { public XPath create() { return new FilterXPath(); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -