Search in sources :

Example 1 with ExtendedXMLStreamReader

use of org.exist.stax.ExtendedXMLStreamReader in project exist by eXist-db.

the class XQueryContext method getXMLStreamReader.

@Override
public ExtendedXMLStreamReader getXMLStreamReader(final NodeValue nv) throws XMLStreamException, IOException {
    final ExtendedXMLStreamReader reader;
    if (nv.getImplementationType() == NodeValue.IN_MEMORY_NODE) {
        final NodeImpl node = (NodeImpl) nv;
        final org.exist.dom.memtree.DocumentImpl ownerDoc = node.getNodeType() == Node.DOCUMENT_NODE ? (org.exist.dom.memtree.DocumentImpl) node : node.getOwnerDocument();
        reader = new InMemoryXMLStreamReader(ownerDoc, ownerDoc);
    } else {
        final NodeProxy proxy = (NodeProxy) nv;
        reader = getBroker().newXMLStreamReader(new NodeProxy(proxy.getOwnerDocument(), NodeId.DOCUMENT_NODE, proxy.getOwnerDocument().getFirstChildAddress()), false);
    }
    return reader;
}
Also used : ExtendedXMLStreamReader(org.exist.stax.ExtendedXMLStreamReader) NodeImpl(org.exist.dom.memtree.NodeImpl) InMemoryXMLStreamReader(org.exist.dom.memtree.InMemoryXMLStreamReader)

Example 2 with ExtendedXMLStreamReader

use of org.exist.stax.ExtendedXMLStreamReader 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)

Aggregations

ExtendedXMLStreamReader (org.exist.stax.ExtendedXMLStreamReader)2 IOException (java.io.IOException)1 ArrayDeque (java.util.ArrayDeque)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 QName (org.exist.dom.QName)1 InMemoryXMLStreamReader (org.exist.dom.memtree.InMemoryXMLStreamReader)1 NodeImpl (org.exist.dom.memtree.NodeImpl)1 ElementImpl (org.exist.dom.persistent.ElementImpl)1 NodeId (org.exist.numbering.NodeId)1 NodePath (org.exist.storage.NodePath)1