public NodeProxy parentWithChild( DocumentImpl doc, NodeId nodeId, boolean directParent, boolean includeSelf) { NodeProxy temp = get(doc, nodeId); if (includeSelf && temp != null) return temp; nodeId = nodeId.getParentId(); while (nodeId != null) { temp = get(doc, nodeId); if (temp != null) return temp; else if (directParent) return null; nodeId = nodeId.getParentId(); } return null; }
/** * The method <code>getAncestors</code> * * @param contextId an <code>int</code> value * @param includeSelf a <code>boolean</code> value * @return a <code>NodeSet</code> value */ public NodeSet getAncestors(int contextId, boolean includeSelf) { ExtArrayNodeSet ancestors = new ExtArrayNodeSet(); for (Iterator i = iterator(); i.hasNext(); ) { NodeProxy current = (NodeProxy) i.next(); if (includeSelf) { if (Expression.NO_CONTEXT_ID != contextId) current.addContextNode(contextId, current); ancestors.add(current); } NodeId parentID = current.getNodeId().getParentId(); while (parentID != null) { // Filter out the temporary nodes wrapper element if (parentID != NodeId.DOCUMENT_NODE && !(parentID.getTreeLevel() == 1 && current.getDocument().getCollection().isTempCollection())) { NodeProxy parent = new NodeProxy(current.getDocument(), parentID, Node.ELEMENT_NODE); if (Expression.NO_CONTEXT_ID != contextId) parent.addContextNode(contextId, current); else parent.copyContext(current); ancestors.add(parent); } parentID = parentID.getParentId(); } } ancestors.mergeDuplicates(); return ancestors; }