broker = pool.get(session.getUser());
final XmldbURI collectionUri = path.removeLastSegment();
final XmldbURI docUri = path.lastSegment();
if (collectionUri==null || docUri==null) {
transact.abort(txn);
throw new EXistException("Illegal document path");
}
final Collection collection = broker.getCollection(collectionUri);
if (collection == null) {
transact.abort(txn);
throw new EXistException(
"Collection " + collectionUri + " not found");
}
final DocumentImpl doc = collection.getDocument(broker, docUri);
if(doc == null)
{throw new EXistException("Document " + docUri + " not found");}
if(doc.getResourceType() == DocumentImpl.BINARY_FILE)
{collection.removeBinaryResource(txn, broker, doc);}
else
{collection.removeXMLResource(txn, broker, docUri);}