Search in sources :

Example 36 with Resource

use of io.milton.resource.Resource in project lobcder by skoulouzis.

the class ResourceList method getRandom.

public Resource getRandom() {
    int l = this.size();
    if (l == 0) {
        return null;
    }
    List<Resource> list = new ArrayList<Resource>();
    for (Resource res : this) {
        list.add(res);
    }
    if (list.isEmpty()) {
        return null;
    }
    Random rnd = new Random();
    int pos = rnd.nextInt(list.size());
    return list.get(pos);
}
Also used : CollectionResource(io.milton.resource.CollectionResource) Resource(io.milton.resource.Resource)

Example 37 with Resource

use of io.milton.resource.Resource in project lobcder by skoulouzis.

the class FckFileManagerResource method find.

private Resource find(CollectionResource wrappedResource, Path p) throws NotAuthorizedException, BadRequestException {
    Resource r = wrappedResource;
    for (String s : p.getParts()) {
        if (r instanceof CollectionResource) {
            CollectionResource col = (CollectionResource) r;
            r = col.child(s);
            if (r == null) {
                log.trace("not found: " + s + " in path: " + p);
                return null;
            }
        } else {
            log.trace("not a collection: " + r.getName() + " in path: " + p);
            return null;
        }
    }
    return r;
}
Also used : CollectionResource(io.milton.resource.CollectionResource) PutableResource(io.milton.resource.PutableResource) GetableResource(io.milton.resource.GetableResource) MakeCollectionableResource(io.milton.resource.MakeCollectionableResource) CollectionResource(io.milton.resource.CollectionResource) Resource(io.milton.resource.Resource)

Aggregations

Resource (io.milton.resource.Resource)37 CollectionResource (io.milton.resource.CollectionResource)23 BadRequestException (io.milton.http.exceptions.BadRequestException)11 NotAuthorizedException (io.milton.http.exceptions.NotAuthorizedException)10 Path (io.milton.common.Path)9 MakeCollectionableResource (io.milton.resource.MakeCollectionableResource)8 PutableResource (io.milton.resource.PutableResource)8 GetableResource (io.milton.resource.GetableResource)7 ConflictException (io.milton.http.exceptions.ConflictException)6 ReplaceableResource (io.milton.resource.ReplaceableResource)6 DeletableResource (io.milton.resource.DeletableResource)5 PostableResource (io.milton.resource.PostableResource)4 IOException (java.io.IOException)4 PutEvent (io.milton.event.PutEvent)3 LockableResource (io.milton.resource.LockableResource)3 PropFindableResource (io.milton.resource.PropFindableResource)3 NewFolderEvent (io.milton.event.NewFolderEvent)2 CopyableResource (io.milton.resource.CopyableResource)2 LockingCollectionResource (io.milton.resource.LockingCollectionResource)2 MoveableResource (io.milton.resource.MoveableResource)2