try {
broker = factory.getBrokerPool().get(user);
collection = broker.openCollection(docUri.removeLastSegment(), Lock.WRITE_LOCK);
if (collection == null) {
transact.abort(transaction);
throw new EXistException("Collection " + docUri.removeLastSegment() + " not found");
}
// keep the write lock in the transaction
transaction.registerLock(collection.getLock(), Lock.WRITE_LOCK);
final DocumentImpl doc = collection.getDocument(broker, docUri.lastSegment());
if (doc == null) {
transact.abort(transaction);
throw new EXistException("Document " + docUri + " not found");
}
if(doc.getResourceType() == DocumentImpl.BINARY_FILE)
{collection.removeBinaryResource(transaction, broker, doc);}
else