use of org.olat.core.util.io.ShieldInputStream in project OpenOLAT by OpenOLAT.
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 parseSheets.
private String parseSheets(Map<String, String> sharedStrings, VFSLeaf leaf) throws IOException, DocumentException {
try (InputStream stream = leaf.getInputStream();
ZipInputStream zip = new ZipInputStream(stream)) {
ZipEntry entry = zip.getNextEntry();
LimitedContentWriter writer = new LimitedContentWriter(100000, FileDocumentFactory.getMaxFileSize());
while (entry != null) {
if (writer.accept()) {
String name = entry.getName();
if (name.startsWith(SHEET) && name.endsWith(".xml")) {
OfficeDocumentHandler dh = new OfficeDocumentHandler(writer, sharedStrings);
parse(new ShieldInputStream(zip), dh);
}
}
entry = zip.getNextEntry();
}
return writer.toString();
} 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 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());
}
use of org.olat.core.util.io.ShieldInputStream in project OpenOLAT by OpenOLAT.
the class QTI21ImportProcessor method process.
public List<QuestionItem> process(File file) {
// export zip file
List<QuestionItem> items = new ArrayList<>();
try (FileSystem fs = FileSystems.newFileSystem(file.toPath(), null)) {
Path fPath = fs.getPath("/");
if (fPath != null) {
ImsManifestVisitor visitor = new ImsManifestVisitor();
Files.walkFileTree(fPath, visitor);
List<Path> imsmanifests = visitor.getImsmanifestFiles();
for (Path imsmanifest : imsmanifests) {
InputStream in = Files.newInputStream(imsmanifest);
ManifestBuilder manifestBuilder = ManifestBuilder.read(new ShieldInputStream(in));
List<ResourceType> resources = manifestBuilder.getResourceList();
for (ResourceType resource : resources) {
ManifestMetadataBuilder metadataBuilder = manifestBuilder.getMetadataBuilder(resource, true);
QuestionItem qitem = processResource(resource, imsmanifest, metadataBuilder);
if (qitem != null) {
items.add(qitem);
}
}
}
}
} catch (IOException e) {
log.error("", e);
}
return items;
}
use of org.olat.core.util.io.ShieldInputStream in project openolat by klemens.
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