Search in sources :

Example 16 with LocalFileImpl

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

the class HotspotEditorController method updateBackground.

private Size updateBackground() {
    Size size = null;
    File objectImg = null;
    if (backgroundImage != null) {
        objectImg = backgroundImage;
    } else if (initialBackgroundImage != null) {
        objectImg = initialBackgroundImage;
    }
    if (objectImg != null) {
        String relativePath = itemFile.getParentFile().toPath().relativize(objectImg.toPath()).toString();
        size = imageService.getSize(new LocalFileImpl(objectImg), null);
        hotspotsCont.contextPut("filename", relativePath);
        setBackgroundSize(size);
    } else {
        hotspotsCont.contextRemove("filename");
    }
    return size;
}
Also used : Size(org.olat.core.commons.services.image.Size) LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl) File(java.io.File)

Example 17 with LocalFileImpl

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

the class HotspotEditorController method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    setFormContextHelp("Test editor QTI 2.1 in detail#details_testeditor_fragetypen_hotspot");
    titleEl = uifactory.addTextElement("title", "form.imd.title", -1, itemBuilder.getTitle(), formLayout);
    titleEl.setElementCssClass("o_sel_assessment_item_title");
    titleEl.setMandatory(true);
    titleEl.setEnabled(!readOnly);
    String relativePath = rootDirectory.toPath().relativize(itemFile.toPath().getParent()).toString();
    VFSContainer itemContainer = (VFSContainer) rootContainer.resolve(relativePath);
    String question = itemBuilder.getQuestion();
    textEl = uifactory.addRichTextElementForQTI21("desc", "form.imd.descr", question, 8, -1, itemContainer, formLayout, ureq.getUserSession(), getWindowControl());
    textEl.addActionListener(FormEvent.ONCLICK);
    textEl.setEnabled(!readOnly);
    textEl.setVisible(!readOnly);
    if (readOnly) {
        FlowFormItem textReadOnlyEl = new FlowFormItem("descro", itemFile);
        textReadOnlyEl.setLabel("form.imd.descr", null);
        textReadOnlyEl.setBlocks(itemBuilder.getQuestionBlocks());
        textReadOnlyEl.setMapperUri(mapperUri);
        formLayout.add(textReadOnlyEl);
    }
    String[] cardinalityKeys = new String[] { Cardinality.SINGLE.name(), Cardinality.MULTIPLE.name() };
    String[] cardinalityValues = new String[] { translate(Cardinality.SINGLE.name()), translate(Cardinality.MULTIPLE.name()) };
    cardinalityEl = uifactory.addRadiosHorizontal("form.imd.cardinality", formLayout, cardinalityKeys, cardinalityValues);
    cardinalityEl.setElementCssClass("o_sel_assessment_item_cardinality");
    cardinalityEl.setEnabled(!restrictedEdit && !readOnly);
    if (itemBuilder.isSingleChoice()) {
        cardinalityEl.select(cardinalityKeys[0], true);
    } else {
        cardinalityEl.select(cardinalityKeys[1], true);
    }
    responsiveEl = uifactory.addCheckboxesHorizontal("form.imd.responsive", formLayout, onKeys, new String[] { "" });
    responsiveEl.setHelpText(translate("form.imd.responsive.hint"));
    responsiveEl.setEnabled(!restrictedEdit && !readOnly);
    if (itemBuilder.isResponsive()) {
        responsiveEl.select(onKeys[0], true);
    }
    initialBackgroundImage = getCurrentBackground();
    backgroundEl = uifactory.addFileElement(getWindowControl(), "form.imd.background", "form.imd.background", formLayout);
    backgroundEl.setEnabled(!restrictedEdit && !readOnly);
    if (initialBackgroundImage != null) {
        backgroundEl.setInitialFile(initialBackgroundImage);
    }
    backgroundEl.addActionListener(FormEvent.ONCHANGE);
    backgroundEl.setDeleteEnabled(true);
    backgroundEl.limitToMimeType(mimeTypes, "error.mimetype", new String[] { mimeTypes.toString() });
    String[] resizeKeys = new String[] { "no" };
    String[] resizeValues = new String[] { translate("form.imd.background.resize.no") };
    resizeEl = uifactory.addRadiosHorizontal("form.imd.background.resize", formLayout, resizeKeys, resizeValues);
    resizeEl.setVisible(false);
    resizeEl.setEnabled(!readOnly);
    if (initialBackgroundImage != null) {
        Size size = imageService.getSize(new LocalFileImpl(initialBackgroundImage), null);
        optimizeResizeEl(size, false);
    }
    // responses
    String page = velocity_root + "/hotspots.html";
    hotspotsCont = FormLayoutContainer.createCustomFormLayout("answers", getTranslator(), page);
    hotspotsCont.getFormItemComponent().addListener(this);
    hotspotsCont.setLabel("new.spots", null);
    hotspotsCont.setRootForm(mainForm);
    hotspotsCont.contextPut("mapperUri", backgroundMapperUri);
    hotspotsCont.contextPut("restrictedEdit", restrictedEdit || readOnly);
    JSAndCSSFormItem js = new JSAndCSSFormItem("js", new String[] { "js/jquery/openolat/jquery.drawing.js" });
    formLayout.add(js);
    formLayout.add(hotspotsCont);
    newCircleButton = uifactory.addFormLink("new.circle", "new.circle", null, hotspotsCont, Link.BUTTON);
    newCircleButton.setIconLeftCSS("o_icon o_icon-lg o_icon_circle");
    newCircleButton.setVisible(!restrictedEdit && !readOnly);
    newRectButton = uifactory.addFormLink("new.rectangle", "new.rectangle", null, hotspotsCont, Link.BUTTON);
    newRectButton.setIconLeftCSS("o_icon o_icon-lg o_icon_rectangle");
    newRectButton.setVisible(!restrictedEdit && !readOnly);
    updateBackground();
    String[] emptyKeys = new String[0];
    correctHotspotsEl = uifactory.addCheckboxesHorizontal("form.imd.correct.spots", formLayout, emptyKeys, emptyKeys);
    correctHotspotsEl.setElementCssClass("o_sel_assessment_item_correct_spots");
    correctHotspotsEl.setEnabled(!restrictedEdit && !readOnly);
    correctHotspotsEl.addActionListener(FormEvent.ONCHANGE);
    rebuildWrappersAndCorrectSelection();
    HotspotLayouts[] layouts = HotspotLayouts.values();
    String[] layoutKeys = new String[layouts.length];
    String[] layoutValues = new String[layouts.length];
    for (int i = layouts.length; i-- > 0; ) {
        layoutKeys[i] = layouts[i].cssClass();
        layoutValues[i] = translate("hotspot.layout." + layouts[i].name());
    }
    layoutEl = uifactory.addDropdownSingleselect("hotspot.layout", "hotspot.layout", formLayout, layoutKeys, layoutValues, null);
    layoutEl.addActionListener(FormEvent.ONCHANGE);
    layoutEl.setEnabled(!readOnly);
    boolean found = false;
    for (int i = layoutKeys.length; i-- > 0; ) {
        if (itemBuilder.hasHotspotInteractionClass(layoutKeys[i])) {
            layoutEl.select(layoutKeys[i], true);
            found = true;
        }
    }
    if (!found) {
        layoutEl.select(layoutKeys[0], true);
    }
    shadowEl = uifactory.addCheckboxesHorizontal("hotspot.layout.shadow", "hotspot.layout.shadow", formLayout, onKeys, new String[] { "" });
    shadowEl.setEnabled(!readOnly);
    if (!itemBuilder.hasHotspotInteractionClass(QTI21Constants.CSS_HOTSPOT_DISABLE_SHADOW)) {
        shadowEl.select(onKeys[0], true);
    }
    updateLayoutCssClass();
    // Submit Button
    FormLayoutContainer buttonsContainer = FormLayoutContainer.createButtonLayout("buttons", getTranslator());
    buttonsContainer.setElementCssClass("o_sel_hotspots_save");
    buttonsContainer.setRootForm(mainForm);
    buttonsContainer.setVisible(!readOnly);
    formLayout.add(buttonsContainer);
    uifactory.addFormSubmitButton("submit", buttonsContainer);
}
Also used : FlowFormItem(org.olat.ims.qti21.ui.components.FlowFormItem) HotspotLayouts(org.olat.ims.qti21.QTI21Constants.HotspotLayouts) Size(org.olat.core.commons.services.image.Size) JSAndCSSFormItem(org.olat.core.gui.components.htmlheader.jscss.JSAndCSSFormItem) VFSContainer(org.olat.core.util.vfs.VFSContainer) LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)

Example 18 with LocalFileImpl

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

the class HotspotChoiceScoreController method updateBackground.

protected void updateBackground() {
    File backgroundImage = null;
    if (StringHelper.containsNonWhitespace(itemBuilder.getBackground())) {
        File itemDirectory = itemFile.getParentFile();
        Path backgroundPath = itemDirectory.toPath().resolve(itemBuilder.getBackground());
        if (Files.exists(backgroundPath)) {
            backgroundImage = backgroundPath.toFile();
        }
    }
    if (backgroundImage != null) {
        String filename = backgroundImage.getName();
        Size size = imageService.getSize(new LocalFileImpl(backgroundImage), null);
        scoreCont.contextPut("filename", filename);
        if (size != null) {
            if (size.getHeight() > 0) {
                scoreCont.contextPut("height", Integer.toString(size.getHeight()));
            } else {
                scoreCont.contextRemove("height");
            }
            if (size.getWidth() > 0) {
                scoreCont.contextPut("width", Integer.toString(size.getWidth()));
            } else {
                scoreCont.contextRemove("width");
            }
        }
    } else {
        scoreCont.contextRemove("filename");
    }
    List<HotspotWrapper> choiceWrappers = new ArrayList<>();
    List<HotspotChoice> choices = itemBuilder.getHotspotChoices();
    for (int i = 0; i < choices.size(); i++) {
        HotspotChoice choice = choices.get(i);
        choiceWrappers.add(new HotspotWrapper(choice, itemBuilder));
    }
    scoreCont.contextPut("hotspots", choiceWrappers);
}
Also used : Path(java.nio.file.Path) Size(org.olat.core.commons.services.image.Size) HotspotChoice(uk.ac.ed.ph.jqtiplus.node.item.interaction.graphic.HotspotChoice) ArrayList(java.util.ArrayList) LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl) File(java.io.File)

Example 19 with LocalFileImpl

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

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)

Example 20 with LocalFileImpl

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

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)

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