Search in sources :

Example 91 with VFSLeaf

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);
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VFSContainer(org.olat.core.util.vfs.VFSContainer)

Example 92 with VFSLeaf

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;
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VFSContainer(org.olat.core.util.vfs.VFSContainer)

Example 93 with VFSLeaf

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);
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) OlatRootFolderImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl) VFSItem(org.olat.core.util.vfs.VFSItem) MediaResource(org.olat.core.gui.media.MediaResource) VFSMediaResource(org.olat.core.util.vfs.VFSMediaResource) VFSMediaResource(org.olat.core.util.vfs.VFSMediaResource)

Example 94 with VFSLeaf

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);
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) OlatRootFolderImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl) BufferedInputStream(java.io.BufferedInputStream) VFSItem(org.olat.core.util.vfs.VFSItem) BufferedOutputStream(java.io.BufferedOutputStream)

Example 95 with VFSLeaf

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();
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) AssertException(org.olat.core.logging.AssertException) DBRuntimeException(org.olat.core.logging.DBRuntimeException) VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem) IOException(java.io.IOException)

Aggregations

VFSLeaf (org.olat.core.util.vfs.VFSLeaf)642 VFSContainer (org.olat.core.util.vfs.VFSContainer)338 VFSItem (org.olat.core.util.vfs.VFSItem)280 File (java.io.File)114 InputStream (java.io.InputStream)96 IOException (java.io.IOException)92 Test (org.junit.Test)86 ArrayList (java.util.ArrayList)72 OutputStream (java.io.OutputStream)60 MetaInfo (org.olat.core.commons.modules.bc.meta.MetaInfo)58 MetaTagged (org.olat.core.commons.modules.bc.meta.tagged.MetaTagged)58 OlatRootFolderImpl (org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl)58 Identity (org.olat.core.id.Identity)54 LocalFileImpl (org.olat.core.util.vfs.LocalFileImpl)52 VFSMediaResource (org.olat.core.util.vfs.VFSMediaResource)46 URL (java.net.URL)40 Date (java.util.Date)40 RepositoryEntry (org.olat.repository.RepositoryEntry)36 URI (java.net.URI)34 MediaResource (org.olat.core.gui.media.MediaResource)34