Search in sources :

Example 11 with LocalFileImpl

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

the class ImpressumAdminController method checkContent.

private boolean checkContent(VFSItem file) {
    boolean check = false;
    if (file instanceof VFSLeaf && file.exists()) {
        if (file instanceof LocalFileImpl) {
            File f = ((LocalFileImpl) file).getBasefile();
            try {
                String content = FileUtils.readFileToString(f);
                content = FilterFactory.getHtmlTagAndDescapingFilter().filter(content);
                if (content.length() > 0) {
                    content = content.trim();
                }
                if (content.length() > 0) {
                    check = true;
                }
            } catch (IOException e) {
                logError("", e);
            }
        } else {
            check = true;
        }
    }
    return check;
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl) IOException(java.io.IOException) File(java.io.File)

Example 12 with LocalFileImpl

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

the class FeedFormController method initForm.

/**
 * @see org.olat.core.gui.components.form.flexible.impl.FormBasicController#initForm(org.olat.core.gui.components.form.flexible.FormItemContainer,
 *      org.olat.core.gui.control.Controller, org.olat.core.gui.UserRequest)
 */
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    // title might be longer from external source
    String saveTitle = PersistenceHelper.truncateStringDbSave(feed.getTitle(), 256, true);
    title = uifactory.addTextElement("title", "feed.title.label", 256, saveTitle, formLayout);
    title.setElementCssClass("o_sel_feed_title");
    title.setMandatory(true);
    title.setNotEmptyCheck("feed.form.field.is_mandatory");
    description = uifactory.addRichTextElementForStringDataMinimalistic("description", "feed.form.description", feed.getDescription(), 5, -1, formLayout, getWindowControl());
    description.setMaxLength(4000);
    RichTextConfiguration richTextConfig = description.getEditorConfiguration();
    // set upload dir to the media dir
    richTextConfig.setFileBrowserUploadRelPath("media");
    // Add a delete link and an image component to the image container.
    deleteImage = uifactory.addFormLink("feed.image.delete", formLayout, Link.BUTTON);
    deleteImage.setVisible(false);
    file = uifactory.addFileElement(getWindowControl(), "feed.file.label", formLayout);
    file.addActionListener(FormEvent.ONCHANGE);
    file.setPreview(ureq.getUserSession(), true);
    if (feed.getImageName() != null) {
        VFSLeaf imageResource = FeedManager.getInstance().createFeedMediaFile(feed, feed.getImageName(), null);
        if (imageResource instanceof LocalFileImpl) {
            file.setPreview(ureq.getUserSession(), true);
            file.setInitialFile(((LocalFileImpl) imageResource).getBasefile());
            deleteImage.setVisible(true);
        }
    }
    Set<String> mimeTypes = new HashSet<String>();
    mimeTypes.add("image/jpeg");
    mimeTypes.add("image/jpg");
    mimeTypes.add("image/png");
    mimeTypes.add("image/gif");
    file.limitToMimeType(mimeTypes, "feed.form.file.type.error.images", null);
    int maxFileSizeKB = feedQuota.getUlLimitKB().intValue();
    String supportAddr = WebappHelper.getMailConfig("mailQuota");
    file.setMaxUploadSizeKB(maxFileSizeKB, "ULLimitExceeded", new String[] { new Long(maxFileSizeKB / 1024).toString(), supportAddr });
    // if external feed, display feed-url text-element:
    if (feed.isExternal()) {
        feedUrl = uifactory.addTextElement("feedUrl", "feed.form.feedurl", 5000, feed.getExternalFeedUrl(), flc);
        feedUrl.setElementCssClass("o_sel_feed_url");
        feedUrl.setDisplaySize(70);
        String type = feed.getResourceableTypeName();
        if (type != null && type.indexOf("BLOG") >= 0) {
            feedUrl.setExampleKey("feed.form.feedurl.example", null);
        } else {
            feedUrl.setExampleKey("feed.form.feedurl.example_podcast", null);
        }
    }
    // Submit and cancelButton buttons
    final FormLayoutContainer buttonLayout = FormLayoutContainer.createButtonLayout("button_layout", getTranslator());
    formLayout.add(buttonLayout);
    uifactory.addFormSubmitButton("submit", buttonLayout);
    cancelButton = uifactory.addFormLink("cancel", buttonLayout, Link.BUTTON);
}
Also used : RichTextConfiguration(org.olat.core.gui.components.form.flexible.impl.elements.richText.RichTextConfiguration) VFSLeaf(org.olat.core.util.vfs.VFSLeaf) LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) HashSet(java.util.HashSet)

Example 13 with LocalFileImpl

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

the class ProjectBrokerCourseNode method importProject.

private void importProject(File projectDir, File projectFile, ProjectBroker projectBroker, ICourse course, CourseEnvironmentMapper envMapper) {
    XStream xstream = XStreamHelper.createXStreamInstance();
    BusinessGroupService bgs = CoreSpringFactory.getImpl(BusinessGroupService.class);
    CoursePropertyManager cpm = course.getCourseEnvironment().getCoursePropertyManager();
    ProjectGroupManager projectGroupManager = CoreSpringFactory.getImpl(ProjectGroupManager.class);
    ProjectBrokerManager projectBrokerManager = CoreSpringFactory.getImpl(ProjectBrokerManager.class);
    // read the projectConfiguration from the importDirectory
    try {
        @SuppressWarnings("unchecked") Map<String, Object> projectConfig = (HashMap<String, Object>) XStreamHelper.readObject(xstream, projectFile);
        String projectTitle = (String) projectConfig.get("title");
        Long originalGroupKey = null;
        if (projectConfig.containsKey("businessGroupKey")) {
            originalGroupKey = (Long) projectConfig.get("businessGroupKey");
        } else {
            for (BusinessGroupReference ref : envMapper.getGroups()) {
                if (ref.getName().endsWith(projectTitle)) {
                    originalGroupKey = ref.getOriginalKey();
                }
            }
        }
        BusinessGroup projectGroup = null;
        if (originalGroupKey != null) {
            Long groupKey = envMapper.toGroupKeyFromOriginalKey(originalGroupKey);
            projectGroup = bgs.loadBusinessGroup(groupKey);
        }
        if (projectGroup == null) {
            projectGroup = projectGroupManager.createProjectGroupFor(projectBroker.getKey(), envMapper.getAuthor(), projectTitle, (String) projectConfig.get("description"), course.getResourceableId());
        }
        if (envMapper.getAuthor() != null) {
            Identity author = envMapper.getAuthor();
            bgs.addOwners(author, null, Collections.singletonList(author), projectGroup, null);
        }
        Project project = projectBrokerManager.createAndSaveProjectFor(projectTitle, (String) projectConfig.get("description"), projectBrokerManager.getProjectBrokerId(cpm, this), projectGroup);
        projectGroupManager.setDeselectionAllowed(project, (boolean) projectConfig.get("allowDeselection"));
        project.setMailNotificationEnabled((boolean) projectConfig.get("mailNotificationEnabled"));
        project.setMaxMembers((int) projectConfig.get("maxMembers"));
        project.setAttachedFileName(projectConfig.get("attachmentFileName").toString());
        for (int i = 0; i < (int) projectConfig.get("customeFieldSize"); i++) {
            project.setCustomFieldValue(i, projectConfig.get("customFieldValue" + i).toString());
        }
        projectBrokerManager.updateProject(project);
        // get the attachment directory within the project
        // directory
        // .getParentFile().listFiles(attachmentFilter);
        File attachmentDir = new File(projectDir, "attachment");
        if (attachmentDir.exists()) {
            File[] attachment = attachmentDir.listFiles();
            if (attachment.length > 0) {
                VFSLeaf attachmentLeaf = new LocalFileImpl(attachment[0]);
                projectBrokerManager.saveAttachedFile(project, projectConfig.get("attachmentFileName").toString(), attachmentLeaf, course.getCourseEnvironment(), this);
            }
        }
    } catch (Exception e) {
        // handle/log error in case of FileIO exception or cast
        // exception if import input is not correct
        log.error("Error while importing a project into projectbroker", e);
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) HashMap(java.util.HashMap) BusinessGroup(org.olat.group.BusinessGroup) XStream(com.thoughtworks.xstream.XStream) LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl) ProjectBrokerManager(org.olat.course.nodes.projectbroker.service.ProjectBrokerManager) AssertException(org.olat.core.logging.AssertException) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) IOException(java.io.IOException) ProjectGroupManager(org.olat.course.nodes.projectbroker.service.ProjectGroupManager) Project(org.olat.course.nodes.projectbroker.datamodel.Project) BusinessGroupService(org.olat.group.BusinessGroupService) BusinessGroupReference(org.olat.group.model.BusinessGroupReference) Identity(org.olat.core.id.Identity) File(java.io.File) CoursePropertyManager(org.olat.course.properties.CoursePropertyManager) PersistingCoursePropertyManager(org.olat.course.properties.PersistingCoursePropertyManager)

Example 14 with LocalFileImpl

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

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 15 with LocalFileImpl

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

the class HotspotEditorController method formInnerEvent.

@Override
protected void formInnerEvent(UserRequest ureq, FormItem source, FormEvent event) {
    if (newCircleButton == source) {
        createHotspotChoice(Shape.CIRCLE, "60,60,25");
        updateHotspots(ureq);
    } else if (newRectButton == source) {
        createHotspotChoice(Shape.RECT, "50,50,100,100");
        updateHotspots(ureq);
    } else if (backgroundEl == source) {
        // upload in itemDirectory;
        if (FileElementEvent.DELETE.equals(event.getCommand())) {
            if (backgroundEl.getUploadFile() != null && backgroundEl.getUploadFile() != backgroundEl.getInitialFile()) {
                backgroundEl.reset();
                if (initialBackgroundImage != null) {
                    backgroundEl.setInitialFile(initialBackgroundImage);
                }
            } else if (initialBackgroundImage != null) {
                initialBackgroundImage = null;
                backgroundEl.setInitialFile(null);
            }
            flc.setDirty(true);
        } else if (backgroundEl.isUploadSuccess()) {
            List<ValidationStatus> status = new ArrayList<>();
            backgroundEl.validate(status);
            if (status.isEmpty()) {
                flc.setDirty(true);
                backgroundImage = backgroundEl.moveUploadFileTo(itemFile.getParentFile());
                Size size = imageService.getSize(new LocalFileImpl(backgroundImage), null);
                optimizeResizeEl(size, true);
            }
        }
        Size backgroundSize = updateBackground();
        updateHotspots(ureq);
        updateHotspotsPosition(backgroundSize);
    } else if (correctHotspotsEl == source) {
        MultipleSelectionElement correctEl = (MultipleSelectionElement) source;
        Collection<String> correctResponseIds = correctEl.getSelectedKeys();
        doCorrectAnswers(correctResponseIds);
        flc.setDirty(true);
    } else if (layoutEl == source) {
        updateLayoutCssClass();
    }
    super.formInnerEvent(ureq, source, event);
}
Also used : MultipleSelectionElement(org.olat.core.gui.components.form.flexible.elements.MultipleSelectionElement) Size(org.olat.core.commons.services.image.Size) LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl) Collection(java.util.Collection) List(java.util.List) ArrayList(java.util.ArrayList)

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