use of org.olat.core.util.vfs.VFSItem in project OpenOLAT by OpenOLAT.
the class MessageListController method doDeliverAttachment.
private void doDeliverAttachment(UserRequest ureq, String cmd) {
MediaResource res = null;
try {
int index = cmd.lastIndexOf("_");
String attachmentPosition = cmd.substring(cmd.indexOf("_") + 1, index);
String messageKey = cmd.substring(index + 1);
int position = Integer.parseInt(attachmentPosition);
Long key = new Long(messageKey);
for (MessageView view : backupViews) {
if (view.getKey().equals(key)) {
List<VFSItem> attachments = view.getAttachments();
// velocity counter start with 1
VFSLeaf attachment = (VFSLeaf) attachments.get(position - 1);
VFSMediaResource fileResource = new VFSMediaResource(attachment);
// prevent XSS attack
fileResource.setDownloadable(true);
res = fileResource;
}
}
} catch (Exception e) {
logError("Cannot deliver message attachment", e);
}
if (res == null) {
res = new NotFoundMediaResource();
}
ureq.getDispatchResult().setResultingMediaResource(res);
}
use of org.olat.core.util.vfs.VFSItem in project OpenOLAT by OpenOLAT.
the class ForumArtefactHandler method prefillArtefactAccordingToSource.
/**
* @see org.olat.portfolio.EPAbstractHandler#prefillArtefactAccordingToSource(org.olat.portfolio.model.artefacts.AbstractArtefact, java.lang.Object)
*/
@Override
public void prefillArtefactAccordingToSource(AbstractArtefact artefact, Object source) {
super.prefillArtefactAccordingToSource(artefact, source);
if (source instanceof OLATResourceable) {
OLATResourceable ores = (OLATResourceable) source;
ForumManager fMgr = ForumManager.getInstance();
Message fm = fMgr.loadMessage(ores.getResourceableId());
String thread = fm.getThreadtop() != null ? fm.getThreadtop().getTitle() + " - " : "";
artefact.setTitle(thread + fm.getTitle());
VFSContainer msgContainer = fMgr.getMessageContainer(fm.getForum().getKey(), fm.getKey());
if (msgContainer != null) {
List<VFSItem> foAttach = msgContainer.getItems();
if (foAttach.size() != 0) {
artefact.setFileSourceContainer(msgContainer);
}
}
artefact.setSignature(70);
artefact.setFulltextContent(fm.getBody());
}
}
use of org.olat.core.util.vfs.VFSItem in project OpenOLAT by OpenOLAT.
the class ForumWebService method attachToPost.
protected Response attachToPost(Message mess, String filename, InputStream file, HttpServletRequest request) {
Identity identity = getIdentity(request);
if (identity == null) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
} else if (!identity.equalsByPersistableKey(mess.getCreator())) {
if (mess.getModifier() == null || !identity.equalsByPersistableKey(mess.getModifier())) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
}
VFSContainer container = fom.getMessageContainer(mess.getForum().getKey(), mess.getKey());
VFSItem item = container.resolve(filename);
VFSLeaf attachment = null;
if (item == null) {
attachment = container.createChildLeaf(filename);
} else {
filename = VFSManager.rename(container, filename);
if (filename == null) {
return Response.serverError().status(Status.NOT_ACCEPTABLE).build();
}
attachment = container.createChildLeaf(filename);
}
OutputStream out = attachment.getOutputStream(false);
try {
IOUtils.copy(file, out);
} catch (IOException e) {
return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
} finally {
FileUtils.closeSafely(out);
FileUtils.closeSafely(file);
}
return Response.ok().build();
}
use of org.olat.core.util.vfs.VFSItem in project OpenOLAT by OpenOLAT.
the class ForumRTFFormatter method visit.
/**
* @see org.olat.core.util.tree.Visitor#visit(org.olat.core.util.nodes.INode)
*/
public void visit(INode node) {
MessageNode mn = (MessageNode) node;
if (isTopThread) {
if (filePerThread) {
// make a file per thread
// to have a meaningful filename we create the file here
String filName = "Thread_" + mn.getKey().toString();
tempContainer = makeTempVFSContainer();
vfsFil = tempContainer.resolve(filName + ".rtf");
if (vfsFil == null) {
tempContainer.createChildLeaf(filName + ".rtf");
vfsFil = tempContainer.resolve(filName + ".rtf");
}
}
// important!
isTopThread = false;
}
// Message Title
sb.append("{\\pard \\brdrb\\brdrs\\brdrw10 \\f1\\fs30\\b ");
sb.append(getImageRTF(mn));
sb.append(getTitlePrefix(mn));
sb.append(mn.getTitle());
sb.append("\\par}");
// Message Body
sb.append("{\\pard \\f0");
sb.append(convertHTMLMarkupToRTF(mn.getBody()));
sb.append("\\par}");
// Message key
sb.append("{\\pard \\f0\\fs15 Message key: ");
sb.append(mn.getKey());
sb.append("} \\line ");
sb.append("{\\pard \\f0\\fs15 created: ");
// Creator and creation date
if (StringHelper.containsNonWhitespace(mn.getPseudonym())) {
sb.append(mn.getPseudonym()).append(" ").append(translator.translate("pseudonym.suffix"));
} else if (mn.isGuest()) {
sb.append(translator.translate("guest"));
} else {
sb.append(mn.getCreator().getUser().getProperty(UserConstants.FIRSTNAME, null));
sb.append(", ");
sb.append(mn.getCreator().getUser().getProperty(UserConstants.LASTNAME, null));
}
sb.append(" ");
sb.append(mn.getCreationDate().toString());
// Modifier and modified date
Identity modifier = mn.getModifier();
if (modifier != null) {
sb.append(" \\line modified: ");
sb.append(modifier.getUser().getProperty(UserConstants.FIRSTNAME, null));
sb.append(", ");
sb.append(modifier.getUser().getProperty(UserConstants.LASTNAME, null));
sb.append(" ");
sb.append(mn.getModifiedDate().toString());
}
sb.append(" \\par}");
// attachment(s)
VFSContainer msgContainer = fm.getMessageContainer(getForumKey(), mn.getKey());
List<VFSItem> attachments = msgContainer.getItems();
if (attachments != null && attachments.size() > 0) {
VFSItem item = container.resolve("attachments");
if (item == null) {
item = container.createChildContainer("attachments");
}
VFSContainer attachmentContainer = (VFSContainer) item;
attachmentContainer.copyFrom(msgContainer);
sb.append("{\\pard \\f0\\fs15 Attachment(s): ");
boolean commaFlag = false;
for (VFSItem attachment : attachments) {
if (commaFlag)
sb.append(", ");
sb.append(attachment.getName());
commaFlag = true;
}
sb.append("} \\line");
}
sb.append("{\\pard \\brdrb\\brdrs\\brdrw10 \\par}");
}
use of org.olat.core.util.vfs.VFSItem in project OpenOLAT by OpenOLAT.
the class CollectImageMediaController method initForm.
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
formLayout.setElementCssClass("o_sel_pf_collect_image_form");
String title = mediaReference == null ? null : mediaReference.getTitle();
titleEl = uifactory.addTextElement("artefact.title", "artefact.title", 255, title, formLayout);
titleEl.setElementCssClass("o_sel_pf_collect_title");
titleEl.setMandatory(true);
String desc = mediaReference == null ? null : mediaReference.getDescription();
descriptionEl = uifactory.addRichTextElementForStringDataMinimalistic("artefact.descr", "artefact.descr", desc, 8, 60, formLayout, getWindowControl());
descriptionEl.getEditorConfiguration().setPathInStatusBar(false);
fileEl = uifactory.addFileElement(getWindowControl(), "artefact.file", "artefact.file", formLayout);
fileEl.limitToMimeType(imageMimeTypes, null, null);
fileEl.addActionListener(FormEvent.ONCHANGE);
fileEl.setMaxUploadSizeKB(10000, null, null);
fileEl.setPreview(ureq.getUserSession(), true);
if (mediaReference != null) {
fileEl.setEnabled(false);
VFSItem item = fileHandler.getImage(mediaReference);
if (item instanceof JavaIOItem) {
fileEl.setInitialFile(((JavaIOItem) item).getBasefile());
}
}
categoriesEl = uifactory.addTextBoxListElement("categories", "categories", "categories.hint", categories, formLayout, getTranslator());
categoriesEl.setHelpText(translate("categories.hint"));
categoriesEl.setElementCssClass("o_sel_ep_tagsinput");
categoriesEl.setAllowDuplicates(false);
Date collectDate = mediaReference == null ? new Date() : mediaReference.getCollectionDate();
String date = Formatter.getInstance(getLocale()).formatDate(collectDate);
uifactory.addStaticTextElement("artefact.collect.date", "artefact.collect.date", date, formLayout);
if (StringHelper.containsNonWhitespace(businessPath)) {
String link = BusinessControlFactory.getInstance().getURLFromBusinessPathString(businessPath);
uifactory.addStaticTextElement("artefact.collect.link", "artefact.collect.link", link, formLayout);
}
FormLayoutContainer buttonsCont = FormLayoutContainer.createButtonLayout("buttons", getTranslator());
formLayout.add(buttonsCont);
uifactory.addFormSubmitButton("save", "save", buttonsCont);
uifactory.addFormCancelButton("cancel", buttonsCont, ureq, getWindowControl());
}
Aggregations