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;
}
}
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;
}
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);
}
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");
}
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");
}
}
Aggregations