use of org.nuxeo.ecm.core.api.NuxeoException 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