Deleting files and folders

The webdav method for deleting resources is, surprise surprise, DELETE. And its supported in milton with the DeletableResource interface:

void delete() throws NotAuthorizedException, ConflictException, BadRequestException;

Implement DELETE for PlanetResource as follows:

public class PlanetResource extends AbstractResource implements GetableResource, ReplaceableResource, MoveableResource, CopyableResource, DeletableResource{

    private static org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger(PlanetResource.class);
    private final SolarSystemResource parent;
    private final Planet planet;

    public PlanetResource(SolarSystemResource parent, Planet planet) {
        this.parent = parent;
        this.planet = planet;

    public void delete() throws NotAuthorizedException, ConflictException, BadRequestException {

Pretty simple, huh?

Performance optimisation for deleting collections

Unfortunately its a little more complicated for collections. Its possible that items within a collection are locked, or that the current user might not have permission to delete an item within the collection, so milton recursively deletes each item explicitly so that locking and permissions are checked. This is very secure but can be a little bit slow. If you want to speed things up you can implement DeletableCollectionResource on your Collection resources:

boolean isLockedOutRecursive(Request request);

If your collection implements this milton will call the method to check that its ok to delete everything and then it will only call delete on the collection itself. This makes it your responsibility to check for permissions and locks on child resources.