Search in sources :

Example 1 with JavaIOItem

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

the class WordOOXMLDocument method readContent.

@Override
public FileContent readContent(VFSLeaf leaf) throws IOException, DocumentException {
    File file = ((JavaIOItem) leaf).getBasefile();
    LimitedContentWriter writer = new LimitedContentWriter(100000, FileDocumentFactory.getMaxFileSize());
    try (ZipFile wordFile = new ZipFile(file)) {
        List<String> contents = new ArrayList<>();
        for (Enumeration<? extends ZipEntry> entriesEnumeration = wordFile.entries(); entriesEnumeration.hasMoreElements(); ) {
            ZipEntry entry = entriesEnumeration.nextElement();
            String name = entry.getName();
            if (name.endsWith("word/document.xml")) {
                contents.add(name);
            } else if (name.startsWith(HEADER) && name.endsWith(".xml")) {
                contents.add(name);
            } else if (name.startsWith(FOOTER) && name.endsWith(".xml")) {
                contents.add(name);
            }
        }
        if (contents.size() > 1) {
            Collections.sort(contents, new WordDocumentComparator());
        }
        for (String content : contents) {
            if (writer.accept()) {
                ZipEntry entry = wordFile.getEntry(content);
                InputStream zip = wordFile.getInputStream(entry);
                OfficeDocumentHandler dh = new OfficeDocumentHandler(writer);
                parse(new ShieldInputStream(zip), dh);
                zip.close();
            }
        }
    } catch (DocumentException e) {
        throw e;
    } catch (Exception e) {
        throw new DocumentException(e.getMessage());
    }
    return new FileContent(writer.toString());
}
Also used : JavaIOItem(org.olat.core.util.vfs.JavaIOItem) ShieldInputStream(org.olat.core.util.io.ShieldInputStream) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) ArrayList(java.util.ArrayList) ShieldInputStream(org.olat.core.util.io.ShieldInputStream) IOException(java.io.IOException) LimitedContentWriter(org.olat.core.util.io.LimitedContentWriter) ZipFile(java.util.zip.ZipFile) File(java.io.File) ZipFile(java.util.zip.ZipFile)

Example 2 with JavaIOItem

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

the class CollectImageMediaController method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    formLayout.setElementCssClass("o_sel_pf_collect_image_form");
    String title = mediaReference == null ? null : mediaReference.getTitle();
    titleEl = uifactory.addTextElement("artefact.title", "artefact.title", 255, title, formLayout);
    titleEl.setElementCssClass("o_sel_pf_collect_title");
    titleEl.setMandatory(true);
    String desc = mediaReference == null ? null : mediaReference.getDescription();
    descriptionEl = uifactory.addRichTextElementForStringDataMinimalistic("artefact.descr", "artefact.descr", desc, 8, 60, formLayout, getWindowControl());
    descriptionEl.getEditorConfiguration().setPathInStatusBar(false);
    fileEl = uifactory.addFileElement(getWindowControl(), "artefact.file", "artefact.file", formLayout);
    fileEl.limitToMimeType(imageMimeTypes, null, null);
    fileEl.addActionListener(FormEvent.ONCHANGE);
    fileEl.setMaxUploadSizeKB(10000, null, null);
    fileEl.setPreview(ureq.getUserSession(), true);
    if (mediaReference != null) {
        fileEl.setEnabled(false);
        VFSItem item = fileHandler.getImage(mediaReference);
        if (item instanceof JavaIOItem) {
            fileEl.setInitialFile(((JavaIOItem) item).getBasefile());
        }
    }
    categoriesEl = uifactory.addTextBoxListElement("categories", "categories", "categories.hint", categories, formLayout, getTranslator());
    categoriesEl.setHelpText(translate("categories.hint"));
    categoriesEl.setElementCssClass("o_sel_ep_tagsinput");
    categoriesEl.setAllowDuplicates(false);
    Date collectDate = mediaReference == null ? new Date() : mediaReference.getCollectionDate();
    String date = Formatter.getInstance(getLocale()).formatDate(collectDate);
    uifactory.addStaticTextElement("artefact.collect.date", "artefact.collect.date", date, formLayout);
    if (StringHelper.containsNonWhitespace(businessPath)) {
        String link = BusinessControlFactory.getInstance().getURLFromBusinessPathString(businessPath);
        uifactory.addStaticTextElement("artefact.collect.link", "artefact.collect.link", link, formLayout);
    }
    FormLayoutContainer buttonsCont = FormLayoutContainer.createButtonLayout("buttons", getTranslator());
    formLayout.add(buttonsCont);
    uifactory.addFormSubmitButton("save", "save", buttonsCont);
    uifactory.addFormCancelButton("cancel", buttonsCont, ureq, getWindowControl());
}
Also used : JavaIOItem(org.olat.core.util.vfs.JavaIOItem) VFSItem(org.olat.core.util.vfs.VFSItem) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) Date(java.util.Date)

Example 3 with JavaIOItem

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

the class CollectFileMediaController method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    formLayout.setElementCssClass("o_sel_pf_collect_document_form");
    String title = mediaReference == null ? null : mediaReference.getTitle();
    titleEl = uifactory.addTextElement("artefact.title", "artefact.title", 255, title, formLayout);
    titleEl.setElementCssClass("o_sel_pf_collect_title");
    titleEl.setMandatory(true);
    String desc = mediaReference == null ? null : mediaReference.getTitle();
    descriptionEl = uifactory.addRichTextElementForStringDataMinimalistic("artefact.descr", "artefact.descr", desc, 8, 60, formLayout, getWindowControl());
    descriptionEl.getEditorConfiguration().setPathInStatusBar(false);
    fileEl = uifactory.addFileElement(getWindowControl(), "artefact.file", "artefact.file", formLayout);
    fileEl.addActionListener(FormEvent.ONCHANGE);
    if (mediaReference != null) {
        fileEl.setEnabled(false);
        VFSItem item = fileHandler.getItem(mediaReference);
        if (item instanceof JavaIOItem) {
            fileEl.setInitialFile(((JavaIOItem) item).getBasefile());
        }
    }
    categoriesEl = uifactory.addTextBoxListElement("categories", "categories", "categories.hint", categories, formLayout, getTranslator());
    categoriesEl.setHelpText(translate("categories.hint"));
    categoriesEl.setElementCssClass("o_sel_ep_tagsinput");
    categoriesEl.setAllowDuplicates(false);
    // String source = "Forum";
    // uifactory.addStaticTextElement("artefact.source", "artefact.source", source, formLayout);
    Date collectDate = mediaReference == null ? new Date() : mediaReference.getCollectionDate();
    String date = Formatter.getInstance(getLocale()).formatDate(collectDate);
    uifactory.addStaticTextElement("artefact.collect.date", "artefact.collect.date", date, formLayout);
    if (StringHelper.containsNonWhitespace(businessPath)) {
        String link = BusinessControlFactory.getInstance().getURLFromBusinessPathString(businessPath);
        uifactory.addStaticTextElement("artefact.collect.link", "artefact.collect.link", link, formLayout);
    }
    FormLayoutContainer buttonsCont = FormLayoutContainer.createButtonLayout("buttons", getTranslator());
    formLayout.add(buttonsCont);
    uifactory.addFormSubmitButton("save", "save", buttonsCont);
    uifactory.addFormCancelButton("cancel", buttonsCont, ureq, getWindowControl());
}
Also used : JavaIOItem(org.olat.core.util.vfs.JavaIOItem) VFSItem(org.olat.core.util.vfs.VFSItem) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) Date(java.util.Date)

Example 4 with JavaIOItem

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

the class VFSResource method getCreation.

@Override
public long getCreation() {
    try {
        if (item instanceof JavaIOItem) {
            JavaIOItem ioItem = (JavaIOItem) item;
            BasicFileAttributes attrs = Files.readAttributes(ioItem.getBasefile().toPath(), BasicFileAttributes.class);
            return attrs.creationTime().toMillis();
        }
        return 0;
    } catch (IOException e) {
        log.warn("getCreationFail" + item, e);
        return 0;
    }
}
Also used : JavaIOItem(org.olat.core.util.vfs.JavaIOItem) IOException(java.io.IOException) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes)

Example 5 with JavaIOItem

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

the class PowerPointOOXMLDocument method readContent.

@Override
public FileContent readContent(VFSLeaf leaf) throws IOException, DocumentException {
    File file = ((JavaIOItem) leaf).getBasefile();
    LimitedContentWriter writer = new LimitedContentWriter(100000, FileDocumentFactory.getMaxFileSize());
    try (ZipFile wordFile = new ZipFile(file)) {
        List<String> contents = new ArrayList<>();
        for (Enumeration<? extends ZipEntry> entriesEnumeration = wordFile.entries(); entriesEnumeration.hasMoreElements(); ) {
            ZipEntry entry = entriesEnumeration.nextElement();
            String name = entry.getName();
            if (name.startsWith(SLIDE) && name.endsWith(".xml")) {
                contents.add(name);
            }
        }
        if (contents.size() > 1) {
            Collections.sort(contents, new PowerPointDocumentComparator());
        }
        for (String content : contents) {
            if (writer.accept()) {
                ZipEntry entry = wordFile.getEntry(content);
                InputStream zip = wordFile.getInputStream(entry);
                OfficeDocumentHandler dh = new OfficeDocumentHandler(writer);
                parse(new ShieldInputStream(zip), dh);
                zip.close();
            }
        }
    } catch (DocumentException e) {
        throw e;
    } catch (Exception e) {
        throw new DocumentException(e.getMessage());
    }
    return new FileContent(writer.toString());
}
Also used : JavaIOItem(org.olat.core.util.vfs.JavaIOItem) ShieldInputStream(org.olat.core.util.io.ShieldInputStream) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) ArrayList(java.util.ArrayList) ShieldInputStream(org.olat.core.util.io.ShieldInputStream) IOException(java.io.IOException) LimitedContentWriter(org.olat.core.util.io.LimitedContentWriter) ZipFile(java.util.zip.ZipFile) File(java.io.File) ZipFile(java.util.zip.ZipFile)

Aggregations

JavaIOItem (org.olat.core.util.vfs.JavaIOItem)12 IOException (java.io.IOException)6 Date (java.util.Date)6 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)6 VFSItem (org.olat.core.util.vfs.VFSItem)6 File (java.io.File)4 InputStream (java.io.InputStream)4 ArrayList (java.util.ArrayList)4 ZipEntry (java.util.zip.ZipEntry)4 ZipFile (java.util.zip.ZipFile)4 LimitedContentWriter (org.olat.core.util.io.LimitedContentWriter)4 ShieldInputStream (org.olat.core.util.io.ShieldInputStream)4 BasicFileAttributes (java.nio.file.attribute.BasicFileAttributes)2