use of org.exist.storage.NodePath2 in project exist by eXist-db.
the class StoredNode method getPath.
// protected StoredNode getLastNode(final Iterator<StoredNode> iterator, final StoredNode node) {
// if(!node.hasChildNodes()) {
// return node;
// }
// final int children = node.getChildCount();
// StoredNode next = null;
// for(int i = 0; i < children; i++) {
// next = iterator.next();
// //Recursivity helps taversing...
// next = getLastNode(iterator, next);
// }
// return next;
// }
@Override
public NodePath getPath() {
final NodePath2 path = new NodePath2();
if (getNodeType() == Node.ELEMENT_NODE) {
path.addNode(this);
}
Node parent;
if (getNodeType() == Node.ATTRIBUTE_NODE) {
parent = ((Attr) this).getOwnerElement();
} else {
parent = getParentNode();
}
while (parent != null && parent.getNodeType() != Node.DOCUMENT_NODE) {
path.addNode(parent);
parent = parent.getParentNode();
}
path.reverseNodes();
return path;
}
use of org.exist.storage.NodePath2 in project exist by eXist-db.
the class RangeIndexWorker method getReindexRoot.
@Override
public <T extends IStoredNode> IStoredNode getReindexRoot(IStoredNode<T> node, NodePath path, boolean insert, boolean includeSelf) {
// return null;
if (config == null)
return null;
NodePath2 p = new NodePath2((NodePath2) path);
boolean reindexRequired = false;
if (node.getNodeType() == Node.ELEMENT_NODE && !includeSelf) {
p.removeLastNode();
}
while (p.length() > 0) {
if (config.matches(p)) {
reindexRequired = true;
break;
}
p.removeLastNode();
}
if (reindexRequired) {
p = new NodePath2((NodePath2) path);
IStoredNode topMost = null;
IStoredNode currentNode = node;
if (currentNode.getNodeType() != Node.ELEMENT_NODE)
currentNode = currentNode.getParentStoredNode();
while (currentNode != null) {
if (config.matches(p))
topMost = currentNode;
currentNode = currentNode.getParentStoredNode();
p.removeLastNode();
}
return topMost;
}
return null;
}
use of org.exist.storage.NodePath2 in project exist by eXist-db.
the class LuceneMatchListener method getPath.
public static NodePath getPath(final NodeProxy proxy) {
final NodePath2 path = new NodePath2();
final IStoredNode<?> node = (IStoredNode<?>) proxy.getNode();
walkAncestor(node, path);
return path;
}
use of org.exist.storage.NodePath2 in project exist by eXist-db.
the class NodePathPattern method match.
private final boolean match(final NodePath o, final int from_pos) {
// TODO cast NodePath to NodePath2 and do 'extended' matching
final NodePath2 other = (NodePath2) o;
final int other_len = other.length();
final int len = qnPath.length();
boolean skip = false;
int i = 0;
QName components_i = null;
for (int j = from_pos; j < other_len; j++) {
if (i == len) {
return qnPath.includeDescendants();
}
if (components_i == null)
components_i = qnPath.getComponent(i);
if (components_i == NodePath.SKIP) {
components_i = qnPath.getComponent(++i);
skip = true;
}
if ((components_i == NodePath.WILDCARD || other.getComponent(j).compareTo(components_i) == 0) && predicates.get(i).evaluate(other, j) && (!skip || j + 1 == other_len || other.getComponent(j + 1).compareTo(components_i) != 0 || !predicates.get(i).evaluate(other, j + 1))) {
++i;
components_i = null;
skip = false;
} else if (skip) {
continue;
} else {
return false;
}
}
return (i == len);
}
Aggregations