use of org.olat.core.util.vfs.VFSLeaf in project OpenOLAT by OpenOLAT.
the class PFManager method uploadFileToReturnBox.
/**
* Upload file to return box.
*
* @param uploadFile
* @param fileName
* @param courseEnv
* @param pfNode
* @param identity
*/
private void uploadFileToReturnBox(File uploadFile, String fileName, CourseEnvironment courseEnv, PFCourseNode pfNode, Identity identity) {
if (uploadFile.exists() && uploadFile.isFile() && uploadFile.length() > 0) {
VFSContainer dropbox = resolveOrCreateReturnFolder(courseEnv, pfNode, identity);
VFSLeaf uploadedFile = dropbox.createChildLeaf(fileName);
VFSManager.copyContent(uploadFile, uploadedFile);
}
}
use of org.olat.core.util.vfs.VFSLeaf in project OpenOLAT by OpenOLAT.
the class PFManager method uploadFileToDropBox.
/**
* Upload file to drop box.
*
* @param uploadFile
* @param fileName
* @param limitFileCount
* @param courseEnv
* @param pfNode
* @param identity
* @return true, if successful
*/
public boolean uploadFileToDropBox(File uploadFile, String fileName, int limitFileCount, CourseEnvironment courseEnv, PFCourseNode pfNode, Identity identity) {
if (uploadFile.exists() && uploadFile.isFile() && uploadFile.length() > 0) {
VFSContainer dropbox = resolveOrCreateDropFolder(courseEnv, pfNode, identity);
int fileCount = countFiles(dropbox);
if (fileCount <= limitFileCount) {
VFSLeaf uploadedFile = dropbox.createChildLeaf(fileName);
VFSManager.copyContent(uploadFile, uploadedFile);
return true;
}
}
return false;
}
use of org.olat.core.util.vfs.VFSLeaf in project OpenOLAT by OpenOLAT.
the class ProjectDetailsDisplayController method doFileDelivery.
private void doFileDelivery(UserRequest ureq, final Project project, final CourseEnvironment courseEnv, final CourseNode cNode) {
// Create a mapper to deliver the auto-download of the file. We have to
// create a dedicated mapper here
// and can not reuse the standard briefcase way of file delivering, some
// very old fancy code
// Mapper is cleaned up automatically by basic controller
OlatRootFolderImpl rootFolder = new OlatRootFolderImpl(projectBrokerManager.getAttamchmentRelativeRootPath(project, courseEnv, cNode), null);
VFSItem item = rootFolder.resolve(project.getAttachmentFileName());
if (item instanceof VFSLeaf) {
VFSLeaf attachment = (VFSLeaf) item;
MediaResource resource = new VFSMediaResource(attachment);
ureq.getDispatchResult().setResultingMediaResource(resource);
}
}
use of org.olat.core.util.vfs.VFSLeaf in project OpenOLAT by OpenOLAT.
the class ProjectBrokerManagerImpl method saveAttachedFile.
public void saveAttachedFile(Project project, String fileName, VFSLeaf uploadedItem, CourseEnvironment courseEnv, CourseNode cNode) {
logDebug("saveAttachedFile file-name=" + uploadedItem.getName());
OlatRootFolderImpl uploadVFSContainer = new OlatRootFolderImpl(getAttamchmentRelativeRootPath(project, courseEnv, cNode), null);
logDebug("saveAttachedFile uploadVFSContainer.relPath=" + uploadVFSContainer.getRelPath());
// only one attachment, delete other file
for (Iterator<VFSItem> iterator = uploadVFSContainer.getItems().iterator(); iterator.hasNext(); ) {
VFSItem item = iterator.next();
// Project.getAttachmentFileName is the previous file-name, will not be deleted; student could have open detail-project page with previous attachemnt-link
if (!item.getName().equals(project.getAttachmentFileName())) {
item.delete();
}
}
VFSLeaf newFile = (VFSLeaf) uploadVFSContainer.resolve(fileName);
if (newFile == null) {
newFile = uploadVFSContainer.createChildLeaf(fileName);
}
BufferedInputStream in = new BufferedInputStream(uploadedItem.getInputStream());
BufferedOutputStream out = new BufferedOutputStream(newFile.getOutputStream(false));
boolean success = false;
if (in != null) {
success = FileUtils.copy(in, out);
}
FileUtils.closeSafely(in);
FileUtils.closeSafely(out);
logDebug("saveAttachedFile success=" + success);
}
use of org.olat.core.util.vfs.VFSLeaf in project OpenOLAT by OpenOLAT.
the class MessageEditController method persistTempUploadedFiles.
/**
* - used locally if in edit mode where the msg-key is known
* - called from ForumController after creating a thread or a reply to copy temp files to
* msg-folder
*
* @param tmpMessage
*/
public void persistTempUploadedFiles(Message tmpMessage) {
if (tmpMessage == null)
throw new AssertException("Message may not be null to persist temp files");
VFSContainer msgContainer = fm.getMessageContainer(forum.getKey(), message.getKey());
if (msgContainer != null) {
List<VFSItem> tmpFList = getTempFolderFileList();
for (VFSItem file : tmpFList) {
VFSLeaf leaf = (VFSLeaf) file;
try {
FileUtils.bcopy(leaf.getInputStream(), msgContainer.createChildLeaf(leaf.getName()).getOutputStream(false), "forumSaveUploadedFile");
} catch (IOException e) {
removeTempUploadedFiles();
throw new RuntimeException("I/O error saving uploaded file:" + msgContainer + "/" + leaf.getName());
}
}
}
removeTempUploadedFiles();
}
Aggregations