Search in sources :

Example 1 with ElementImpl

use of org.exist.dom.persistent.ElementImpl in project exist by eXist-db.

the class Indexer method endCDATA.

@Override
public void endCDATA() {
    if (!stack.isEmpty()) {
        final ElementImpl last = stack.peek();
        if (charBuf != null && charBuf.length() > 0) {
            final CDATASectionImpl cdata = new CDATASectionImpl(charBuf);
            cdata.setOwnerDocument(document);
            last.appendChildInternal(prevNode, cdata);
            if (!validate) {
                broker.storeNode(transaction, cdata, currentPath, indexSpec);
                if (indexListener != null) {
                    indexListener.characters(transaction, cdata, currentPath);
                }
            }
            setPrevious(cdata);
            if (!nodeContentStack.isEmpty()) {
                for (final XMLString next : nodeContentStack) {
                    next.append(charBuf);
                }
            }
            charBuf.reset();
        }
    }
    inCDATASection = false;
}
Also used : ElementImpl(org.exist.dom.persistent.ElementImpl) XMLString(org.exist.util.XMLString) CDATASectionImpl(org.exist.dom.persistent.CDATASectionImpl)

Example 2 with ElementImpl

use of org.exist.dom.persistent.ElementImpl in project exist by eXist-db.

the class Indexer method endElement.

@Override
public void endElement(final String namespace, final String name, final String qname) {
    final ElementImpl last = stack.peek();
    processText(last, ProcessTextParent.ELEMENT_END);
    stack.pop();
    XMLString elemContent = null;
    try {
        if (!validate && RangeIndexSpec.hasQNameOrValueIndex(last.getIndexType())) {
            elemContent = nodeContentStack.pop();
        }
        if (validate) {
            if (childCnt != null) {
                setChildCount(last);
            }
        } else {
            final String content = elemContent == null ? null : elemContent.toString();
            broker.endElement(last, currentPath, content);
            if (childCnt == null && last.getChildCount() > 0 || (childCnt != null && childCnt[last.getPosition()] != last.getChildCount())) {
                broker.updateNode(transaction, last, false);
            }
            if (indexListener != null) {
                indexListener.endElement(transaction, last, currentPath);
            }
        }
        currentPath.removeLastNode();
        setPrevious(last);
        level--;
    } finally {
        if (elemContent != null) {
            elemContent.reset();
        }
    }
}
Also used : ElementImpl(org.exist.dom.persistent.ElementImpl) XMLString(org.exist.util.XMLString) XMLString(org.exist.util.XMLString)

Example 3 with ElementImpl

use of org.exist.dom.persistent.ElementImpl in project exist by eXist-db.

the class DOMIndexer method store.

/**
 * Store the nodes.
 */
public void store() {
    // Create a wrapper element as root node
    final ElementImpl elem = new ElementImpl(ROOT_QNAME, broker.getBrokerPool().getSymbols());
    elem.setNodeId(broker.getBrokerPool().getNodeFactory().createInstance());
    elem.setOwnerDocument(targetDoc);
    elem.setChildCount(doc.getChildCount());
    elem.addNamespaceMapping(Namespaces.EXIST_NS_PREFIX, Namespaces.EXIST_NS);
    final NodePath path = new NodePath();
    path.addComponent(ROOT_QNAME);
    stack.push(elem);
    broker.storeNode(transaction, elem, path, indexSpec);
    targetDoc.appendChild((NodeHandle) elem);
    elem.setChildCount(0);
    // store the document nodes
    int top = (doc.size > 1) ? 1 : -1;
    while (top > 0) {
        store(top, path);
        top = doc.getNextSiblingFor(top);
    }
    // Close the wrapper element
    stack.pop();
    broker.endElement(elem, path, null);
    path.removeLastComponent();
}
Also used : ElementImpl(org.exist.dom.persistent.ElementImpl) NodePath(org.exist.storage.NodePath)

Example 4 with ElementImpl

use of org.exist.dom.persistent.ElementImpl in project exist by eXist-db.

the class DOMIndexer method endNode.

/**
 * DOCUMENT ME!
 *
 * @param nodeNr
 * @param currentPath DOCUMENT ME!
 */
private void endNode(final int nodeNr, final NodePath currentPath) {
    if (doc.nodeKind[nodeNr] == Node.ELEMENT_NODE) {
        final ElementImpl last = stack.pop();
        broker.endElement(last, currentPath, null);
        currentPath.removeLastComponent();
        setPrevious(last);
    }
}
Also used : ElementImpl(org.exist.dom.persistent.ElementImpl)

Example 5 with ElementImpl

use of org.exist.dom.persistent.ElementImpl in project exist by eXist-db.

the class FunResolveQName method eval.

public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException {
    if (context.getProfiler().isEnabled()) {
        context.getProfiler().start(this);
        context.getProfiler().message(this, Profiler.DEPENDENCIES, "DEPENDENCIES", Dependency.getDependenciesName(this.getDependencies()));
        if (contextSequence != null) {
            context.getProfiler().message(this, Profiler.START_SEQUENCES, "CONTEXT SEQUENCE", contextSequence);
        }
    }
    final Sequence qnameSeq = args[0];
    if (qnameSeq.isEmpty()) {
        return EmptySequence.EMPTY_SEQUENCE;
    } else {
        context.pushInScopeNamespaces();
        final String qnameString = args[0].getStringValue();
        if (QName.isQName(qnameString) == VALID.val) {
            try {
                String prefix = QName.extractPrefix(qnameString);
                if (prefix == null) {
                    prefix = "";
                }
                String uri = null;
                final NodeValue node = (NodeValue) args[1].itemAt(0);
                if (node.getImplementationType() == NodeValue.PERSISTENT_NODE) {
                    NodeProxy proxy = (NodeProxy) node;
                    final NodeSet ancestors = proxy.getAncestors(contextId, true);
                    for (NodeProxy ancestor : ancestors) {
                        proxy = ancestor;
                        final ElementImpl e = (ElementImpl) proxy.getNode();
                        uri = findNamespaceURI(e, prefix);
                        if (uri != null) {
                            break;
                        }
                    }
                } else {
                    NodeImpl next = (NodeImpl) node;
                    do {
                        uri = findNamespaceURI((org.exist.dom.memtree.ElementImpl) next, prefix);
                        if (uri != null) {
                            break;
                        } else {
                            next = (NodeImpl) next.getParentNode();
                        }
                    } while (next != null && next.getNodeType() == Node.ELEMENT_NODE);
                }
                if (uri == null && prefix != null && !prefix.isEmpty()) {
                    throw new XPathException(this, ErrorCodes.FONS0004, "No namespace found for prefix. No binding for prefix '" + prefix + "' was found.", args[0]);
                }
                final String localPart = QName.extractLocalName(qnameString);
                final QName qn = new QName(localPart, uri, prefix);
                final QNameValue result = new QNameValue(context, qn);
                if (context.getProfiler().isEnabled()) {
                    context.getProfiler().end(this, "", result);
                }
                context.popInScopeNamespaces();
                return result;
            } catch (final QName.IllegalQNameException e) {
                throw new XPathException(this, ErrorCodes.FOCA0002, "Invalid lexical value. '" + qnameString + "' is not a QName.", args[0]);
            }
        } else {
            throw new XPathException(this, ErrorCodes.FOCA0002, "Invalid lexical value. '" + qnameString + "' is not a QName.", args[0]);
        }
    }
}
Also used : NodeSet(org.exist.dom.persistent.NodeSet) NodeValue(org.exist.xquery.value.NodeValue) NodeImpl(org.exist.dom.memtree.NodeImpl) XPathException(org.exist.xquery.XPathException) QName(org.exist.dom.QName) QNameValue(org.exist.xquery.value.QNameValue) EmptySequence(org.exist.xquery.value.EmptySequence) Sequence(org.exist.xquery.value.Sequence) NodeProxy(org.exist.dom.persistent.NodeProxy) ElementImpl(org.exist.dom.persistent.ElementImpl)

Aggregations

ElementImpl (org.exist.dom.persistent.ElementImpl)15 AttrImpl (org.exist.dom.persistent.AttrImpl)5 EXistException (org.exist.EXistException)4 DocumentImpl (org.exist.dom.persistent.DocumentImpl)4 StoredNode (org.exist.dom.persistent.StoredNode)4 TextImpl (org.exist.dom.persistent.TextImpl)4 NotificationService (org.exist.storage.NotificationService)4 QName (org.exist.dom.QName)3 PermissionDeniedException (org.exist.security.PermissionDeniedException)3 XMLString (org.exist.util.XMLString)3 XPathException (org.exist.xquery.XPathException)3 Sequence (org.exist.xquery.value.Sequence)3 TriggerException (org.exist.collections.triggers.TriggerException)2 CDATASectionImpl (org.exist.dom.persistent.CDATASectionImpl)2 CommentImpl (org.exist.dom.persistent.CommentImpl)2 NodePath (org.exist.storage.NodePath)2 Txn (org.exist.storage.txn.Txn)2 LockException (org.exist.util.LockException)2 Item (org.exist.xquery.value.Item)2 StringValue (org.exist.xquery.value.StringValue)2