public long process() throws PermissionDeniedException, EXistException, XPathException { NodeImpl[] qr = select(docs); if(qr == null) return 0; IndexListener listener = new IndexListener(qr); NodeImpl node; Node parent; DocumentImpl doc = null; Collection collection = null, prevCollection = null; for(int i = 0; i < qr.length; i++) { node = qr[i]; doc = (DocumentImpl) node.getOwnerDocument(); if (!doc.getPermissions().validate(broker.getUser(), Permission.UPDATE)) throw new PermissionDeniedException("permission to remove document denied"); collection = doc.getCollection(); if(prevCollection != null && collection != prevCollection) doc.getBroker().saveCollection(prevCollection); doc.setIndexListener(listener); parent = node.getParentNode(); if (parent.getNodeType() != Node.ELEMENT_NODE) { throw new EXistException("you cannot remove the document element. Use update " + "instead"); } else parent.removeChild(node); doc.clearIndexListener(); doc.setLastModified(System.currentTimeMillis()); prevCollection = collection; } if(doc != null) doc.getBroker().saveCollection(collection); return qr.length; }
public long process() throws PermissionDeniedException, LockException, EXistException, XPathException { try { NodeImpl[] ql = selectAndLock(); IndexListener listener = new IndexListener(ql); NodeImpl node; Node parent; DocumentImpl doc = null; Collection collection = null, prevCollection = null; for (int i = 0; i < ql.length; i++) { node = ql[i]; doc = (DocumentImpl) node.getOwnerDocument(); if (!doc.getPermissions().validate(broker.getUser(), Permission.UPDATE)) throw new PermissionDeniedException( "permission to remove document denied"); collection = doc.getCollection(); if (prevCollection != null && collection != prevCollection) doc.getBroker().saveCollection(prevCollection); doc.setIndexListener(listener); parent = node.getParentNode(); if (parent.getNodeType() != Node.ELEMENT_NODE) { throw new EXistException( "you cannot remove the document element. Use update " + "instead"); } else parent.removeChild(node); doc.clearIndexListener(); doc.setLastModified(System.currentTimeMillis()); prevCollection = collection; } if (doc != null) doc.getBroker().saveCollection(collection); return ql.length; } finally { unlockDocuments(); } }
	public long process()		throws PermissionDeniedException, EXistException, XPathException {		NodeImpl[] qr = select(docs);		if(qr == null)			return 0;		IndexListener listener = new IndexListener(qr);		NodeImpl node;		Node parent;		DocumentImpl doc = null;		Collection collection = null, prevCollection = null;		for(int i = 0; i < qr.length; i++) {			node = qr[i];			doc = (DocumentImpl) node.getOwnerDocument();			if (!doc.getPermissions().validate(broker.getUser(), Permission.UPDATE))				throw new PermissionDeniedException("permission to remove document denied");			collection = doc.getCollection();			if(prevCollection != null && collection != prevCollection)				doc.getBroker().saveCollection(prevCollection);			doc.setIndexListener(listener);			parent = node.getParentNode();			if (parent.getNodeType() != Node.ELEMENT_NODE) {				throw new EXistException("you cannot remove the document element. Use update " +					"instead");			} else				parent.removeChild(node);			doc.clearIndexListener();			doc.setLastModified(System.currentTimeMillis());			prevCollection = collection;		}		if(doc != null)			doc.getBroker().saveCollection(collection);		return qr.length;	}