Search in sources :

Example 1 with NodePath2

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;
}
Also used : NodePath2(org.exist.storage.NodePath2) Node(org.w3c.dom.Node)

Example 2 with NodePath2

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;
}
Also used : NodePath2(org.exist.storage.NodePath2) IStoredNode(org.exist.dom.persistent.IStoredNode)

Example 3 with NodePath2

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;
}
Also used : NodePath2(org.exist.storage.NodePath2) IStoredNode(org.exist.dom.persistent.IStoredNode)

Example 4 with NodePath2

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);
}
Also used : NodePath2(org.exist.storage.NodePath2) QName(org.exist.dom.QName)

Aggregations

NodePath2 (org.exist.storage.NodePath2)4 IStoredNode (org.exist.dom.persistent.IStoredNode)2 QName (org.exist.dom.QName)1 Node (org.w3c.dom.Node)1