Search in sources :

Example 11 with ShieldOutputStream

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);
    }
}
Also used : OpenXMLDocumentWriter(org.olat.core.util.openxml.OpenXMLDocumentWriter) ShieldOutputStream(org.olat.core.util.io.ShieldOutputStream) Translator(org.olat.core.gui.translator.Translator) ZipOutputStream(java.util.zip.ZipOutputStream) AssessmentSection(uk.ac.ed.ph.jqtiplus.node.test.AssessmentSection) TestPart(uk.ac.ed.ph.jqtiplus.node.test.TestPart) OpenXMLDocument(org.olat.core.util.openxml.OpenXMLDocument) AssessmentTestComposerController(org.olat.ims.qti21.ui.editor.AssessmentTestComposerController) SAXException(org.xml.sax.SAXException) IOException(java.io.IOException)

Example 12 with ShieldOutputStream

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);
    }
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) ZipOutputStream(java.util.zip.ZipOutputStream) OutputStream(java.io.OutputStream) ShieldOutputStream(org.olat.core.util.io.ShieldOutputStream) ZipEntry(java.util.zip.ZipEntry) TaskList(org.olat.course.nodes.gta.TaskList) ICourse(org.olat.course.ICourse) Date(java.util.Date) AssessableCourseNode(org.olat.course.nodes.AssessableCourseNode) ShieldOutputStream(org.olat.core.util.io.ShieldOutputStream) BusinessGroupService(org.olat.group.BusinessGroupService) ZipOutputStream(java.util.zip.ZipOutputStream) GTAManager(org.olat.course.nodes.gta.GTAManager) Identity(org.olat.core.id.Identity)

Example 13 with ShieldOutputStream

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);
    }
}
Also used : ShieldOutputStream(org.olat.core.util.io.ShieldOutputStream) ZipOutputStream(java.util.zip.ZipOutputStream) ZipEntry(java.util.zip.ZipEntry) File(java.io.File) Map(java.util.Map) DocReference(org.olat.core.util.openxml.DocReference)

Example 14 with ShieldOutputStream

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);
    }
}
Also used : Binder(org.olat.modules.portfolio.Binder) ManifestType(org.olat.imscp.xml.manifest.ManifestType) ShieldOutputStream(org.olat.core.util.io.ShieldOutputStream) ZipOutputStream(java.util.zip.ZipOutputStream) ZipEntry(java.util.zip.ZipEntry) Page(org.olat.modules.portfolio.Page) ByteArrayOutputStream(java.io.ByteArrayOutputStream) AssessmentSection(org.olat.modules.portfolio.AssessmentSection) Section(org.olat.modules.portfolio.Section) JAXBException(javax.xml.bind.JAXBException) SAXException(org.xml.sax.SAXException) IOException(java.io.IOException)

Example 15 with ShieldOutputStream

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);
    }
}
Also used : ShieldOutputStream(org.olat.core.util.io.ShieldOutputStream) ShieldOutputStream(org.olat.core.util.io.ShieldOutputStream) ZipOutputStream(java.util.zip.ZipOutputStream) OutputStream(java.io.OutputStream) ZipEntry(java.util.zip.ZipEntry) IOException(java.io.IOException)

Aggregations

ShieldOutputStream (org.olat.core.util.io.ShieldOutputStream)26 ZipEntry (java.util.zip.ZipEntry)24 ZipOutputStream (java.util.zip.ZipOutputStream)20 IOException (java.io.IOException)18 File (java.io.File)12 OutputStream (java.io.OutputStream)12 Identity (org.olat.core.id.Identity)8 Date (java.util.Date)6 URISyntaxException (java.net.URISyntaxException)4 FileVisitResult (java.nio.file.FileVisitResult)4 Path (java.nio.file.Path)4 BasicFileAttributes (java.nio.file.attribute.BasicFileAttributes)4 OLATRuntimeException (org.olat.core.logging.OLATRuntimeException)4 AssessableCourseNode (org.olat.course.nodes.AssessableCourseNode)4 GTAManager (org.olat.course.nodes.gta.GTAManager)4 TaskList (org.olat.course.nodes.gta.TaskList)4 BusinessGroup (org.olat.group.BusinessGroup)4 ManifestBuilder (org.olat.ims.qti21.model.xml.ManifestBuilder)4 Binder (org.olat.modules.portfolio.Binder)4 SAXException (org.xml.sax.SAXException)4