use of org.nuxeo.ecm.webdav.backend.Backend in project nuxeo-filesystem-connectors by nuxeo.
the class ExistingResource method copyOrMove.
private Response copyOrMove(String method, @HeaderParam("Destination") String destination, @HeaderParam("Overwrite") String overwrite) {
if (backend.isLocked(doc.getRef()) && !backend.canUnlock(doc.getRef())) {
return Response.status(423).build();
}
destination = encode(destination.getBytes(), "ISO-8859-1");
try {
destination = new URI(destination).getPath();
} catch (URISyntaxException e) {
throw new NuxeoException(e);
}
Backend root = BackendHelper.getBackend("/", request);
Set<String> names = new HashSet<String>(root.getVirtualFolderNames());
Path destinationPath = new Path(destination);
String[] segments = destinationPath.segments();
int removeSegments = 0;
for (String segment : segments) {
if (names.contains(segment)) {
break;
} else {
removeSegments++;
}
}
destinationPath = destinationPath.removeFirstSegments(removeSegments);
String destPath = destinationPath.toString();
String davDestPath = destPath;
Backend destinationBackend = BackendHelper.getBackend(davDestPath, request);
destPath = destinationBackend.parseLocation(destPath).toString();
log.debug("to " + davDestPath);
// Remove dest if it exists and the Overwrite header is set to "T".
int status = 201;
if (destinationBackend.exists(davDestPath)) {
if ("F".equals(overwrite)) {
return Response.status(412).build();
}
destinationBackend.removeItem(davDestPath);
status = 204;
}
// Check if parent exists
String destParentPath = getParentPath(destPath);
PathRef destParentRef = new PathRef(destParentPath);
if (!destinationBackend.exists(getParentPath(davDestPath))) {
return Response.status(409).build();
}
if ("COPY".equals(method)) {
DocumentModel destDoc = backend.copyItem(doc, destParentRef);
backend.renameItem(destDoc, getNameFromPath(destPath));
} else if ("MOVE".equals(method)) {
if (backend.isRename(doc.getPathAsString(), destPath)) {
backend.renameItem(doc, getNameFromPath(destPath));
} else {
backend.moveItem(doc, destParentRef);
}
}
backend.saveChanges();
return Response.status(status).build();
}
use of org.nuxeo.ecm.webdav.backend.Backend in project nuxeo-filesystem-connectors by nuxeo.
the class RootResource method findResource.
@Path("{path:.+}")
public Object findResource(@PathParam("path") String path) {
try {
path = new String(path.getBytes(), "UTF-8");
} catch (UnsupportedEncodingException e) {
throw new NuxeoException(e);
}
Backend backend = BackendHelper.getBackend(path, request);
if (backend == null) {
throw new WebApplicationException(Response.Status.NOT_FOUND);
}
if (backend.isVirtual()) {
return new VirtualFolderResource(path, request, backend.getVirtualFolderNames());
}
DocumentModel doc = null;
try {
doc = backend.getDocument(path);
} catch (DocumentNotFoundException e) {
log.error("Error during resolving path: " + path, e);
throw new WebApplicationException(Response.Status.CONFLICT);
}
if (doc == null) {
return new UnknownResource(path, request, backend);
}
// Send 401 error if not authorised to read.
if (!backend.hasPermission(doc.getRef(), SecurityConstants.READ)) {
throw new WebApplicationException(Response.Status.UNAUTHORIZED);
}
if (doc.isFolder()) {
return new FolderResource(getDocumentPath(doc), doc, request, backend);
} else {
return new FileResource(getDocumentPath(doc), doc, request, backend);
}
}
Aggregations