Collection collection = null;
Collection collection = null, prevCollection = null;
	public long process()		throws PermissionDeniedException, EXistException {		ArrayList qr = select(docs);		NodeList children = content.getChildNodes();		if(qr == null || children.getLength() == 0)			return 0;		IndexListener listener = new IndexListener(qr);		NodeImpl node;		NodeImpl parent;		DocumentImpl doc = null;		Collection collection = null;		int len = children.getLength();		LOG.debug("found " + len + " nodes to insert");		for (Iterator i = qr.iterator(); i.hasNext();) {			node = (NodeImpl) i.next();			doc = (DocumentImpl) node.getOwnerDocument();			doc.setIndexListener(listener);			collection = doc.getCollection();			if (!collection				.getPermissions()				.validate(user, Permission.UPDATE))				throw new PermissionDeniedException(					"write access to collection denied; user="						+ user.getName());			if (!doc.getPermissions().validate(user, Permission.UPDATE))				throw new PermissionDeniedException("permission to remove document denied");			parent = (NodeImpl) node.getParentNode();			switch (mode) {				case INSERT_BEFORE :					parent.insertBefore(children, node);					break;				case INSERT_AFTER :					 ((NodeImpl) parent).insertAfter(children, node);					break;			}			doc.clearIndexListener();		}		return qr.size();	}