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());
}
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());
}
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());
}
Aggregations