Search in sources :

Example 96 with LocalFileImpl

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

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)

Example 97 with LocalFileImpl

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

the class VideoManagerImpl method getFrameWithFilter.

@Override
public boolean getFrameWithFilter(OLATResource videoResource, int frameNumber, long duration, VFSLeaf frame) {
    File videoFile = ((LocalFileImpl) getMasterVideoFile(videoResource)).getBasefile();
    BufferedImage bufImg = null;
    boolean imgBlack = true;
    int countBlack = 0;
    try (RandomAccessFile randomAccessFile = new RandomAccessFile(videoFile, "r")) {
        OutputStream frameOutputStream = frame.getOutputStream(false);
        FileChannel ch = randomAccessFile.getChannel();
        FileChannelWrapper in = new FileChannelWrapper(ch);
        FrameGrab frameGrab = new FrameGrab(in).seekToFrameSloppy(frameNumber);
        bufImg = frameGrab.getFrame();
        int xmin = bufImg.getMinX();
        int ymin = bufImg.getMinY();
        int xmax = xmin + bufImg.getWidth();
        int ymax = ymin + bufImg.getHeight();
        int pixelCount = bufImg.getWidth() * bufImg.getHeight();
        for (int x = xmin; x < xmax; x++) {
            for (int y = ymin; y < ymax; y++) {
                int rgb = bufImg.getRGB(x, y);
                // int alpha = (0xff000000 & rgb) >>> 24;
                int r = (0x00ff0000 & rgb) >> 16;
                int g = (0x0000ff00 & rgb) >> 8;
                int b = (0x000000ff & rgb);
                if (r < 30 && g < 30 && b < 30) {
                    countBlack++;
                }
            }
        }
        if (countBlack > (int) (0.7F * pixelCount)) {
            imgBlack = true;
        } else {
            imgBlack = false;
            ImageIO.write(bufImg, "JPG", frameOutputStream);
        }
        // avoid endless loop
        if (frameNumber > duration) {
            imgBlack = false;
        }
        // close everything to prevent resource leaks
        frameOutputStream.close();
        in.close();
        ch.close();
        return imgBlack;
    } catch (Exception | AssertionError e) {
        log.error("Could not get frame::" + frameNumber + " for video::" + videoFile.getAbsolutePath(), e);
        return false;
    }
}
Also used : FileChannel(java.nio.channels.FileChannel) BufferedOutputStream(java.io.BufferedOutputStream) OutputStream(java.io.OutputStream) FileChannelWrapper(org.jcodec.common.FileChannelWrapper) LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl) BufferedImage(java.awt.image.BufferedImage) SchedulerException(org.quartz.SchedulerException) IOException(java.io.IOException) FrameGrab(org.jcodec.api.FrameGrab) RandomAccessFile(java.io.RandomAccessFile) RandomAccessFile(java.io.RandomAccessFile) ZipFile(java.util.zip.ZipFile) File(java.io.File)

Example 98 with LocalFileImpl

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

the class VideoManagerImpl method getFrame.

/**
 * write the the given frame at frameNumber in the frame leaf
 * @param videoResource videoresource
 * @param frameNumber the frameNumber at which the frame should be taken from
 * @param frame the VFSLeaf to write the picked image to
 */
@Override
public boolean getFrame(OLATResource videoResource, int frameNumber, VFSLeaf frame) {
    File videoFile = ((LocalFileImpl) getMasterVideoFile(videoResource)).getBasefile();
    try (RandomAccessFile randomAccessFile = new RandomAccessFile(videoFile, "r")) {
        FileChannel ch = randomAccessFile.getChannel();
        FileChannelWrapper in = new FileChannelWrapper(ch);
        FrameGrab frameGrab = new FrameGrab(in).seekToFrameSloppy(frameNumber);
        OutputStream frameOutputStream = frame.getOutputStream(false);
        BufferedImage bufImg = frameGrab.getFrame();
        ImageIO.write(bufImg, "JPG", frameOutputStream);
        // close everything to prevent resource leaks
        frameOutputStream.close();
        in.close();
        ch.close();
        return true;
    } catch (Exception | AssertionError e) {
        log.error("Could not get frame::" + frameNumber + " for video::" + videoFile.getAbsolutePath(), e);
        return false;
    }
}
Also used : FrameGrab(org.jcodec.api.FrameGrab) RandomAccessFile(java.io.RandomAccessFile) FileChannel(java.nio.channels.FileChannel) BufferedOutputStream(java.io.BufferedOutputStream) OutputStream(java.io.OutputStream) FileChannelWrapper(org.jcodec.common.FileChannelWrapper) LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl) RandomAccessFile(java.io.RandomAccessFile) ZipFile(java.util.zip.ZipFile) File(java.io.File) BufferedImage(java.awt.image.BufferedImage) SchedulerException(org.quartz.SchedulerException) IOException(java.io.IOException)

Example 99 with LocalFileImpl

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

the class ScormAssessmentManager method collectData.

/**
 * Collects the cmi data of the given Scorm-file.
 * @param scoFile
 * @return
 */
private List<CmiData> collectData(VFSItem scoFile) {
    List<CmiData> datas = new ArrayList<CmiData>();
    ScoDocument document = new ScoDocument(null);
    try {
        if (scoFile instanceof LocalFileImpl) {
            document.loadDocument(((LocalFileImpl) scoFile).getBasefile());
        } else {
            logger.warn("Cannot use this type of VSFItem to load a SCO Datamodel: " + scoFile.getClass().getName(), null);
            return null;
        }
        String fileName = scoFile.getName();
        String itemId = fileName.substring(0, fileName.length() - 4);
        String[][] scoModel = document.getScoModel();
        for (String[] line : scoModel) {
            datas.add(new CmiData(itemId, line[0], line[1]));
        }
    } catch (Exception e) {
        logger.error("Cannot load a SCO Datamodel", e);
    }
    return datas;
}
Also used : ArrayList(java.util.ArrayList) LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl) ScoDocument(org.olat.modules.scorm.server.servermodels.ScoDocument) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException)

Example 100 with LocalFileImpl

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

the class ItemSequence method archiveScoData.

// <OLATCE-289>
/**
 * This method copies the current cmi-file to a new file with timestamp so that all attempts
 * can be evaluated by the assessment tool.
 * @return
 */
public boolean archiveScoData() {
    File currentCmiFile = _scoDataModel.getFile().getAbsoluteFile();
    LocalFileImpl currentCmiFileVFS = new LocalFileImpl(_scoDataModel.getFile().getAbsoluteFile());
    String suffix = "." + FileUtils.getFileSuffix(currentCmiFile.getName());
    String newFileName = currentCmiFile.getName().substring(0, currentCmiFile.getName().indexOf(suffix)) + "_" + String.valueOf(System.currentTimeMillis() + suffix);
    File outf = new File(currentCmiFile.getParentFile(), newFileName);
    OutputStream os = null;
    try {
        os = new FileOutputStream(outf);
    } catch (FileNotFoundException e) {
        return false;
    }
    InputStream is = currentCmiFileVFS.getInputStream();
    FileUtils.copy(is, os);
    FileUtils.closeSafely(os);
    FileUtils.closeSafely(is);
    return true;
}
Also used : InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl) File(java.io.File)

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