Search in sources :

Example 86 with LocalFileImpl

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

the class GlossaryItemManager method upgradeAndDeleteOldGlossary.

/**
 * upgrades the old textmarker-format into the new DocBook-glossary-format
 *
 * @param folderContainingGlossary
 * @param textMarkerFile
 */
protected void upgradeAndDeleteOldGlossary(VFSContainer folderContainingGlossary, VFSLeaf textMarkerFile) {
    // check if a new glossary exists, warn
    if (folderContainingGlossary.resolve(GLOSSARY_FILENAME) != null) {
        logError("Upgrading Glossary in " + folderContainingGlossary.toString() + ": There is already a new glossary-file. There can't be an old and a new version in the same directory!", null);
    } else {
        // upgrade it
        TextMarkerManager textMarkerManager = TextMarkerManagerImpl.getInstance();
        List<TextMarker> textMarkerList = textMarkerManager.loadTextMarkerList(textMarkerFile);
        Collections.sort(textMarkerList);
        ArrayList<GlossaryItem> glossaryItemArr = new ArrayList<GlossaryItem>();
        for (TextMarker tm : textMarkerList) {
            String glossTerm = tm.getMarkedMainText();
            String glossDef = tm.getHooverText();
            GlossaryItem glossItem = new GlossaryItem(glossTerm, glossDef);
            // handle alias -> save as synonyms
            String aliasString = tm.getMarkedAliasText();
            if (StringHelper.containsNonWhitespace(aliasString)) {
                String[] aliasArr = aliasString.split(";");
                ArrayList<String> glossSynonyms = new ArrayList<String>();
                glossSynonyms.addAll(Arrays.asList(aliasArr));
                glossItem.setGlossSynonyms(glossSynonyms);
            }
            glossaryItemArr.add(glossItem);
        }
        VFSLeaf glossaryFile = folderContainingGlossary.createChildLeaf(GLOSSARY_FILENAME);
        saveToFile(glossaryFile, glossaryItemArr);
        // keep a backup in debug mode:
        if (Settings.isDebuging()) {
            File tmFile = ((LocalFileImpl) textMarkerFile).getBasefile();
            File tmCont = ((LocalFolderImpl) folderContainingGlossary).getBasefile();
            FileUtils.copyFileToDir(tmFile, new File(tmCont + "/bkp"), "backup old glossary");
        }
        textMarkerFile.delete();
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) ArrayList(java.util.ArrayList) LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl) TextMarkerManager(org.olat.core.gui.control.generic.textmarker.TextMarkerManager) TextMarker(org.olat.core.gui.control.generic.textmarker.TextMarker) LocalFolderImpl(org.olat.core.util.vfs.LocalFolderImpl) File(java.io.File)

Example 87 with LocalFileImpl

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

the class FileElementImpl method setInitialFile.

@Override
public void setInitialFile(File initialFile) {
    this.initialFile = initialFile;
    if (initialFile != null && previewEl != null) {
        VFSLeaf media = new LocalFileImpl(initialFile);
        previewEl.setMedia(media);
        previewEl.setMaxWithAndHeightToFitWithin(300, 200);
        previewEl.setVisible(true);
    } else if (previewEl != null) {
        previewEl.setVisible(false);
    }
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl)

Example 88 with LocalFileImpl

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

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

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

the class ExportManager method saveFile.

private void saveFile(String targetDir, String fileName, VFSContainer tmpDir, List<VFSItem> files, String email, String emailI18nSubkey, Locale locale) {
    File file = new File(targetDir, fileName);
    VFSLeaf exportFile = new LocalFileImpl(file);
    if (!ZipUtil.zip(files, exportFile, true)) {
        // cleanup zip file
        exportFile.delete();
    } else {
        // success
        sendEMail(email, locale, emailI18nSubkey);
    }
    removeTemporaryFolder(tmpDir);
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl) File(java.io.File)

Example 90 with LocalFileImpl

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

the class ForumOpenXMLFormatter method processAttachments.

private void processAttachments(VFSContainer attachmentsContainer) {
    List<VFSItem> attachments = new ArrayList<VFSItem>(attachmentsContainer.getItems(filter));
    for (VFSItem attachment : attachments) {
        if (attachment instanceof LocalFileImpl) {
            // add the text
            document.appendText(translator.translate("attachments"), true, Style.bold);
        }
    }
    for (VFSItem attachment : attachments) {
        if (attachment instanceof LocalFileImpl) {
            File file = ((LocalFileImpl) attachment).getBasefile();
            String filename = file.getName();
            int lastDot = filename.lastIndexOf('.');
            boolean attach = true;
            if (lastDot > 0) {
                String extension = filename.substring(lastDot + 1).toLowerCase();
                if ("jpeg".equals(extension) || "jpg".equals(extension) || "gif".equals(extension) || "png".equals(extension)) {
                    document.appendImage(file);
                    attach = false;
                }
            }
            if (attach) {
                StringBuilder attachSb = new StringBuilder(64);
                String uniqueFilename = getUniqueFilename(file);
                fileToAttachmentsMap.put(file, new DocReference("", uniqueFilename, null, file));
                attachSb.append(filename).append(": /attachments/").append(uniqueFilename);
                document.appendText(attachSb.toString(), true);
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) VFSItem(org.olat.core.util.vfs.VFSItem) LocalFileImpl(org.olat.core.util.vfs.LocalFileImpl) File(java.io.File) DocReference(org.olat.core.util.openxml.DocReference)

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