//start a transaction
final Txn transaction = getTransaction();
try {
final NotificationService notifier = context.getBroker().getBrokerPool().getNotificationService();
final StoredNode ql[] = selectAndLock(transaction, inSeq);
final IndexListener listener = new IndexListener(ql);
TextImpl text;
AttrImpl attribute;
ElementImpl parent;
for (int i = 0; i < ql.length; i++) {
final StoredNode node = ql[i];
final DocumentImpl doc = (DocumentImpl)node.getOwnerDocument();
if (!doc.getPermissions().validate(context.getUser(),
Permission.WRITE)){
throw new XPathException(this, "User '" + context.getSubject().getName() + "' does not have permission to write to the document '" + doc.getDocumentURI() + "'!");
}
doc.getMetadata().setIndexListener(listener);
//update the document
switch (node.getNodeType())
{
case Node.ELEMENT_NODE:
final NodeListImpl content = new NodeListImpl();
for (final SequenceIterator j = contentSeq.iterate(); j.hasNext(); ) {
final Item next = j.nextItem();
if (Type.subTypeOf(next.getType(), Type.NODE))
{content.add(((NodeValue)next).getNode());}
else {
text = new TextImpl(next.getStringValue());
content.add(text);
}
}
((ElementImpl) node).update(transaction, content);
break;
case Node.TEXT_NODE:
parent = (ElementImpl) node.getParentNode();
text = new TextImpl(contentSeq.getStringValue());
text.setOwnerDocument(doc);
parent.updateChild(transaction, node, text);
break;
case Node.ATTRIBUTE_NODE:
parent = (ElementImpl) node.getParentNode();
if (parent == null) {
LOG.warn("parent node not found for "
+ node.getNodeId());
break;
}
final AttrImpl attr = (AttrImpl) node;
attribute = new AttrImpl(attr.getQName(), contentSeq.getStringValue(), context.getBroker().getBrokerPool().getSymbols());
attribute.setOwnerDocument(doc);