Search in sources :

Example 6 with ShieldOutputStream

use of org.olat.core.util.io.ShieldOutputStream in project OpenOLAT by OpenOLAT.

the class RepositoryEntryImportExport method exportDoExportProperties.

public void exportDoExportProperties(ZipOutputStream zout) throws IOException {
    RepositoryEntryImport imp = new RepositoryEntryImport(re);
    RepositoryManager rm = RepositoryManager.getInstance();
    VFSLeaf image = rm.getImage(re);
    if (image != null) {
        imp.setImageName(image.getName());
        zout.putNextEntry(new ZipEntry(image.getName()));
        try (InputStream inImage = image.getInputStream()) {
            FileUtils.copy(inImage, new ShieldOutputStream(zout));
        } catch (Exception e) {
            log.error("", e);
        }
        zout.closeEntry();
    }
    RepositoryService repositoryService = CoreSpringFactory.getImpl(RepositoryService.class);
    VFSLeaf movie = repositoryService.getIntroductionMovie(re);
    if (movie != null) {
        imp.setMovieName(movie.getName());
        zout.putNextEntry(new ZipEntry(movie.getName()));
        try (InputStream inMovie = movie.getInputStream()) {
            FileUtils.copy(inMovie, new ShieldOutputStream(zout));
        } catch (Exception e) {
            log.error("", e);
        }
        zout.closeEntry();
    }
    zout.putNextEntry(new ZipEntry(PROPERTIES_FILE));
    getXStream().toXML(imp, new ShieldOutputStream(zout));
    zout.closeEntry();
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) ShieldOutputStream(org.olat.core.util.io.ShieldOutputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) IOException(java.io.IOException)

Example 7 with ShieldOutputStream

use of org.olat.core.util.io.ShieldOutputStream in project OpenOLAT by OpenOLAT.

the class ScoreAccountingHelper method createCourseResultsOverview.

public static void createCourseResultsOverview(List<Identity> identities, List<AssessableCourseNode> nodes, ICourse course, Locale locale, ZipOutputStream zout) {
    try (OutputStream out = new ShieldOutputStream(zout)) {
        zout.putNextEntry(new ZipEntry("Course_results.xlsx"));
        createCourseResultsOverviewXMLTable(identities, nodes, course, locale, out);
        zout.closeEntry();
    } catch (IOException e) {
        log.error("", e);
    }
    for (AssessableCourseNode node : nodes) {
        String dir = "Assessment_documents/" + StringHelper.transformDisplayNameToFileSystemName(node.getShortName());
        if (node instanceof IQTESTCourseNode || node.getModuleConfiguration().getBooleanSafe(MSCourseNode.CONFIG_KEY_HAS_INDIVIDUAL_ASSESSMENT_DOCS, false)) {
            for (Identity assessedIdentity : identities) {
                List<File> assessmentDocuments = course.getCourseEnvironment().getAssessmentManager().getIndividualAssessmentDocuments(node, assessedIdentity);
                if (assessmentDocuments != null && !assessmentDocuments.isEmpty()) {
                    String name = assessedIdentity.getUser().getLastName() + "_" + assessedIdentity.getUser().getFirstName() + "_" + assessedIdentity.getName();
                    String userDirName = dir + "/" + StringHelper.transformDisplayNameToFileSystemName(name);
                    for (File document : assessmentDocuments) {
                        String path = userDirName + "/" + document.getName();
                        ZipUtil.addFileToZip(path, document, zout);
                    }
                }
            }
        }
    }
}
Also used : AssessableCourseNode(org.olat.course.nodes.AssessableCourseNode) IQTESTCourseNode(org.olat.course.nodes.IQTESTCourseNode) 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) Identity(org.olat.core.id.Identity) File(java.io.File)

Example 8 with ShieldOutputStream

use of org.olat.core.util.io.ShieldOutputStream in project openolat by klemens.

the class CheckListExcelExport method exportAll.

public void exportAll(String filename, ZipOutputStream exportStream) {
    List<AssessmentData> dataList = checkboxManager.getAssessmentDatas(course, courseNode.getIdent(), null, null);
    try (OutputStream out = new ShieldOutputStream(exportStream)) {
        exportStream.putNextEntry(new ZipEntry(filename + ".xlsx"));
        exportWorkbook(dataList, out);
        exportStream.closeEntry();
    } catch (IOException e) {
        log.error("", e);
    }
}
Also used : AssessmentData(org.olat.course.nodes.cl.model.AssessmentData) ShieldOutputStream(org.olat.core.util.io.ShieldOutputStream) ZipOutputStream(java.util.zip.ZipOutputStream) OutputStream(java.io.OutputStream) ShieldOutputStream(org.olat.core.util.io.ShieldOutputStream) ZipEntry(java.util.zip.ZipEntry) IOException(java.io.IOException)

Example 9 with ShieldOutputStream

use of org.olat.core.util.io.ShieldOutputStream in project openolat by klemens.

the class QTI21ExportProcessor method process.

public void process(QuestionItemFull qitem, ZipOutputStream zout) {
    String dir = qitem.getDirectory();
    File rootDirectory = qpoolFileStorage.getDirectory(dir);
    String rootDir = "qitem_" + qitem.getKey();
    File imsmanifest = new File(rootDirectory, "imsmanifest.xml");
    ManifestBuilder manifestBuilder;
    if (imsmanifest.exists()) {
        manifestBuilder = ManifestBuilder.read(imsmanifest);
    } else {
        manifestBuilder = new ManifestBuilder();
    }
    File resourceFile = new File(rootDirectory, qitem.getRootFilename());
    URI assessmentItemUri = resourceFile.toURI();
    ResolvedAssessmentItem resolvedAssessmentItem = qtiService.loadAndResolveAssessmentItemForCopy(assessmentItemUri, rootDirectory);
    enrichWithMetadata(qitem, resolvedAssessmentItem, manifestBuilder);
    try {
        zout.putNextEntry(new ZipEntry(rootDir + "/imsmanifest.xml"));
        manifestBuilder.write(new ShieldOutputStream(zout));
        zout.closeEntry();
    } catch (Exception e) {
        log.error("", e);
    }
    try {
        Files.walkFileTree(rootDirectory.toPath(), new SimpleFileVisitor<Path>() {

            @Override
            public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
                String filename = file.getFileName().toString();
                if (!"imsmanifest.xml".equals(filename) && !filename.startsWith(".")) {
                    String relPath = rootDirectory.toPath().relativize(file).toString();
                    ZipUtil.addFileToZip(rootDir + "/" + relPath, file, zout);
                }
                return FileVisitResult.CONTINUE;
            }
        });
    } catch (IOException e) {
        log.error("", e);
    }
}
Also used : Path(java.nio.file.Path) ManifestBuilder(org.olat.ims.qti21.model.xml.ManifestBuilder) ZipEntry(java.util.zip.ZipEntry) FileVisitResult(java.nio.file.FileVisitResult) IOException(java.io.IOException) URI(java.net.URI) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) ShieldOutputStream(org.olat.core.util.io.ShieldOutputStream) ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) File(java.io.File) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes)

Example 10 with ShieldOutputStream

use of org.olat.core.util.io.ShieldOutputStream in project openolat by klemens.

the class RepositoryEntryImportExport method exportDoExportProperties.

public void exportDoExportProperties(ZipOutputStream zout) throws IOException {
    RepositoryEntryImport imp = new RepositoryEntryImport(re);
    RepositoryManager rm = RepositoryManager.getInstance();
    VFSLeaf image = rm.getImage(re);
    if (image != null) {
        imp.setImageName(image.getName());
        zout.putNextEntry(new ZipEntry(image.getName()));
        try (InputStream inImage = image.getInputStream()) {
            FileUtils.copy(inImage, new ShieldOutputStream(zout));
        } catch (Exception e) {
            log.error("", e);
        }
        zout.closeEntry();
    }
    RepositoryService repositoryService = CoreSpringFactory.getImpl(RepositoryService.class);
    VFSLeaf movie = repositoryService.getIntroductionMovie(re);
    if (movie != null) {
        imp.setMovieName(movie.getName());
        zout.putNextEntry(new ZipEntry(movie.getName()));
        try (InputStream inMovie = movie.getInputStream()) {
            FileUtils.copy(inMovie, new ShieldOutputStream(zout));
        } catch (Exception e) {
            log.error("", e);
        }
        zout.closeEntry();
    }
    zout.putNextEntry(new ZipEntry(PROPERTIES_FILE));
    getXStream().toXML(imp, new ShieldOutputStream(zout));
    zout.closeEntry();
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) ShieldOutputStream(org.olat.core.util.io.ShieldOutputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) 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