Search in sources :

Example 61 with LocalFileImpl

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

the class MovieServiceImpl method generateThumbnail.

@Override
public FinalSize generateThumbnail(VFSLeaf file, VFSLeaf thumbnailFile, int maxWidth, int maxHeight, boolean fill) throws CannotGenerateThumbnailException {
    FinalSize size = null;
    if (file instanceof LocalFileImpl && thumbnailFile instanceof LocalFileImpl) {
        try {
            WorkThreadInformations.setInfoFiles(null, file);
            WorkThreadInformations.set("Generate thumbnail (video) VFSLeaf=" + file);
            File baseFile = ((LocalFileImpl) file).getBasefile();
            File scaledImage = ((LocalFileImpl) thumbnailFile).getBasefile();
            BufferedImage frame = FrameGrab.getFrame(baseFile, 20);
            Size scaledSize = ImageHelperImpl.calcScaledSize(frame, maxWidth, maxHeight);
            if (ImageHelperImpl.writeTo(frame, scaledImage, scaledSize, "jpeg")) {
                size = new FinalSize(scaledSize.getWidth(), scaledSize.getHeight());
            }
        // NullPointerException can be thrown if the jcodec cannot handle the codec of the movie
        // ArrayIndexOutOfBoundsException
        } catch (Exception | AssertionError e) {
            log.error("", e);
        } finally {
            WorkThreadInformations.unset();
        }
    }
    return size;
}
Also used : FinalSize(org.olat.core.commons.services.thumbnail.FinalSize) Size(org.olat.core.commons.services.image.Size) FinalSize(org.olat.core.commons.services.thumbnail.FinalSize) LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) BufferedImage(java.awt.image.BufferedImage) CannotGenerateThumbnailException(org.olat.core.commons.services.thumbnail.CannotGenerateThumbnailException)

Example 62 with LocalFileImpl

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

the class SendDocumentsByEMailController method setFiles.

protected void setFiles(VFSContainer rootContainer, List<VFSLeaf> leafs) {
    this.files = leafs;
    StringBuilder subjectSb = new StringBuilder();
    if (StringHelper.containsNonWhitespace(subjectElement.getValue())) {
        subjectSb.append(subjectElement.getValue()).append('\n').append('\n');
    }
    StringBuilder bodySb = new StringBuilder();
    if (StringHelper.containsNonWhitespace(bodyElement.getValue())) {
        bodySb.append(bodyElement.getValue()).append('\n').append('\n');
    }
    attachments = new ArrayList<File>();
    long fileSize = 0l;
    for (VFSLeaf file : files) {
        MetaInfo infos = null;
        if (file instanceof MetaTagged) {
            infos = ((MetaTagged) file).getMetaInfo();
        }
        // subject
        appendToSubject(file, infos, subjectSb);
        // body
        appendMetadatas(file, infos, bodySb);
        appendBusinessPath(rootContainer, file, bodySb);
        bodySb.append('\n').append('\n');
        fileSize += file.getSize();
        if (allowAttachments && file instanceof LocalFileImpl) {
            File f = ((LocalFileImpl) file).getBasefile();
            attachments.add(f);
        }
    }
    int mailQuota = CoreSpringFactory.getImpl(MailModule.class).getMaxSizeForAttachement();
    long fileSizeInMB = fileSize / (1024l * 1024l);
    if (allowAttachments) {
        if (fileSizeInMB > mailQuota) {
            attachments.clear();
            setFormWarning("send.mail.fileToBigForAttachments", new String[] { String.valueOf(mailQuota), String.valueOf(fileSizeInMB) });
        } else {
            List<FileInfo> infos = new ArrayList<FileInfo>(files.size());
            for (VFSLeaf file : files) {
                final String name = file.getName();
                final double size = file.getSize() / (1024.0 * 1024.0);
                final String sizeStr = formatMb.format(size);
                final String cssClass = CSSHelper.createFiletypeIconCssClassFor(file.getName());
                infos.add(new FileInfo(name, sizeStr, cssClass));
            }
            attachmentsLayout.contextPut("attachments", infos);
        }
    }
    subjectElement.setValue(subjectSb.toString());
    bodyElement.setValue(bodySb.toString());
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) MetaInfo(org.olat.core.commons.modules.bc.meta.MetaInfo) MetaTagged(org.olat.core.commons.modules.bc.meta.tagged.MetaTagged) ArrayList(java.util.ArrayList) LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl) MailModule(org.olat.core.util.mail.MailModule) File(java.io.File)

Example 63 with LocalFileImpl

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

the class HotspotEditorController method formOK.

@Override
protected void formOK(UserRequest ureq) {
    if (readOnly)
        return;
    itemBuilder.setTitle(titleEl.getValue());
    // set the question with the text entries
    String questionText = textEl.getRawValue();
    itemBuilder.setQuestion(questionText);
    itemBuilder.setResponsive(responsiveEl.isAtLeastSelected(1));
    File objectImg = null;
    if (backgroundImage != null) {
        objectImg = backgroundImage;
    } else if (initialBackgroundImage != null) {
        objectImg = initialBackgroundImage;
    }
    if (cardinalityEl.isOneSelected()) {
        String selectedCardinality = cardinalityEl.getSelectedKey();
        itemBuilder.setCardinality(Cardinality.valueOf(selectedCardinality));
    }
    boolean updateHotspot = true;
    if (objectImg != null) {
        String filename = objectImg.getName();
        String mimeType = WebappHelper.getMimeType(filename);
        Size currentSize = imageService.getSize(new LocalFileImpl(objectImg), null);
        Size size = currentSize;
        if (resizeEl.isVisible() && !resizeEl.isSelected(0)) {
            int maxSize = Integer.parseInt(resizeEl.getSelectedKey());
            if (maxSize < currentSize.getHeight() || maxSize < currentSize.getWidth()) {
                String extension = FileUtils.getFileSuffix(filename);
                size = imageService.scaleImage(objectImg, extension, objectImg, maxSize, maxSize, false);
                setBackgroundSize(size);
                scaleHotspot(currentSize, size);
                optimizeResizeEl(size, false);
                updateHotspot = false;
            }
        }
        int height = -1;
        int width = -1;
        if (size != null) {
            height = size.getHeight();
            width = size.getWidth();
        }
        String relPath = itemFile.getParentFile().toPath().relativize(objectImg.toPath()).toString();
        itemBuilder.setBackground(relPath, mimeType, height, width);
    }
    if (updateHotspot) {
        updateHotspots(ureq);
    }
    if (layoutEl.isOneSelected()) {
        String selectedLayout = layoutEl.getSelectedKey();
        for (HotspotLayouts layout : HotspotLayouts.values()) {
            itemBuilder.removeHotspotInteractionClass(layout.cssClass());
        }
        itemBuilder.addHotspotInteractionClass(selectedLayout);
    }
    if (shadowEl.isAtLeastSelected(1)) {
        itemBuilder.removeHotspotInteractionClass(QTI21Constants.CSS_HOTSPOT_DISABLE_SHADOW);
    } else {
        itemBuilder.addHotspotInteractionClass(QTI21Constants.CSS_HOTSPOT_DISABLE_SHADOW);
    }
    fireEvent(ureq, new AssessmentItemEvent(AssessmentItemEvent.ASSESSMENT_ITEM_CHANGED, itemBuilder.getAssessmentItem(), QTI21QuestionType.hotspot));
}
Also used : HotspotLayouts(org.olat.ims.qti21.QTI21Constants.HotspotLayouts) Size(org.olat.core.commons.services.image.Size) LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl) File(java.io.File) AssessmentItemEvent(org.olat.ims.qti21.ui.editor.events.AssessmentItemEvent)

Example 64 with LocalFileImpl

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

the class ScormExportManager method collectData.

private void collectData(String username, VFSContainer scoFolder, ScormExportVisitor visitor) {
    List<VFSItem> contents = scoFolder.getItems(new XMLFilter());
    for (VFSItem file : contents) {
        ScoDocument document = new ScoDocument(null);
        try {
            if (file instanceof LocalFileImpl) {
                document.loadDocument(((LocalFileImpl) file).getBasefile());
            } else {
                logger.warn("Cannot use this type of VSFItem to load a SCO Datamodel: " + file.getClass().getName(), null);
                continue;
            }
            String[][] scoModel = document.getScoModel();
            ScoDatas parsedDatas = parseScoModel(file.getName(), username, scoModel);
            visitor.visit(parsedDatas);
        } catch (Exception e) {
            logger.error("Cannot load a SCO Datamodel", e);
        }
    }
}
Also used : VFSItem(org.olat.core.util.vfs.VFSItem) LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl) ScoDocument(org.olat.modules.scorm.server.servermodels.ScoDocument)

Example 65 with LocalFileImpl

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

the class ScormAssessmentManager method getSequencerModel.

/**
 * Load the SequencerModel
 * @param username
 * @param courseEnv
 * @param node
 * @return can be null if the user hasn't visited the course
 */
public SequencerModel getSequencerModel(String username, CourseEnvironment courseEnv, ScormCourseNode node) {
    VFSContainer scoDirectory = ScormDirectoryHelper.getScoDirectory(username, courseEnv, node);
    if (scoDirectory == null)
        return null;
    VFSItem reloadSettingsFile = scoDirectory.resolve(RELOAD_SETTINGS_FILE);
    if (reloadSettingsFile instanceof LocalFileImpl) {
        LocalFileImpl fileImpl = (LocalFileImpl) reloadSettingsFile;
        return new SequencerModel(fileImpl.getBasefile(), null);
    } else if (reloadSettingsFile != null) {
        throw new OLATRuntimeException(this.getClass(), "Programming error, SCORM results must be file based", null);
    }
    return null;
}
Also used : OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) SequencerModel(org.olat.modules.scorm.server.servermodels.SequencerModel) VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem) 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