/** * Get the number of places down that the current Node is from the root Node. * Returns 1 if current Node is a child of the root Node. * Returns 0 if this NodeTreeWalker has not yet traversed to any Nodes. * @return The depth the current Node is from the root Node. */ public int getCurrentNodeDepth() { int depth = 0; if (this.mCurrentNode != null)//if we are not at the root Node. { Node traverseNode = this.mCurrentNode; while (traverseNode != this.mRootNode) { ++depth; traverseNode = traverseNode.getParent(); } } return (depth); }
public boolean accept(Node n) { while (n != null) { n = n.getParent(); if (atest.accept(n)) return true; } return false; } }
public boolean accept (Node n) { while (n != null) { n = n.getParent (); if (atest.accept (n)) return (true); } return (false); } }
public void visitEndTag(Tag tag) { Node parent; parent = tag.getParent (); // process only those nodes not processed by a parent if (null == parent) // an orphan end tag modifiedResult.append(tag.toHtml()); else if (null == parent.getParent ()) // a top level tag with no parents modifiedResult.append(parent.toHtml()); }
public void visitEndTag(Tag tag) { Node parent; parent = tag.getParent (); // process only those nodes not processed by a parent if (null == parent) // an orphan end tag modifiedResult.append(tag.toHtml()); else if (null == parent.getParent ()) // a top level tag with no parents modifiedResult.append(parent.toHtml()); }
/** * Traverses to the next Node from the current Node using depth-first tree traversal * @return The next Node from the current Node using depth-first tree traversal. */ protected Node getNextNodeDepthFirst() { //loosely based on http://www.myarch.com/treeiter/traditways.jhtml int currentDepth = getCurrentNodeDepth(); Node traverseNode = null; if ((this.mMaxDepth == -1) || (currentDepth < this.mMaxDepth))//if it is less than max depth, then getting first child won't be more than max depth { traverseNode = this.mCurrentNode.getFirstChild(); if (traverseNode != null) return (traverseNode); } traverseNode = this.mCurrentNode; Node tempNextSibling = null;//keeping a reference to this this saves calling getNextSibling once later while ((traverseNode != this.mRootNode) && (tempNextSibling = traverseNode.getNextSibling()) == null)//CANNOT assign traverseNode as root Node traverseNode = traverseNode.getParent();// use child-parent link to get to the parent level return (tempNextSibling);//null if ran out of Node's }
public void visitTag(Tag tag) { if (tag instanceof LinkTag) ((LinkTag)tag).setLink(linkPrefix + ((LinkTag)tag).getLink()); else if (tag instanceof ImageTag) ((ImageTag)tag).setImageURL(linkPrefix + ((ImageTag)tag).getImageURL()); // process only those nodes that won't be processed by an end tag, // nodes without parents or parents without an end tag, since // the complete processing of all children should happen before // we turn this node back into html text if (null == tag.getParent () && (!(tag instanceof CompositeTag) || null == ((CompositeTag)tag).getEndTag ())) modifiedResult.append(tag.toHtml()); }
/** * Accept tags with parent acceptable to the filter. * If recursion is enabled, each parent in turn up to * the topmost enclosing node is checked. * Recursion only proceeds while no parent satisfies the * filter. * @param node The node to check. * @return <code>true</code> if the node has an acceptable parent, * <code>false</code> otherwise. */ public boolean accept (Node node) { Node parent; boolean ret; ret = false; if (!(node instanceof Tag) || !((Tag)node).isEndTag ()) { parent = node.getParent (); if ((null != parent) && (null != getParentFilter ())) { ret = getParentFilter ().accept (parent); if (!ret && getRecursive ()) ret = accept (parent); } } return (ret); } }
/** * Accept tags with parent acceptable to the filter. * If recursion is enabled, each parent in turn up to * the topmost enclosing node is checked. * Recursion only proceeds while no parent satisfies the * filter. * @param node The node to check. * @return <code>true</code> if the node has an acceptable parent, * <code>false</code> otherwise. */ public boolean accept (Node node) { Node parent; boolean ret; ret = false; if (!(node instanceof Tag) || !((Tag)node).isEndTag ()) { parent = node.getParent (); if ((null != parent) && (null != getParentFilter ())) { ret = getParentFilter ().accept (parent); if (!ret && getRecursive ()) ret = accept (parent); } } return (ret); } }
if (!(node instanceof Tag) || !((Tag)node).isEndTag ()) parent = node.getParent (); if (null != parent)
if (!(node instanceof Tag) || !((Tag)node).isEndTag ()) parent = node.getParent (); if (null != parent)