Search in sources :

Example 11 with CollectionResource

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

the class WebDavResourceTypeHelper method getResourceTypes.

@Override
public List<QName> getResourceTypes(Resource r) {
    if (r instanceof CollectionResource) {
        ArrayList<QName> list = new ArrayList<QName>();
        QName qn = new QName(WebDavProtocol.NS_DAV.getName(), "collection");
        list.add(qn);
        return list;
    } else {
        return null;
    }
}
Also used : CollectionResource(io.milton.resource.CollectionResource) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList)

Example 12 with CollectionResource

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

the class AnnotationResourceFactory method findFromRoot.

public Resource findFromRoot(AnnoCollectionResource rootFolder, Path p) throws NotAuthorizedException, BadRequestException {
    CollectionResource col = rootFolder;
    Resource r = null;
    for (String s : p.getParts()) {
        if (col == null) {
            if (log.isTraceEnabled()) {
                log.trace("findFromRoot: collection is null, can't look for child: " + s);
            }
            return null;
        }
        r = col.child(s);
        if (r == null) {
            if (log.isTraceEnabled()) {
                log.trace("findFromRoot: Couldnt find child: " + s + " of parent: " + col.getName() + " with type: " + col.getClass());
            }
            return null;
        } else {
            if (log.isTraceEnabled()) {
                if (r instanceof AnnoResource) {
                    AnnoResource ar = (AnnoResource) r;
                    log.trace("findFromRoot: found a child: " + r.getName() + " with source type: " + ar.getSource().getClass());
                } else {
                    log.trace("findFromRoot: found a child: " + r.getName() + " of type: " + r.getClass());
                }
            }
        }
        if (r instanceof CollectionResource) {
            col = (CollectionResource) r;
        } else {
            col = null;
        }
    }
    return r;
}
Also used : CollectionResource(io.milton.resource.CollectionResource) Resource(io.milton.resource.Resource) PropFindableResource(io.milton.resource.PropFindableResource) CollectionResource(io.milton.resource.CollectionResource)

Example 13 with CollectionResource

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

the class MiltonFtpAdapter method createFileSystemView.

@Override
public FileSystemView createFileSystemView(User user) throws FtpException {
    MiltonUser mu = (MiltonUser) user;
    Resource root;
    try {
        root = resourceFactory.getResource(mu.domain, "/");
    } catch (NotAuthorizedException ex) {
        throw new FtpException(ex);
    } catch (BadRequestException ex) {
        throw new FtpException(ex);
    }
    return new MiltonFsView(Path.root, (CollectionResource) root, resourceFactory, (MiltonUser) user);
}
Also used : CollectionResource(io.milton.resource.CollectionResource) Resource(io.milton.resource.Resource) BadRequestException(io.milton.http.exceptions.BadRequestException) FtpException(org.apache.ftpserver.ftplet.FtpException) NotAuthorizedException(io.milton.http.exceptions.NotAuthorizedException)

Example 14 with CollectionResource

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

the class MoveHandler method processExistingResource.

@Override
public void processExistingResource(HttpManager manager, Request request, Response response, Resource resource) throws NotAuthorizedException, BadRequestException, ConflictException {
    MoveableResource r = (MoveableResource) resource;
    Dest dest = Utils.getDecodedDestination(request.getDestinationHeader());
    Resource rDest = manager.getResourceFactory().getResource(dest.host, dest.url);
    log.debug("process: moving from: " + r.getName() + " -> " + dest.url + " with name: " + dest.name);
    if (rDest == null) {
        log.debug("process: destination parent does not exist: " + dest);
        responseHandler.respondConflict(resource, response, request, "Destination parent does not exist: " + dest);
    } else if (!(rDest instanceof CollectionResource)) {
        log.debug("process: destination exists but is not a collection");
        responseHandler.respondConflict(resource, response, request, "Destination exists but is not a collection: " + dest);
    } else {
        boolean wasDeleted = false;
        CollectionResource colDest = (CollectionResource) rDest;
        // check if the dest exists
        Resource rExisting = colDest.child(dest.name);
        if (rExisting != null) {
            // check for overwrite header
            if (!canOverwrite(request)) {
                log.info("destination resource exists, and overwrite header is not set. dest name: " + dest.name + " dest folder: " + colDest.getName());
                responseHandler.respondPreconditionFailed(request, response, rExisting);
                return;
            } else {
                if (deleteExistingBeforeMove) {
                    if (rExisting instanceof DeletableResource) {
                        log.debug("deleting existing resource");
                        DeletableResource drExisting = (DeletableResource) rExisting;
                        if (deleteHelper.isLockedOut(request, drExisting)) {
                            log.debug("destination resource exists but is locked");
                            responseHandler.respondLocked(request, response, drExisting);
                            return;
                        }
                        log.debug("deleting pre-existing destination resource");
                        deleteHelper.delete(drExisting, manager.getEventManager());
                        wasDeleted = true;
                    } else {
                        log.warn("destination exists, and overwrite header is set, but destination is not a DeletableResource");
                        responseHandler.respondConflict(resource, response, request, "A resource exists at the destination, and it cannot be deleted");
                        return;
                    }
                }
            }
        }
        log.debug("process: moving resource to: " + rDest.getName());
        try {
            if (!handlerHelper.checkAuthorisation(manager, colDest, request, request.getMethod(), request.getAuthorization())) {
                responseHandler.respondUnauthorised(colDest, response, request);
                return;
            }
            manager.getEventManager().fireEvent(new MoveEvent(resource, colDest, dest.name));
            r.moveTo(colDest, dest.name);
            // See http://www.ettrema.com:8080/browse/MIL-87
            if (wasDeleted) {
                responseHandler.respondNoContent(resource, response, request);
            } else {
                responseHandler.respondCreated(resource, response, request);
            }
        } catch (ConflictException ex) {
            log.warn("conflict", ex);
            responseHandler.respondConflict(resource, response, request, dest.toString());
        }
    }
    log.debug("process: finished");
}
Also used : CollectionResource(io.milton.resource.CollectionResource) MoveableResource(io.milton.resource.MoveableResource) ConflictException(io.milton.http.exceptions.ConflictException) DeletableResource(io.milton.resource.DeletableResource) Resource(io.milton.resource.Resource) CollectionResource(io.milton.resource.CollectionResource) MoveableResource(io.milton.resource.MoveableResource) DeletableResource(io.milton.resource.DeletableResource) MoveEvent(io.milton.event.MoveEvent)

Example 15 with CollectionResource

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

the class MoveJsonResource method processForm.

@Override
public String processForm(Map<String, String> parameters, Map<String, FileItem> files) throws BadRequestException, NotAuthorizedException {
    String dest = parameters.get("destination");
    if (dest == null) {
        throw new BadRequestException(this, "The destination parameter is null");
    } else if (dest.trim().length() == 0) {
        throw new BadRequestException(this, "The destination parameter is empty");
    }
    Path pDest = Path.path(dest);
    if (pDest == null) {
        throw new BadRequestException(this, "Couldnt parse the destination header, returned null from: " + dest);
    }
    String parentPath = "/";
    if (pDest.getParent() != null) {
        parentPath = pDest.getParent().toString();
    }
    Resource rDestParent = resourceFactory.getResource(host, parentPath);
    if (rDestParent == null)
        throw new BadRequestException(wrapped, "The destination parent does not exist");
    if (rDestParent instanceof CollectionResource) {
        CollectionResource colDestParent = (CollectionResource) rDestParent;
        if (colDestParent.child(pDest.getName()) == null) {
            try {
                wrapped.moveTo(colDestParent, pDest.getName());
            } catch (ConflictException ex) {
                log.warn("Exception copying to: " + pDest.getName(), ex);
                throw new BadRequestException(rDestParent, "conflict: " + ex.getMessage());
            }
            return null;
        } else {
            log.warn("destination already exists: " + pDest.getName() + " in folder: " + colDestParent.getName());
            throw new BadRequestException(rDestParent, "File already exists");
        }
    } else {
        throw new BadRequestException(wrapped, "The destination parent is not a collection resource");
    }
}
Also used : Path(io.milton.common.Path) CollectionResource(io.milton.resource.CollectionResource) ConflictException(io.milton.http.exceptions.ConflictException) CollectionResource(io.milton.resource.CollectionResource) Resource(io.milton.resource.Resource) PostableResource(io.milton.resource.PostableResource) MoveableResource(io.milton.resource.MoveableResource) BadRequestException(io.milton.http.exceptions.BadRequestException)

Aggregations

CollectionResource (io.milton.resource.CollectionResource)19 Resource (io.milton.resource.Resource)16 MakeCollectionableResource (io.milton.resource.MakeCollectionableResource)7 Path (io.milton.common.Path)6 BadRequestException (io.milton.http.exceptions.BadRequestException)5 NotAuthorizedException (io.milton.http.exceptions.NotAuthorizedException)5 GetableResource (io.milton.resource.GetableResource)5 PutableResource (io.milton.resource.PutableResource)5 ConflictException (io.milton.http.exceptions.ConflictException)4 DeletableResource (io.milton.resource.DeletableResource)3 ReplaceableResource (io.milton.resource.ReplaceableResource)3 QName (javax.xml.namespace.QName)3 NewFolderEvent (io.milton.event.NewFolderEvent)2 CopyableResource (io.milton.resource.CopyableResource)2 MoveableResource (io.milton.resource.MoveableResource)2 PostableResource (io.milton.resource.PostableResource)2 PropFindableResource (io.milton.resource.PropFindableResource)2 ArrayList (java.util.ArrayList)2 FtpException (org.apache.ftpserver.ftplet.FtpException)2 MoveEvent (io.milton.event.MoveEvent)1