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