use of org.olat.core.util.io.ShieldOutputStream in project openolat by klemens.
the class QTI21WordExport method exportTest.
private void exportTest(AssessmentTest assessmentTest, String header, ZipOutputStream out, boolean withResponses) {
try (ShieldOutputStream sout = new ShieldOutputStream(out);
ZipOutputStream zout = new ZipOutputStream(sout)) {
zout.setLevel(9);
OpenXMLDocument document = new OpenXMLDocument();
document.setMediaContainer(mediaContainer);
document.setDocumentHeader(header);
Translator translator = Util.createPackageTranslator(AssessmentTestDisplayController.class, locale, Util.createPackageTranslator(AssessmentTestComposerController.class, locale));
renderAssessmentTest(assessmentTest, document, translator);
for (TestPart testPart : assessmentTest.getChildAbstractParts()) {
List<AssessmentSection> assessmentSections = testPart.getAssessmentSections();
for (AssessmentSection assessmentSection : assessmentSections) {
renderAssessmentSection(assessmentSection, document, withResponses, translator);
}
}
OpenXMLDocumentWriter writer = new OpenXMLDocumentWriter();
writer.createDocument(zout, document);
} catch (Exception e) {
log.error("", e);
}
}
use of org.olat.core.util.io.ShieldOutputStream in project openolat by klemens.
the class GroupBulkDownloadResource method prepare.
@Override
public void prepare(HttpServletResponse hres) {
try {
hres.setCharacterEncoding(encoding);
} catch (Exception e) {
log.error("", e);
}
String label = StringHelper.transformDisplayNameToFileSystemName(courseNode.getShortName()) + "_" + Formatter.formatDatetimeWithMinutes(new Date()) + ".zip";
String urlEncodedLabel = StringHelper.urlEncodeUTF8(label);
hres.setHeader("Content-Disposition", "attachment; filename*=UTF-8''" + urlEncodedLabel);
hres.setHeader("Content-Description", urlEncodedLabel);
try (ZipOutputStream zout = new ZipOutputStream(hres.getOutputStream())) {
zout.setLevel(9);
ICourse course = CourseFactory.loadCourse(courseOres);
GTAManager gtaManager = CoreSpringFactory.getImpl(GTAManager.class);
if (courseNode.getModuleConfiguration().getBooleanSafe(GTACourseNode.GTASK_GRADING)) {
List<Identity> assessableIdentities = CoreSpringFactory.getImpl(BusinessGroupService.class).getMembers(groups, GroupRoles.participant.name());
String courseTitle = course.getCourseTitle();
String fileName = ExportUtil.createFileNameWithTimeStamp(courseTitle, "xlsx");
List<AssessableCourseNode> nodes = Collections.<AssessableCourseNode>singletonList(courseNode);
try (OutputStream out = new ShieldOutputStream(zout)) {
zout.putNextEntry(new ZipEntry(fileName));
ScoreAccountingHelper.createCourseResultsOverviewXMLTable(assessableIdentities, nodes, course, locale, out);
zout.closeEntry();
} catch (Exception e) {
log.error("", e);
}
}
TaskList taskList = gtaManager.getTaskList(course.getCourseEnvironment().getCourseGroupManager().getCourseEntry(), courseNode);
for (BusinessGroup businessGroup : groups) {
courseNode.archiveNodeData(course, businessGroup, taskList, "", zout);
}
} catch (Exception e) {
log.error("", e);
}
}
use of org.olat.core.util.io.ShieldOutputStream in project openolat by klemens.
the class ForumDownloadResource method prepare.
@Override
public void prepare(HttpServletResponse hres) {
try {
hres.setCharacterEncoding("UTF-8");
} catch (Exception e) {
log.error("", e);
}
try (ZipOutputStream zout = new ZipOutputStream(hres.getOutputStream())) {
String secureLabel = StringHelper.transformDisplayNameToFileSystemName(label);
String file = secureLabel + ".zip";
hres.setHeader("Content-Disposition", "attachment; filename*=UTF-8''" + StringHelper.urlEncodeUTF8(file));
hres.setHeader("Content-Description", StringHelper.urlEncodeUTF8(label));
ZipEntry test = new ZipEntry(secureLabel + ".docx");
zout.putNextEntry(test);
Map<File, DocReference> attachments = exportForum(zout);
zout.closeEntry();
if (attachments != null && attachments.size() > 0) {
for (Map.Entry<File, DocReference> attachmentEntry : attachments.entrySet()) {
File attachment = attachmentEntry.getKey();
DocReference ref = attachmentEntry.getValue();
zout.putNextEntry(new ZipEntry("attachments/" + ref.getFilename()));
Files.copy(attachment.toPath(), new ShieldOutputStream(zout));
zout.closeEntry();
}
}
} catch (Exception e) {
log.error("", e);
}
}
use of org.olat.core.util.io.ShieldOutputStream in project openolat by klemens.
the class ExportBinderAsCPResource method prepare.
@Override
public void prepare(HttpServletResponse hres) {
try {
hres.setCharacterEncoding("UTF-8");
} catch (Exception e) {
log.error("", e);
}
try (ZipOutputStream zout = new ZipOutputStream(hres.getOutputStream())) {
Binder binder = portfolioService.getBinderByKey(binderRef.getKey());
String label = binder.getTitle();
String secureLabel = StringHelper.transformDisplayNameToFileSystemName(label);
String file = secureLabel + ".zip";
hres.setHeader("Content-Disposition", "attachment; filename*=UTF-8''" + StringHelper.urlEncodeUTF8(file));
hres.setHeader("Content-Description", StringHelper.urlEncodeUTF8(label));
// load pages
List<Section> sections = portfolioService.getSections(binder);
List<Page> pages = portfolioService.getPages(binder, null);
// manifest
ManifestType manifest = createImsManifest(binder, sections, pages);
zout.putNextEntry(new ZipEntry("imsmanifest.xml"));
write(manifest, new ShieldOutputStream(zout));
zout.closeEntry();
// write pages
for (Section section : sections) {
exportSection(section, zout);
}
// write pages
for (Page page : pages) {
exportPage(page, zout);
}
// theme and javascripts
exportCSSAndJs(zout);
// make it readable offline
ByteArrayOutputStream manifestOut = new ByteArrayOutputStream();
write(manifest, manifestOut);
String manifestXml = new String(manifestOut.toByteArray());
String indexSrc = sectionFilename(sections.get(0));
CPOfflineReadableManager.getInstance().makeCPOfflineReadable(manifestXml, indexSrc, zout);
} catch (Exception e) {
log.error("", e);
}
}
use of org.olat.core.util.io.ShieldOutputStream in project OpenOLAT by OpenOLAT.
the class QTI21ArchiveFormat method export.
public void export(String filename, ZipOutputStream exportStream) {
try (OutputStream out = new ShieldOutputStream(exportStream)) {
exportStream.putNextEntry(new ZipEntry(filename));
exportWorkbook(out);
exportStream.closeEntry();
} catch (IOException e) {
log.error("", e);
}
}
Aggregations