use of org.nuxeo.common.utils.Path in project nuxeo-filesystem-connectors by nuxeo.
the class AbstractVirtualBackend method registerSimpleBackends.
protected void registerSimpleBackends(List<DocumentModel> docs) {
List<String> paths = new ArrayList<String>();
for (DocumentModel doc : docs) {
paths.add(doc.getPathAsString());
}
List<String> heads = new ArrayList<String>();
for (int idx = 0; idx < paths.size(); idx++) {
String path = paths.get(idx);
if (isHead(path, paths, idx)) {
heads.add(path);
}
}
for (String head : heads) {
String headName = new Path(head).lastSegment();
String name = headName;
int idx = 1;
while (backendMap.containsKey(name)) {
name = headName + "-" + idx;
idx = idx + 1;
}
Backend backend = realBackendFactory.createBackend(name, head, new Path(this.rootUrl).append(name).toString(), getSession());
registerBackend(backend);
}
}
use of org.nuxeo.common.utils.Path 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.common.utils.Path in project nuxeo-filesystem-connectors by nuxeo.
the class SimpleBackend method parseLocation.
@Override
public Path parseLocation(String location) {
Path finalLocation = new Path(rootPath);
Path rootUrlPath = new Path(rootUrl);
Path urlLocation = new Path(location);
Path cutLocation = urlLocation.removeFirstSegments(rootUrlPath.segmentCount());
finalLocation = finalLocation.append(cutLocation);
String fileName = finalLocation.lastSegment();
String parentPath = finalLocation.removeLastSegments(1).toString();
return new Path(parentPath).append(fileName);
}
use of org.nuxeo.common.utils.Path in project nuxeo-filesystem-connectors by nuxeo.
the class SimpleBackend method isRename.
@Override
public boolean isRename(String source, String destination) {
Path sourcePath = new Path(source);
Path destinationPath = new Path(destination);
return sourcePath.removeLastSegments(1).toString().equals(destinationPath.removeLastSegments(1).toString());
}
use of org.nuxeo.common.utils.Path in project nuxeo-filesystem-connectors by nuxeo.
the class SimpleBackend method updateDocument.
@Override
public DocumentModel updateDocument(DocumentModel doc, String name, Blob content) {
FileManager fileManager = Framework.getService(FileManager.class);
String parentPath = new Path(doc.getPathAsString()).removeLastSegments(1).toString();
try {
// this cannot be done before the update anymore
// doc.putContextData(SOURCE_EDIT_KEYWORD, "webdav");
// overwrite=true
doc = fileManager.createDocumentFromBlob(getSession(), content, parentPath, true, name);
} catch (IOException e) {
throw new NuxeoException("Error while updating document", e);
}
return doc;
}
Aggregations