/* (non-Javadoc)
* @see com.adito.vfs.VFSResource#delete()
*/
public void delete() throws DAVMultiStatus, IOException {
if (this.isNull())
throw new DAVException(404, "Not found", this);
if (getMount().isReadOnly()) {
throw new DAVException(DAVStatus.SC_FORBIDDEN, "You cannot delete this file because the the mount is readonly!");
}
if (this.isResource()) {
try {
if (!getFile().delete()) {
throw new DAVException(403, "Can't delete resource '" + getRelativePath() + "'", this);
} else {
this.getMount().getStore().getRepository().notify(this, DAVListener.RESOURCE_REMOVED);
}
} catch (IOException e) {
throw new DAVException(403, "Can't delete resource. " + VfsUtils.maskSensitiveArguments(e.getMessage()), this);
}
} else if (this.isMount()) {
throw new DAVException(403, "Can't delete resource '" + getRelativePath()
+ "' as it is the root for the mount point "
+ this.getMount().getMountString(), this);
} else if (this.isCollection()) {
DAVMultiStatus multistatus = new DAVMultiStatus();
Iterator children = this.getChildren();
while (children.hasNext())
try {
((VFSResource) children.next()).delete();
} catch (DAVException exception) {
multistatus.merge(exception);
}
if (multistatus.size() > 0)
throw multistatus;
try {
if (!getFile().delete()) {
throw new DAVException(403, "Can't delete collection", this);
} else {
this.getMount().getStore().getRepository().notify(this, DAVListener.COLLECTION_REMOVED);
}
} catch (IOException e) {
log.error("Failed to delete resource.", e);
throw new DAVException(403, "Can't delete collection " + getRelativePath() + ". " + e.getMessage(), this);
}
}
}