use of org.olat.core.util.io.ShieldInputStream in project openolat by klemens.
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 klemens.
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 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;
}
Aggregations