use of org.olat.core.util.io.ShieldInputStream in project openolat by klemens.
the class ExcelOOXMLDocument method parseSharedStrings.
private Map<String, String> parseSharedStrings(VFSLeaf leaf) throws IOException, DocumentException {
SharedStringsHandler dh = new SharedStringsHandler();
try (InputStream stream = leaf.getInputStream();
ZipInputStream zip = new ZipInputStream(stream)) {
ZipEntry entry = zip.getNextEntry();
while (entry != null) {
String name = entry.getName();
if (name.endsWith("xl/sharedStrings.xml")) {
parse(new ShieldInputStream(zip), dh);
break;
}
entry = zip.getNextEntry();
}
return dh.getMap();
} catch (DocumentException e) {
throw e;
} catch (Exception e) {
throw new DocumentException(e.getMessage());
}
}
use of org.olat.core.util.io.ShieldInputStream in project openolat by klemens.
the class OpenDocument method readContent.
public FileContent readContent(VFSLeaf leaf) throws DocumentException {
final OpenDocumentHandler dh = new OpenDocumentHandler();
InputStream stream = null;
ZipInputStream zip = null;
try {
stream = leaf.getInputStream();
zip = new ZipInputStream(stream);
ZipEntry entry = zip.getNextEntry();
while (entry != null) {
if (entry.getName().endsWith("content.xml")) {
parse(new ShieldInputStream(zip), dh);
// we parsed only content
break;
}
entry = zip.getNextEntry();
}
} catch (DocumentException e) {
throw e;
} catch (Exception e) {
throw new DocumentException(e.getMessage());
} finally {
FileUtils.closeSafely(zip);
FileUtils.closeSafely(stream);
}
return new FileContent(dh.getContent());
}
use of org.olat.core.util.io.ShieldInputStream in project OpenOLAT by OpenOLAT.
the class ExcelOOXMLDocument method parseSharedStrings.
private Map<String, String> parseSharedStrings(VFSLeaf leaf) throws IOException, DocumentException {
SharedStringsHandler dh = new SharedStringsHandler();
try (InputStream stream = leaf.getInputStream();
ZipInputStream zip = new ZipInputStream(stream)) {
ZipEntry entry = zip.getNextEntry();
while (entry != null) {
String name = entry.getName();
if (name.endsWith("xl/sharedStrings.xml")) {
parse(new ShieldInputStream(zip), dh);
break;
}
entry = zip.getNextEntry();
}
return dh.getMap();
} catch (DocumentException e) {
throw e;
} catch (Exception e) {
throw new DocumentException(e.getMessage());
}
}
use of org.olat.core.util.io.ShieldInputStream 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());
}
use of org.olat.core.util.io.ShieldInputStream in project OpenOLAT by OpenOLAT.
the class OpenXMLDocument method convertLaTeX.
public List<Node> convertLaTeX(String latex) {
List<Node> mathEls = new ArrayList<Node>();
try {
// convert latex -> mathml
String mathml = ConvertFromLatexToMathML.convertToMathML(latex);
// convert mathml to word docx
ByteArrayOutputStream out = new ByteArrayOutputStream(20000);
ConvertFromMathMLToWord.writeWordDocStreamFromMathML(out, mathml);
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
out = null;
// extract docx
ZipInputStream zip = new ZipInputStream(in);
ZipEntry entry = zip.getNextEntry();
while (entry != null) {
String name = entry.getName();
if (name.endsWith("word/document.xml")) {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setValidating(false);
factory.setNamespaceAware(false);
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(new ShieldInputStream(zip));
NodeList bodyList = doc.getElementsByTagName("w:body");
if (bodyList.getLength() == 1) {
Node body = bodyList.item(0);
for (Node node = body.getFirstChild(); node != null; node = node.getNextSibling()) {
Node importedNode = document.importNode(node, true);
mathEls.add(importedNode);
}
}
}
entry = zip.getNextEntry();
}
} catch (Exception e) {
log.error("", e);
}
return mathEls;
}
Aggregations