Search in sources :

Example 11 with INodeIterator

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

the class NativeBroker method dropIndex.

private void dropIndex(final Txn transaction, @EnsureLocked(mode = LockMode.WRITE_LOCK) final DocumentImpl document) {
    final StreamListener listener = getIndexController().getStreamListener(document, ReindexMode.REMOVE_ALL_NODES);
    listener.startIndexDocument(transaction);
    final NodeList nodes = document.getChildNodes();
    for (int i = 0; i < nodes.getLength(); i++) {
        final IStoredNode<?> node = (IStoredNode<?>) nodes.item(i);
        try (final INodeIterator iterator = getNodeIterator(node)) {
            iterator.next();
            scanNodes(transaction, iterator, node, new NodePath2(), IndexMode.REMOVE, listener);
        } catch (final IOException ioe) {
            LOG.error("Unable to close node iterator", ioe);
        }
    }
    listener.endIndexDocument(transaction);
    notifyDropIndex(document);
    getIndexController().flush();
}
Also used : INodeIterator(org.exist.storage.dom.INodeIterator) NodeList(org.w3c.dom.NodeList) StreamListener(org.exist.indexing.StreamListener)

Example 12 with INodeIterator

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

the class ElementImpl method getAttributes.

@Override
public NamedNodeMap getAttributes() {
    final org.exist.dom.NamedNodeMapImpl map = new NamedNodeMapImpl(ownerDocument, true);
    if (hasAttributes()) {
        try (final DBBroker broker = ownerDocument.getBrokerPool().getBroker();
            final INodeIterator iterator = broker.getNodeIterator(this)) {
            // skip self
            iterator.next();
            final int childCount = getChildCount();
            for (int i = 0; i < childCount; i++) {
                final IStoredNode next = iterator.next();
                if (next.getNodeType() != Node.ATTRIBUTE_NODE) {
                    break;
                }
                map.setNamedItem(next);
            }
        } catch (final EXistException | IOException e) {
            LOG.warn("Exception while retrieving attributes: {}", e.getMessage());
        }
    }
    if (declaresNamespacePrefixes()) {
        for (final Map.Entry<String, String> entry : namespaceMappings.entrySet()) {
            final String prefix = entry.getKey();
            final String ns = entry.getValue();
            final QName attrName = new QName(prefix, Namespaces.XMLNS_NS, XMLConstants.XMLNS_ATTRIBUTE);
            final AttrImpl attr = new AttrImpl(attrName, ns, null);
            attr.setOwnerDocument(ownerDocument);
            map.setNamedItem(attr);
        }
    }
    return map;
}
Also used : org.w3c.dom(org.w3c.dom) NamedNodeMapImpl(org.exist.dom.NamedNodeMapImpl) QName(org.exist.dom.QName) EXistException(org.exist.EXistException) IOException(java.io.IOException) NamedNodeMapImpl(org.exist.dom.NamedNodeMapImpl) INodeIterator(org.exist.storage.dom.INodeIterator)

Aggregations

INodeIterator (org.exist.storage.dom.INodeIterator)12 NodeList (org.w3c.dom.NodeList)7 IOException (java.io.IOException)6 StreamListener (org.exist.indexing.StreamListener)4 PooledObject (org.apache.commons.pool2.PooledObject)2 DefaultPooledObject (org.apache.commons.pool2.impl.DefaultPooledObject)2 EXistException (org.exist.EXistException)2 DOMTransaction (org.exist.storage.dom.DOMTransaction)2 NamedNodeMapImpl (org.exist.dom.NamedNodeMapImpl)1 QName (org.exist.dom.QName)1 DocumentTypeImpl (org.exist.dom.persistent.DocumentTypeImpl)1 IStoredNode (org.exist.dom.persistent.IStoredNode)1 NodeProxy (org.exist.dom.persistent.NodeProxy)1 NodePath (org.exist.storage.NodePath)1 TerminatedException (org.exist.xquery.TerminatedException)1 org.w3c.dom (org.w3c.dom)1