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;
}
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();
}
}
Aggregations