Search in sources :

Example 16 with LimitedContentWriter

use of org.olat.core.util.io.LimitedContentWriter in project openolat by klemens.

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)

Example 17 with LimitedContentWriter

use of org.olat.core.util.io.LimitedContentWriter in project openolat by klemens.

the class TextDocument method readContent.

@Override
protected FileContent readContent(VFSLeaf leaf) throws IOException {
    InputStreamReader in = new InputStreamReader(leaf.getInputStream());
    LimitedContentWriter out = new LimitedContentWriter((int) leaf.getSize(), FileDocumentFactory.getMaxFileSize());
    try {
        copy(in, out);
    } catch (Exception e) {
        log.error("", e);
    }
    return new FileContent(out.toString());
}
Also used : LimitedContentWriter(org.olat.core.util.io.LimitedContentWriter) InputStreamReader(java.io.InputStreamReader) IOException(java.io.IOException)

Example 18 with LimitedContentWriter

use of org.olat.core.util.io.LimitedContentWriter in project openolat by klemens.

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)

Aggregations

IOException (java.io.IOException)18 LimitedContentWriter (org.olat.core.util.io.LimitedContentWriter)18 BufferedInputStream (java.io.BufferedInputStream)8 InputStream (java.io.InputStream)8 ZipEntry (java.util.zip.ZipEntry)6 ShieldInputStream (org.olat.core.util.io.ShieldInputStream)6 File (java.io.File)4 ArrayList (java.util.ArrayList)4 ZipFile (java.util.zip.ZipFile)4 POIFSFileSystem (org.apache.poi.poifs.filesystem.POIFSFileSystem)4 JavaIOItem (org.olat.core.util.vfs.JavaIOItem)4 BufferedReader (java.io.BufferedReader)2 FileReader (java.io.FileReader)2 InputStreamReader (java.io.InputStreamReader)2 ZipInputStream (java.util.zip.ZipInputStream)2 PDDocument (org.apache.pdfbox.pdmodel.PDDocument)2 PDFTextStripper (org.apache.pdfbox.util.PDFTextStripper)2 HSSFCell (org.apache.poi.hssf.usermodel.HSSFCell)2 HSSFRow (org.apache.poi.hssf.usermodel.HSSFRow)2 HSSFSheet (org.apache.poi.hssf.usermodel.HSSFSheet)2