use of org.olat.core.util.io.ShieldOutputStream in project OpenOLAT by OpenOLAT.
the class BinderTemplateMediaResource 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())) {
PortfolioService portfolioService = CoreSpringFactory.getImpl(PortfolioService.class);
Binder loadedTemplate = portfolioService.getBinderByKey(template.getKey());
String label = loadedTemplate.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));
zout.setLevel(9);
zout.putNextEntry(new ZipEntry("binder.xml"));
BinderXStream.toStream(loadedTemplate, zout);
zout.closeEntry();
if (StringHelper.containsNonWhitespace(loadedTemplate.getImagePath())) {
File posterImage = portfolioService.getPosterImageFile(loadedTemplate);
if (posterImage.exists()) {
zout.putNextEntry(new ZipEntry(loadedTemplate.getImagePath()));
FileUtils.copyFile(posterImage, new ShieldOutputStream(zout));
zout.closeEntry();
}
}
OLATResource resource = templateEntry.getOlatResource();
File baseContainer = FileResourceManager.getInstance().getFileResource(resource);
RepositoryEntryImportExport importExport = new RepositoryEntryImportExport(templateEntry, baseContainer);
importExport.exportDoExportProperties(zout);
} catch (Exception e) {
log.error("", e);
}
}
use of org.olat.core.util.io.ShieldOutputStream in project OpenOLAT by OpenOLAT.
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);
}
}
use of org.olat.core.util.io.ShieldOutputStream in project OpenOLAT by OpenOLAT.
the class TACourseNode method archiveNodeData.
@Override
public boolean archiveNodeData(Locale locale, ICourse course, ArchiveOptions options, ZipOutputStream exportStream, String charset) {
boolean dataFound = false;
String dropboxPath = DropboxController.getDropboxPathRelToFolderRoot(course.getCourseEnvironment(), this);
OlatRootFolderImpl dropboxDir = new OlatRootFolderImpl(dropboxPath, null);
String solutionsPath = TACourseNode.getFoldernodesPathRelToFolderBase(course.getCourseEnvironment()) + "/" + this.getIdent();
OlatRootFolderImpl solutionDir = new OlatRootFolderImpl(solutionsPath, null);
String returnboxPath = ReturnboxController.getReturnboxPathRelToFolderRoot(course.getCourseEnvironment(), this);
OlatRootFolderImpl returnboxDir = new OlatRootFolderImpl(returnboxPath, null);
Boolean hasTask = (Boolean) getModuleConfiguration().get(TACourseNode.CONF_TASK_ENABLED);
String dirName = "task_" + StringHelper.transformDisplayNameToFileSystemName(getShortName()) + "_" + Formatter.formatDatetimeFilesystemSave(new Date(System.currentTimeMillis()));
if (dropboxDir.exists() || solutionDir.exists() || returnboxDir.exists() || hasTask.booleanValue()) {
// prepare writing course results overview table
List<Identity> users = ScoreAccountingHelper.loadUsers(course.getCourseEnvironment(), options);
Set<String> dropboxNames = null;
if (options != null && (options.getGroup() != null || options.getIdentities() != null)) {
dropboxNames = new HashSet<String>();
for (Identity user : users) {
dropboxNames.add(user.getName());
}
}
String courseTitle = course.getCourseTitle();
String fileName = ExportUtil.createFileNameWithTimeStamp(courseTitle, "xlsx");
List<AssessableCourseNode> nodes = Collections.<AssessableCourseNode>singletonList(this);
// write course results overview table to filesystem
try (OutputStream out = new ShieldOutputStream(exportStream)) {
exportStream.putNextEntry(new ZipEntry(dirName + "/" + fileName));
ScoreAccountingHelper.createCourseResultsOverviewXMLTable(users, nodes, course, locale, out);
exportStream.closeEntry();
} catch (IOException e) {
log.error("", e);
}
// copy solutions to tmp dir
if (solutionDir.exists()) {
for (VFSItem child : solutionDir.getItems()) {
dataFound = true;
ZipUtil.addToZip(child, dirName + "/solutions", exportStream);
}
}
// copy dropboxes to tmp dir
if (dropboxDir.exists()) {
// OLAT-6362 archive only dropboxes of users that handed in at least one file -> prevent empty folders in archive
List<VFSItem> dropBoxContent = dropboxDir.getItems();
for (VFSItem file : dropBoxContent) {
if ((dropboxNames == null || dropboxNames.contains(file.getName())) && VFSManager.isDirectoryAndNotEmpty(file)) {
dataFound = true;
ZipUtil.addToZip(file, dirName + "/dropboxes", exportStream);
}
}
}
// copy only the choosen task to user taskfolder, loop over all users
String taskfolderPath = TACourseNode.getTaskFolderPathRelToFolderRoot(course.getCourseEnvironment(), this);
OlatRootFolderImpl taskfolderDir = new OlatRootFolderImpl(taskfolderPath, null);
for (Identity identity : users) {
// check if user already chose a task
String assignedTask = TaskController.getAssignedTask(identity, course.getCourseEnvironment(), this);
if (assignedTask != null) {
VFSItem item = taskfolderDir.resolve(assignedTask);
if (item != null) {
// copy choosen task to user folder
ZipUtil.addToZip(item, dirName + "/taskfolders/" + identity.getName(), exportStream);
dataFound = true;
}
}
}
// copy returnboxes
if (returnboxDir.exists()) {
// OLAT-6362 archive only existing returnboxes -> prevent empty folders in archive
List<VFSItem> returnBoxContent = returnboxDir.getItems();
for (VFSItem file : returnBoxContent) {
if ((dropboxNames == null || dropboxNames.contains(file.getName())) && VFSManager.isDirectoryAndNotEmpty(file)) {
dataFound = true;
ZipUtil.addToZip(file, dirName + "/returnboxes", exportStream);
}
}
}
// assessment documents
if (getModuleConfiguration().getBooleanSafe(MSCourseNode.CONFIG_KEY_HAS_INDIVIDUAL_ASSESSMENT_DOCS, false)) {
for (Identity assessedIdentity : users) {
List<File> assessmentDocuments = course.getCourseEnvironment().getAssessmentManager().getIndividualAssessmentDocuments(this, assessedIdentity);
if (assessmentDocuments != null && !assessmentDocuments.isEmpty()) {
for (File document : assessmentDocuments) {
String path = dirName + "/assessment_documents/" + assessedIdentity.getName() + "/" + document.getName();
ZipUtil.addFileToZip(path, document, exportStream);
}
}
}
}
}
return dataFound;
}
use of org.olat.core.util.io.ShieldOutputStream in project OpenOLAT by OpenOLAT.
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);
}
}
use of org.olat.core.util.io.ShieldOutputStream in project OpenOLAT by OpenOLAT.
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);
}
}
Aggregations