String currentDateTime = toXSDDateTime(new Date());
String currentDateTime = DateFormatter.toXSDDateTime(new Date());
   public void doDelete(DBBroker broker,IncomingMessage request,OutgoingMessage response)      throws BadRequestException,PermissionDeniedException,NotFoundException,EXistException   {      XmldbURI pathUri = XmldbURI.create(request.getPath());      XmldbURI srcUri = null;            Collection collection = broker.getCollection(pathUri);      if (collection == null) {         throw new BadRequestException("Collection "+request.getPath()+" does not exist.");      }      String id = request.getParameter("id");      if (id==null) {         // delete collection         TransactionManager transact = broker.getBrokerPool().getTransactionManager();         Txn transaction = transact.beginTransaction();         broker.removeCollection(transaction, collection);         transact.commit(transaction);         response.setStatusCode(204);         return;      }            LOG.info("Deleting entry "+id+" in collection "+request.getPath());      DocumentImpl feedDoc = null;      TransactionManager transact = broker.getBrokerPool().getTransactionManager();      Txn transaction = transact.beginTransaction();      String currentDateTime = toXSDDateTime(new Date());      try {                  // Get the feed         //LOG.info("Acquiring lock on feed document...");         feedDoc = collection.getDocument(broker,FEED_DOCUMENT_URI);         feedDoc.getUpdateLock().acquire(Lock.WRITE_LOCK);         // Find the entry         FindEntry finder = new FindEntry(id);         DOM.findChildren(feedDoc.getDocumentElement(),Atom.NAMESPACE_STRING,"entry",finder);         Element entry = finder.getEntry();                  if (entry==null) {            transact.abort(transaction);            throw new BadRequestException("Entry with id "+id+" cannot be found.");         }                  // Remove the media resource if there is one         Element content = DOM.findChild(entry,Atom.NAMESPACE_STRING,"content");         if (content!=null) {            String src = content.getAttribute("src");            LOG.debug("Found content element, checking for resource "+src);            if (src!=null && src.indexOf('/')<0) {               srcUri =XmldbURI.create(src);               DocumentImpl resource = collection.getDocument(broker,srcUri);               if (resource!=null) {                  LOG.debug("Deleting resource "+src+" from "+request.getPath());                  if (resource.getResourceType() == DocumentImpl.BINARY_FILE) {                     collection.removeBinaryResource(transaction,broker,srcUri);                  } else {                     collection.removeXMLResource(transaction,broker,srcUri);                  }               }            }         }                  // Remove the entry         ElementImpl feedRoot = (ElementImpl)feedDoc.getDocumentElement();         feedRoot.removeChild(transaction,entry);         // Update the feed time         DOMDB.replaceTextElement(transaction,feedRoot,Atom.NAMESPACE_STRING,"updated",currentDateTime,true);         // Store the change on the feed         LOG.debug("Storing change...");         broker.storeXMLResource(transaction, feedDoc);         transact.commit(transaction);         LOG.debug("Done!");         response.setStatusCode(204);      } catch (TriggerException ex) {         transact.abort(transaction);         throw new EXistException("Cannot delete media resource "+srcUri,ex);      } catch (LockException ex) {         transact.abort(transaction);         throw new EXistException("Cannot acquire write lock.",ex);      } finally {         if (feedDoc!=null) {            feedDoc.getUpdateLock().release(Lock.WRITE_LOCK);         }      }         }