final NodeList children = content;
if (children.getLength() == 0) {return 0;}
int modificationCount = 0;
try {
final StoredNode[] ql = selectAndLock(transaction);
NodeImpl parent;
final IndexListener listener = new IndexListener(ql);
final NotificationService notifier = broker.getBrokerPool().getNotificationService();
final String newName = children.item(0).getNodeValue();
for (int i = 0; i < ql.length; i++) {
final StoredNode node = ql[i];
final DocumentImpl doc = (DocumentImpl)node.getOwnerDocument();
if (!doc.getPermissions().validate(broker.getSubject(), Permission.WRITE)) {
throw new PermissionDeniedException("User '" + broker.getSubject().getName() + "' does not have permission to write to the document '" + doc.getDocumentURI() + "'!");
}
doc.getMetadata().setIndexListener(listener);
parent = (NodeImpl) node.getParentNode();
switch (node.getNodeType()) {
case Node.ELEMENT_NODE:
final ElementImpl newElem = new ElementImpl((ElementImpl) node);
newElem.setNodeName(new QName(newName, "", null));
parent.updateChild(transaction, node, newElem);
modificationCount++;
break;
case Node.ATTRIBUTE_NODE:
final AttrImpl newAttr = new AttrImpl((AttrImpl) node);
newAttr.setNodeName(new QName(newName, "", null));
parent.updateChild(transaction, node, newAttr);
modificationCount++;
break;
default:
throw new EXistException("unsupported node-type");
}