use of org.olat.core.util.openxml.DocReference 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.openxml.DocReference 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.openxml.DocReference in project OpenOLAT by OpenOLAT.
the class ForumOpenXMLFormatter method processAttachments.
private void processAttachments(VFSContainer attachmentsContainer) {
List<VFSItem> attachments = new ArrayList<VFSItem>(attachmentsContainer.getItems(filter));
for (VFSItem attachment : attachments) {
if (attachment instanceof LocalFileImpl) {
// add the text
document.appendText(translator.translate("attachments"), true, Style.bold);
}
}
for (VFSItem attachment : attachments) {
if (attachment instanceof LocalFileImpl) {
File file = ((LocalFileImpl) attachment).getBasefile();
String filename = file.getName();
int lastDot = filename.lastIndexOf('.');
boolean attach = true;
if (lastDot > 0) {
String extension = filename.substring(lastDot + 1).toLowerCase();
if ("jpeg".equals(extension) || "jpg".equals(extension) || "gif".equals(extension) || "png".equals(extension)) {
document.appendImage(file);
attach = false;
}
}
if (attach) {
StringBuilder attachSb = new StringBuilder(64);
String uniqueFilename = getUniqueFilename(file);
fileToAttachmentsMap.put(file, new DocReference("", uniqueFilename, null, file));
attachSb.append(filename).append(": /attachments/").append(uniqueFilename);
document.appendText(attachSb.toString(), true);
}
}
}
}
use of org.olat.core.util.openxml.DocReference in project openolat by klemens.
the class ForumOpenXMLFormatter method processAttachments.
private void processAttachments(VFSContainer attachmentsContainer) {
List<VFSItem> attachments = new ArrayList<VFSItem>(attachmentsContainer.getItems(filter));
for (VFSItem attachment : attachments) {
if (attachment instanceof LocalFileImpl) {
// add the text
document.appendText(translator.translate("attachments"), true, Style.bold);
}
}
for (VFSItem attachment : attachments) {
if (attachment instanceof LocalFileImpl) {
File file = ((LocalFileImpl) attachment).getBasefile();
String filename = file.getName();
int lastDot = filename.lastIndexOf('.');
boolean attach = true;
if (lastDot > 0) {
String extension = filename.substring(lastDot + 1).toLowerCase();
if ("jpeg".equals(extension) || "jpg".equals(extension) || "gif".equals(extension) || "png".equals(extension)) {
document.appendImage(file);
attach = false;
}
}
if (attach) {
StringBuilder attachSb = new StringBuilder(64);
String uniqueFilename = getUniqueFilename(file);
fileToAttachmentsMap.put(file, new DocReference("", uniqueFilename, null, file));
attachSb.append(filename).append(": /attachments/").append(uniqueFilename);
document.appendText(attachSb.toString(), true);
}
}
}
}
Aggregations