use of org.olat.core.util.io.ShieldOutputStream in project OpenOLAT by OpenOLAT.
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 OpenOLAT.
the class GTACourseNode method archiveNodeData.
@Override
public boolean archiveNodeData(Locale locale, ICourse course, ArchiveOptions options, ZipOutputStream exportStream, String charset) {
final GTAManager gtaManager = CoreSpringFactory.getImpl(GTAManager.class);
final ModuleConfiguration config = getModuleConfiguration();
String prefix;
if (GTAType.group.name().equals(config.getStringValue(GTACourseNode.GTASK_TYPE))) {
prefix = "grouptask_";
} else {
prefix = "ita_";
}
String dirName = prefix + StringHelper.transformDisplayNameToFileSystemName(getShortName()) + "_" + Formatter.formatDatetimeFilesystemSave(new Date(System.currentTimeMillis()));
TaskList taskList = gtaManager.getTaskList(course.getCourseEnvironment().getCourseGroupManager().getCourseEntry(), this);
// save assessment datas
List<Identity> users = null;
if (config.getBooleanSafe(GTASK_GRADING)) {
users = ScoreAccountingHelper.loadUsers(course.getCourseEnvironment(), options);
String courseTitle = course.getCourseTitle();
String fileName = ExportUtil.createFileNameWithTimeStamp(courseTitle, "xlsx");
List<AssessableCourseNode> nodes = Collections.<AssessableCourseNode>singletonList(this);
try (OutputStream out = new ShieldOutputStream(exportStream)) {
exportStream.putNextEntry(new ZipEntry(dirName + "/" + fileName));
ScoreAccountingHelper.createCourseResultsOverviewXMLTable(users, nodes, course, locale, out);
exportStream.closeEntry();
} catch (Exception e) {
log.error("", e);
}
}
// copy tasks
if (taskList != null) {
if (GTAType.group.name().equals(config.getStringValue(GTACourseNode.GTASK_TYPE))) {
List<BusinessGroup> selectedGroups;
if (options != null && options.getGroup() != null) {
selectedGroups = Collections.singletonList(options.getGroup());
} else {
selectedGroups = gtaManager.getBusinessGroups(this);
}
for (BusinessGroup businessGroup : selectedGroups) {
archiveNodeData(course, businessGroup, taskList, dirName, exportStream);
}
} else {
if (users == null) {
users = ScoreAccountingHelper.loadUsers(course.getCourseEnvironment(), options);
}
Set<Identity> uniqueUsers = new HashSet<>(users);
for (Identity user : uniqueUsers) {
archiveNodeData(course, user, taskList, dirName, exportStream);
}
}
}
// copy solutions
if (config.getBooleanSafe(GTACourseNode.GTASK_SAMPLE_SOLUTION)) {
VFSContainer solutions = gtaManager.getSolutionsContainer(course.getCourseEnvironment(), this);
if (solutions.exists()) {
String solutionDirName = dirName + "/solutions";
for (VFSItem solution : solutions.getItems(new SystemItemFilter())) {
ZipUtil.addToZip(solution, solutionDirName, exportStream);
}
}
}
return true;
}
use of org.olat.core.util.io.ShieldOutputStream in project OpenOLAT by OpenOLAT.
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 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 OpenOLAT.
the class QTI21ExportProcessor method assembleTest.
public void assembleTest(List<QuestionItemFull> fullItems, ZipOutputStream zout) {
try {
QtiSerializer qtiSerializer = qtiService.qtiSerializer();
// imsmanifest
ManifestBuilder manifest = ManifestBuilder.createAssessmentTestBuilder();
// assessment test
AssessmentTest assessmentTest = AssessmentTestFactory.createAssessmentTest("Assessment test from pool", "Section");
String assessmentTestFilename = assessmentTest.getIdentifier() + ".xml";
manifest.appendAssessmentTest(assessmentTestFilename);
// make a section
AssessmentSection section = assessmentTest.getTestParts().get(0).getAssessmentSections().get(0);
// assessment items
for (QuestionItemFull qitem : fullItems) {
File resourceDirectory = qpoolFileStorage.getDirectory(qitem.getDirectory());
File itemFile = new File(resourceDirectory, qitem.getRootFilename());
String itemFilename = itemFile.getName();
String container = qitem.getKey().toString();
String containedFilename = container + "/" + itemFilename;
ResolvedAssessmentItem resolvedAssessmentItem = qtiService.loadAndResolveAssessmentItemForCopy(itemFile.toURI(), resourceDirectory);
ZipUtil.addFileToZip(containedFilename, itemFile, zout);
AssessmentTestFactory.appendAssessmentItem(section, containedFilename);
manifest.appendAssessmentItem(containedFilename);
ManifestMetadataBuilder metadata = manifest.getResourceBuilderByHref(containedFilename);
metadata.appendMetadataFrom(qitem, resolvedAssessmentItem, locale);
// write materials
try {
Files.walkFileTree(resourceDirectory.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(".") && !itemFilename.equals(filename)) {
String relPath = resourceDirectory.toPath().relativize(file).toString();
ZipUtil.addFileToZip(container + "/" + relPath, file, zout);
}
return FileVisitResult.CONTINUE;
}
});
} catch (IOException e) {
log.error("", e);
}
}
zout.putNextEntry(new ZipEntry(assessmentTestFilename));
qtiSerializer.serializeJqtiObject(assessmentTest, new ShieldOutputStream(zout));
zout.closeEntry();
zout.putNextEntry(new ZipEntry("imsmanifest.xml"));
manifest.write(new ShieldOutputStream(zout));
zout.closeEntry();
} catch (IOException | URISyntaxException e) {
log.error("", e);
}
}
Aggregations