public long process() throws PermissionDeniedException, EXistException, XPathException { NodeImpl[] qr = select(docs); NodeList children = content.getChildNodes(); if (qr == null) return 0; IndexListener listener = new IndexListener(qr); NodeImpl node; Node temp; TextImpl text; AttrImpl attribute; ElementImpl parent; DocumentImpl doc = null; Collection collection = null, prevCollection = null; int result = children.getLength(); for (int i = 0; i < qr.length; i++) { node = qr[i]; if(node == null) { LOG.warn("select " + selectStmt + " returned empty node"); continue; } doc = (DocumentImpl) node.getOwnerDocument(); doc.setIndexListener(listener); collection = doc.getCollection(); if (!doc.getPermissions().validate(broker.getUser(), Permission.UPDATE)) throw new PermissionDeniedException("permission to update document denied"); if(prevCollection != null && collection != prevCollection) doc.getBroker().saveCollection(prevCollection); switch (node.getNodeType()) { case Node.ELEMENT_NODE : if (result == 0) result = 1; ((ElementImpl) node).update(children); break; case Node.TEXT_NODE : parent = (ElementImpl)node.getParentNode(); if (children.getLength() != 0) { temp = children.item(0); text = new TextImpl(temp.getNodeValue()); } else { result = 1; text = new TextImpl(""); } text.setOwnerDocument(doc); parent.updateChild(node, text); break; case Node.ATTRIBUTE_NODE : parent = (ElementImpl)node.getParentNode(); if(parent == null) { LOG.warn("parent node not found for " + node.getGID()); break; } AttrImpl attr = (AttrImpl)node; if (children.getLength() != 0) { temp = children.item(0); attribute = new AttrImpl(attr.getQName(), temp.getNodeValue()); } else { result = 1; attribute = new AttrImpl(attr.getQName(), ""); } attribute.setOwnerDocument(doc); parent.updateChild(node, attribute); break; default : throw new EXistException("unsupported node-type"); } prevCollection = collection; doc.setLastModified(System.currentTimeMillis()); } if(doc != null) doc.getBroker().saveCollection(collection); return result; }
public long process() throws PermissionDeniedException, LockException, EXistException, XPathException { NodeList children = content.getChildNodes(); if (children.getLength() == 0) return 0; int modifications = children.getLength(); try { NodeImpl ql[] = selectAndLock(); IndexListener listener = new IndexListener(ql); NodeImpl node; Node temp; TextImpl text; AttrImpl attribute; ElementImpl parent; DocumentImpl doc = null; Collection collection = null, prevCollection = null; for (int i = 0; i < ql.length; i++) { node = ql[i]; if (node == null) { LOG.warn("select " + selectStmt + " returned empty node"); continue; } doc = (DocumentImpl) node.getOwnerDocument(); doc.setIndexListener(listener); collection = doc.getCollection(); if (!doc.getPermissions().validate(broker.getUser(), Permission.UPDATE)) throw new PermissionDeniedException( "permission to update document denied"); if (prevCollection != null && collection != prevCollection) doc.getBroker().saveCollection(prevCollection); switch (node.getNodeType()) { case Node.ELEMENT_NODE: if (modifications == 0) modifications = 1; ((ElementImpl) node).update(children); break; case Node.TEXT_NODE: parent = (ElementImpl) node.getParentNode(); if (children.getLength() != 0) { temp = children.item(0); text = new TextImpl(temp.getNodeValue()); } else { modifications = 1; text = new TextImpl(""); } text.setOwnerDocument(doc); parent.updateChild(node, text); break; case Node.ATTRIBUTE_NODE: parent = (ElementImpl) node.getParentNode(); if (parent == null) { LOG.warn("parent node not found for " + node.getGID()); break; } AttrImpl attr = (AttrImpl) node; if (children.getLength() != 0) { temp = children.item(0); attribute = new AttrImpl(attr.getQName(), temp .getNodeValue()); } else { modifications = 1; attribute = new AttrImpl(attr.getQName(), ""); } attribute.setOwnerDocument(doc); parent.updateChild(node, attribute); break; default: throw new EXistException("unsupported node-type"); } doc.setLastModified(System.currentTimeMillis()); prevCollection = collection; } if (doc != null) doc.getBroker().saveCollection(collection); } finally { unlockDocuments(); } return modifications; }
	public long process() throws PermissionDeniedException, EXistException, XPathException {		NodeImpl[] qr = select(docs);		NodeList children = content.getChildNodes();		if (qr == null)			return 0;		IndexListener listener = new IndexListener(qr);		NodeImpl node;		Node temp;		TextImpl text;		AttrImpl attribute;		ElementImpl parent;		DocumentImpl doc = null;		Collection collection = null, prevCollection = null;		int result = children.getLength();		for (int i = 0; i < qr.length; i++) {			node = qr[i];			if(node == null) {				LOG.warn("select " + selectStmt + " returned empty node");				continue;			}			doc = (DocumentImpl) node.getOwnerDocument();			doc.setIndexListener(listener);			collection = doc.getCollection();			if (!doc.getPermissions().validate(broker.getUser(), Permission.UPDATE))				throw new PermissionDeniedException("permission to update document denied");			if(prevCollection != null && collection != prevCollection)				doc.getBroker().saveCollection(prevCollection);			switch (node.getNodeType()) {				case Node.ELEMENT_NODE :					if (result == 0) result = 1;					((ElementImpl) node).update(children);					break;				case Node.TEXT_NODE :					parent = (ElementImpl)node.getParentNode();					if (children.getLength() != 0) {						temp = children.item(0);						text = new TextImpl(temp.getNodeValue());					} else {						result = 1;						text = new TextImpl("");					}					text.setOwnerDocument(doc);					parent.updateChild(node, text);					break;				case Node.ATTRIBUTE_NODE :					parent = (ElementImpl)node.getParentNode();					if(parent == null) {					    LOG.warn("parent node not found for " + node.getGID());					    break;					}					AttrImpl attr = (AttrImpl)node;					if (children.getLength() != 0) {						temp = children.item(0);						attribute = new AttrImpl(attr.getQName(), temp.getNodeValue());					} else {						result = 1;						attribute = new AttrImpl(attr.getQName(), "");					}					attribute.setOwnerDocument(doc);					parent.updateChild(node, attribute);					break;				default :					throw new EXistException("unsupported node-type");			}			prevCollection = collection;			doc.setLastModified(System.currentTimeMillis());		}		if(doc != null)			doc.getBroker().saveCollection(collection);		return result;	}