Search in sources :

Example 11 with NodePath

use of org.exist.storage.NodePath in project exist by eXist-db.

the class ContentFunctions method streamContent.

private Sequence streamContent(ContentExtraction ce, BinaryValue binary, Sequence pathSeq, FunctionReference ref, Map<String, String> mappings, Sequence data) throws XPathException {
    NodePath[] paths = new NodePath[pathSeq.getItemCount()];
    int i = 0;
    for (SequenceIterator iter = pathSeq.iterate(); iter.hasNext(); i++) {
        String path = iter.nextItem().getStringValue();
        paths[i] = new NodePath(mappings, path, false);
    }
    ContentReceiver receiver = new ContentReceiver(context, paths, ref, data);
    try {
        ce.extractContentAndMetadata(binary, receiver);
    } catch (IOException | SAXException | ContentExtractionException ex) {
        LOG.error(ex.getMessage(), ex);
        throw new XPathException(this, ex.getMessage(), ex);
    }
    return receiver.getResult();
}
Also used : SequenceIterator(org.exist.xquery.value.SequenceIterator) XPathException(org.exist.xquery.XPathException) IOException(java.io.IOException) ContentReceiver(org.exist.contentextraction.ContentReceiver) ContentExtractionException(org.exist.contentextraction.ContentExtractionException) NodePath(org.exist.storage.NodePath) SAXException(org.xml.sax.SAXException)

Example 12 with NodePath

use of org.exist.storage.NodePath in project exist by eXist-db.

the class IndexStatisticsWorker method updateDocument.

private void updateDocument(final DBBroker broker, final DocumentImpl doc) {
    final ElementImpl root = (ElementImpl) doc.getDocumentElement();
    final int rootLevel = root.getNodeId().getTreeLevel();
    try {
        final NodePath path = new NodePath();
        final Deque<NodeStats> stack = new ArrayDeque<>();
        final ExtendedXMLStreamReader reader = broker.getXMLStreamReader(root, false);
        while (reader.hasNext()) {
            final int status = reader.next();
            switch(status) {
                case XMLStreamReader.START_ELEMENT:
                    for (final NodeStats next : stack) {
                        next.incDepth();
                    }
                    final QName qname = reader.getQName();
                    path.addComponent(qname);
                    final NodeStats nodeStats = perDocGuide.add(path);
                    stack.push(nodeStats);
                    break;
                case XMLStreamReader.END_ELEMENT:
                    path.removeLastComponent();
                    final NodeStats stats = stack.pop();
                    stats.updateMaxDepth();
                    final NodeId otherId = (NodeId) reader.getProperty(ExtendedXMLStreamReader.PROPERTY_NODE_ID);
                    final int otherLevel = otherId.getTreeLevel();
                    if (otherLevel == rootLevel) {
                        // exit-while
                        break;
                    }
                    break;
            }
        }
    } catch (final IOException | XMLStreamException e) {
        e.printStackTrace();
    }
}
Also used : ExtendedXMLStreamReader(org.exist.stax.ExtendedXMLStreamReader) ElementImpl(org.exist.dom.persistent.ElementImpl) XMLStreamException(javax.xml.stream.XMLStreamException) QName(org.exist.dom.QName) NodeId(org.exist.numbering.NodeId) IOException(java.io.IOException) NodePath(org.exist.storage.NodePath) ArrayDeque(java.util.ArrayDeque)

Example 13 with NodePath

use of org.exist.storage.NodePath in project exist by eXist-db.

the class NodeStats method mergeInto.

protected void mergeInto(DataGuide other, NodePath currentPath) {
    NodePath newPath;
    if (qname == null) {
        newPath = currentPath;
    } else {
        newPath = new NodePath(currentPath);
        newPath.addComponent(qname);
        other.add(newPath, this);
    }
    if (children != null) {
        for (final NodeStats child : children) {
            child.mergeInto(other, newPath);
        }
    }
}
Also used : NodePath(org.exist.storage.NodePath)

Example 14 with NodePath

use of org.exist.storage.NodePath in project exist by eXist-db.

the class RangeQueryRewriter method toNodePath.

protected static NodePath toNodePath(List<LocationStep> steps) {
    NodePath path = new NodePath();
    for (LocationStep step : steps) {
        if (step == null) {
            return null;
        }
        NodeTest test = step.getTest();
        if (test.isWildcardTest() && step.getAxis() == Constants.SELF_AXIS) {
            // return path;
            continue;
        }
        if (!test.isWildcardTest() && test.getName() != null) {
            int axis = step.getAxis();
            if (axis == Constants.DESCENDANT_AXIS || axis == Constants.DESCENDANT_SELF_AXIS) {
                path.addComponent(NodePath.SKIP);
            } else if (axis != Constants.CHILD_AXIS && axis != Constants.ATTRIBUTE_AXIS) {
                // not optimizable
                return null;
            }
            path.addComponent(test.getName());
        }
    }
    return path;
}
Also used : NodePath(org.exist.storage.NodePath)

Aggregations

NodePath (org.exist.storage.NodePath)14 IOException (java.io.IOException)4 Reader (java.io.Reader)2 StringReader (java.io.StringReader)2 Nullable (javax.annotation.Nullable)2 XMLStreamException (javax.xml.stream.XMLStreamException)2 Analyzer (org.apache.lucene.analysis.Analyzer)2 TokenStream (org.apache.lucene.analysis.TokenStream)2 CharTermAttribute (org.apache.lucene.analysis.tokenattributes.CharTermAttribute)2 OffsetAttribute (org.apache.lucene.analysis.tokenattributes.OffsetAttribute)2 Term (org.apache.lucene.index.Term)2 PhraseQuery (org.apache.lucene.search.PhraseQuery)2 Query (org.apache.lucene.search.Query)2 MemTreeBuilder (org.exist.dom.memtree.MemTreeBuilder)2 ElementImpl (org.exist.dom.persistent.ElementImpl)2 NodeId (org.exist.numbering.NodeId)2 ExtendedXMLStreamReader (org.exist.stax.ExtendedXMLStreamReader)2 ArrayDeque (java.util.ArrayDeque)1 State (org.apache.lucene.util.AttributeSource.State)1 Collection (org.exist.collections.Collection)1