use of org.nuxeo.ecm.platform.filemanager.api.FileManager 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;
}
use of org.nuxeo.ecm.platform.filemanager.api.FileManager in project nuxeo-drive-server by nuxeo.
the class NuxeoDriveCreateTestDocuments method run.
@OperationMethod
public Blob run(DocumentModel parent) throws Exception {
NuxeoDriveIntegrationTestsHelper.checkOperationAllowed();
FileManager fileManager = Framework.getService(FileManager.class);
for (int i = 0; i < number; i++) {
String name = String.format(namePattern, i);
Blob content = new StringBlob(String.format(contentPattern, i));
content.setFilename(name);
fileManager.createDocumentFromBlob(session, content, parent.getPathAsString(), false, name);
if (delay > 0) {
Thread.sleep(delay);
}
}
return new StringBlob(number.toString(), "text/plain");
}
use of org.nuxeo.ecm.platform.filemanager.api.FileManager in project nuxeo-filesystem-connectors by nuxeo.
the class SimpleBackend method createFile.
@Override
public DocumentModel createFile(String parentPath, String name, Blob content) {
DocumentModel parent = resolveLocation(parentPath);
if (!parent.isFolder()) {
throw new NuxeoException("Can not create a child in a non folderish node");
}
try {
cleanTrashPath(parent, name);
DocumentModel file;
if (Framework.isBooleanPropertyTrue(ALWAYS_CREATE_FILE_PROP)) {
// compat for older versions, always create a File
file = getSession().createDocumentModel(parent.getPathAsString(), name, "File");
file.setPropertyValue("dc:title", name);
if (content != null) {
BlobHolder bh = file.getAdapter(BlobHolder.class);
if (bh != null) {
bh.setBlob(content);
}
}
file = getSession().createDocument(file);
} else {
// use the FileManager to create the file
FileManager fileManager = Framework.getService(FileManager.class);
file = fileManager.createDocumentFromBlob(getSession(), content, parent.getPathAsString(), false, name);
}
getPathCache().put(parseLocation(parentPath) + "/" + name, file);
return file;
} catch (IOException e) {
throw new NuxeoException("Error child creating new folder", e);
}
}
Aggregations