Search in sources :

Example 71 with LocalFileImpl

use of org.olat.core.util.vfs.LocalFileImpl in project OpenOLAT by OpenOLAT.

the class SharedFolderManager method getAsMediaResource.

public MediaResource getAsMediaResource(OLATResourceable res) {
    String exportFileName = res.getResourceableId() + ".zip";
    File fExportZIP = new File(WebappHelper.getTmpDir() + "/" + exportFileName);
    VFSContainer sharedFolder = getSharedFolder(res);
    // OLAT-5368: do intermediate commit to avoid transaction timeout
    // discussion intermediatecommit vs increased transaction timeout:
    // pro intermediatecommit: not much
    // pro increased transaction timeout: would fix OLAT-5368 but only move the problem
    // @TODO OLAT-2597: real solution is a long-running background-task concept...
    DBFactory.getInstance().intermediateCommit();
    ZipUtil.zip(sharedFolder.getItems(), new LocalFileImpl(fExportZIP), false);
    return new CleanupAfterDeliveryFileMediaResource(fExportZIP);
}
Also used : CleanupAfterDeliveryFileMediaResource(org.olat.core.gui.media.CleanupAfterDeliveryFileMediaResource) VFSContainer(org.olat.core.util.vfs.VFSContainer) LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl) File(java.io.File)

Example 72 with LocalFileImpl

use of org.olat.core.util.vfs.LocalFileImpl in project OpenOLAT by OpenOLAT.

the class ItemFormController method fileUploaded.

/**
 * Helper to process a uploaded file. Adjust the filename and the file
 * suffix. Guess the width and height and fill the appropriate fields.
 */
private void fileUploaded() {
    file.clearError();
    if (file.isUploadSuccess()) {
        String newFilename = file.getUploadFileName().toLowerCase().replaceAll(" ", "_");
        file.setUploadFileName(newFilename);
        VFSLeaf movie = new LocalFileImpl(file.getUploadFile());
        if (newFilename.endsWith("mov") || newFilename.endsWith("m4v")) {
            // when uploading a video from an iOS device.
            if (movieService.isMP4(movie, newFilename)) {
                newFilename = newFilename.substring(0, newFilename.length() - 3) + "mp4";
                file.setUploadFileName(newFilename);
            }
        }
        if (validateFilename(newFilename)) {
            // try to detect width and height for movies, prefill for user if possible
            Size size = movieService.getSize(movie, FileUtils.getFileSuffix(newFilename));
            if (size != null) {
                if (size.getWidth() > 1) {
                    widthEl.setValue(Integer.toString(size.getWidth()));
                }
                if (size.getHeight() > 1) {
                    heightEl.setValue(Integer.toString(size.getHeight()));
                }
            }
        }
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) Size(org.olat.core.commons.services.image.Size) LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl)

Example 73 with LocalFileImpl

use of org.olat.core.util.vfs.LocalFileImpl in project OpenOLAT by OpenOLAT.

the class RepositoryEntryImportExport method exportDoExportProperties.

/**
 * Export metadata of a repository entry to a file.
 * Only one repository entry's metadata may be exported into a directory. The
 * file name of the properties file will be the same for all repository entries!
 */
public void exportDoExportProperties() {
    // save repository entry properties
    FileOutputStream fOut = null;
    try {
        fOut = new FileOutputStream(new File(baseDirectory, PROPERTIES_FILE));
        XStream xstream = getXStream();
        RepositoryEntryImport imp = new RepositoryEntryImport(re);
        RepositoryManager rm = RepositoryManager.getInstance();
        VFSLeaf image = rm.getImage(re);
        if (image instanceof LocalFileImpl) {
            imp.setImageName(image.getName());
            FileUtils.copyFileToDir(((LocalFileImpl) image).getBasefile(), baseDirectory, "");
        }
        RepositoryService repositoryService = CoreSpringFactory.getImpl(RepositoryService.class);
        VFSLeaf movie = repositoryService.getIntroductionMovie(re);
        if (movie instanceof LocalFileImpl) {
            imp.setMovieName(movie.getName());
            FileUtils.copyFileToDir(((LocalFileImpl) movie).getBasefile(), baseDirectory, "");
        }
        addLicenseInformations(imp, re);
        xstream.toXML(imp, fOut);
    } catch (IOException ioe) {
        throw new OLATRuntimeException("Error writing repo properties.", ioe);
    } finally {
        FileUtils.closeSafely(fOut);
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) XStream(com.thoughtworks.xstream.XStream) FileOutputStream(java.io.FileOutputStream) LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl) IOException(java.io.IOException) File(java.io.File)

Example 74 with LocalFileImpl

use of org.olat.core.util.vfs.LocalFileImpl in project OpenOLAT by OpenOLAT.

the class RepositoryEntryImportExport method importContent.

public RepositoryEntry importContent(RepositoryEntry newEntry, VFSContainer mediaContainer) {
    if (!anyExportedPropertiesAvailable())
        return newEntry;
    RepositoryManager repositoryManager = CoreSpringFactory.getImpl(RepositoryManager.class);
    if (StringHelper.containsNonWhitespace(getImageName())) {
        File newFile = new File(baseDirectory, getImageName());
        VFSLeaf newImage = new LocalFileImpl(newFile);
        repositoryManager.setImage(newImage, newEntry);
    }
    if (StringHelper.containsNonWhitespace(getMovieName())) {
        String movieName = getMovieName();
        String extension = FileUtils.getFileSuffix(movieName);
        File newFile = new File(baseDirectory, movieName);
        try (InputStream inStream = new FileInputStream(newFile)) {
            VFSLeaf movieLeaf = mediaContainer.createChildLeaf(newEntry.getKey() + "." + extension);
            VFSManager.copyContent(inStream, movieLeaf);
        } catch (IOException e) {
            log.error("", e);
        }
    }
    return setRepoEntryPropertiesFromImport(newEntry);
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl) IOException(java.io.IOException) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 75 with LocalFileImpl

use of org.olat.core.util.vfs.LocalFileImpl in project OpenOLAT by OpenOLAT.

the class RepositoryEditDescriptionController method formInnerEvent.

@Override
protected void formInnerEvent(UserRequest ureq, FormItem source, FormEvent event) {
    if (source == dateTypesEl) {
        updateDatesVisibility();
    } else if (source == licenseEl) {
        LicenseUIFactory.updateVisibility(licenseEl, licensorEl, licenseFreetextEl);
        ;
    } else if (source == fileUpload) {
        if (FileElementEvent.DELETE.equals(event.getCommand())) {
            fileUpload.clearError();
            VFSLeaf img = repositoryManager.getImage(repositoryEntry);
            if (fileUpload.getUploadFile() != null && fileUpload.getUploadFile() != fileUpload.getInitialFile()) {
                fileUpload.reset();
                if (img != null) {
                    fileUpload.setInitialFile(((LocalFileImpl) img).getBasefile());
                }
            } else if (img != null) {
                repositoryManager.deleteImage(repositoryEntry);
                fileUpload.setInitialFile(null);
            }
            flc.setDirty(true);
        }
    } else if (source == movieUpload) {
        if (FileElementEvent.DELETE.equals(event.getCommand())) {
            movieUpload.clearError();
            VFSLeaf movie = repositoryService.getIntroductionMovie(repositoryEntry);
            if (movieUpload.getUploadFile() != null && movieUpload.getUploadFile() != movieUpload.getInitialFile()) {
                movieUpload.reset();
                if (movie != null) {
                    movieUpload.setInitialFile(((LocalFileImpl) movie).getBasefile());
                }
            } else if (movie != null) {
                movie.delete();
                movieUpload.setInitialFile(null);
            }
            flc.setDirty(true);
        }
    }
    super.formInnerEvent(ureq, source, event);
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl)

Aggregations

LocalFileImpl (org.olat.core.util.vfs.LocalFileImpl)126 File (java.io.File)70 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)52 VFSContainer (org.olat.core.util.vfs.VFSContainer)32 Size (org.olat.core.commons.services.image.Size)22 ArrayList (java.util.ArrayList)20 IOException (java.io.IOException)18 VFSItem (org.olat.core.util.vfs.VFSItem)18 RandomAccessFile (java.io.RandomAccessFile)14 FileChannel (java.nio.channels.FileChannel)12 FileChannelWrapper (org.jcodec.common.FileChannelWrapper)12 CannotGenerateThumbnailException (org.olat.core.commons.services.thumbnail.CannotGenerateThumbnailException)12 OLATResource (org.olat.resource.OLATResource)10 Date (java.util.Date)8 MP4Demuxer (org.jcodec.containers.mp4.demuxer.MP4Demuxer)8 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)8 OLATRuntimeException (org.olat.core.logging.OLATRuntimeException)8 VFSCPNamedItem (org.olat.ims.cp.ui.VFSCPNamedItem)8 BufferedImage (java.awt.image.BufferedImage)6 InputStream (java.io.InputStream)6