Creating new folders

Creating new folders (aka directories or collections) is done in Webdav by the MKCOL method, and is supported in milton with the MakeCollectionableResource interface which has a single method:

CollectionResource createCollection(String newName) throws NotAuthorizedException, ConflictException, BadRequestException;

So to be able to create Galaxies in our example project you would implement MakeCollectionableResource on RootUniverseResource like this:

public class RootUniverseResource extends AbstractResource implements MakeCollectionableResource {

    private static org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger(RootUniverseResource.class);
    private final UniverseDao universeDao;
    private ArrayList<Resource> children;
   
    public RootUniverseResource(UniverseDao universeDao) {
        this.universeDao = universeDao;
    }

    @Override
    public CollectionResource createCollection(String newName) throws NotAuthorizedException, ConflictException, BadRequestException {
        UniverseDao.Galaxy s = universeDao.addGalaxy(newName);
        GalaxyResource r = new GalaxyResource(this, s);
        getChildren();
        children.add(r);
        return r;
    }

Implement it in the same way on GalaxyResource and SolarSystemResource to allow all of our resources to be created.

Next Article:

Implementing Copy