use of org.olat.core.util.io.ShieldInputStream in project OpenOLAT by OpenOLAT.
the class ItemFileResourceValidator method validate.
public boolean validate(String filename, InputStream in) {
boolean valid = false;
if (filename.toLowerCase().endsWith(".xml")) {
valid = validateXml(in);
IOUtils.closeQuietly(in);
} else if (filename.toLowerCase().endsWith(".zip")) {
ZipInputStream oZip = new ZipInputStream(in);
try {
ZipEntry oEntr = oZip.getNextEntry();
while (oEntr != null) {
if (!oEntr.isDirectory()) {
if (validateXml(new ShieldInputStream(oZip))) {
valid = true;
}
}
oZip.closeEntry();
oEntr = oZip.getNextEntry();
}
} catch (Exception e) {
log.error("", e);
valid = false;
} finally {
IOUtils.closeQuietly(oZip);
IOUtils.closeQuietly(in);
}
}
return valid;
}
use of org.olat.core.util.io.ShieldInputStream in project OpenOLAT by OpenOLAT.
the class AssessmentItemFileResourceValidator method walkZip.
private boolean walkZip(ZipInputStream oZip) {
boolean valid = false;
try {
ZipEntry oEntr = oZip.getNextEntry();
while (oEntr != null) {
if (!oEntr.isDirectory()) {
String fname = oEntr.getName().toLowerCase();
if (!"imsmanifest.xml".equals(fname) && fname.endsWith(".xml")) {
if (validateXml(new ShieldInputStream(oZip))) {
valid = true;
}
} else if (fname.endsWith(".zip")) {
ZipInputStream subZip = new ZipInputStream(new ShieldInputStream(oZip));
valid |= walkZip(subZip);
}
}
oZip.closeEntry();
oEntr = oZip.getNextEntry();
}
} catch (Exception e) {
log.error("", e);
valid = false;
}
return valid;
}
use of org.olat.core.util.io.ShieldInputStream in project openolat by klemens.
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 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.ShieldInputStream 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