Search in sources :

Example 91 with VFSItem

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);
}
Also used : NotFoundMediaResource(org.olat.core.gui.media.NotFoundMediaResource) VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VFSItem(org.olat.core.util.vfs.VFSItem) MediaResource(org.olat.core.gui.media.MediaResource) NotFoundMediaResource(org.olat.core.gui.media.NotFoundMediaResource) VFSMediaResource(org.olat.core.util.vfs.VFSMediaResource) VFSMediaResource(org.olat.core.util.vfs.VFSMediaResource)

Example 92 with VFSItem

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());
    }
}
Also used : Message(org.olat.modules.fo.Message) OLATResourceable(org.olat.core.id.OLATResourceable) ForumManager(org.olat.modules.fo.manager.ForumManager) VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem)

Example 93 with VFSItem

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();
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) VFSContainer(org.olat.core.util.vfs.VFSContainer) OutputStream(java.io.OutputStream) VFSItem(org.olat.core.util.vfs.VFSItem) IOException(java.io.IOException) Identity(org.olat.core.id.Identity) RestSecurityHelper.getIdentity(org.olat.restapi.security.RestSecurityHelper.getIdentity)

Example 94 with VFSItem

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}");
}
Also used : MessageNode(org.olat.modules.fo.archiver.MessageNode) VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem) Identity(org.olat.core.id.Identity)

Example 95 with VFSItem

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());
}
Also used : JavaIOItem(org.olat.core.util.vfs.JavaIOItem) VFSItem(org.olat.core.util.vfs.VFSItem) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) Date(java.util.Date)

Aggregations

VFSItem (org.olat.core.util.vfs.VFSItem)546 VFSContainer (org.olat.core.util.vfs.VFSContainer)356 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)272 File (java.io.File)78 Test (org.junit.Test)68 OlatRootFolderImpl (org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl)68 ArrayList (java.util.ArrayList)64 InputStream (java.io.InputStream)52 MetaInfo (org.olat.core.commons.modules.bc.meta.MetaInfo)52 Identity (org.olat.core.id.Identity)50 MetaTagged (org.olat.core.commons.modules.bc.meta.tagged.MetaTagged)48 IOException (java.io.IOException)42 Date (java.util.Date)40 URI (java.net.URI)38 LocalFolderImpl (org.olat.core.util.vfs.LocalFolderImpl)38 SystemItemFilter (org.olat.core.util.vfs.filters.SystemItemFilter)34 OutputStream (java.io.OutputStream)30 VFSMediaResource (org.olat.core.util.vfs.VFSMediaResource)28 HttpResponse (org.apache.http.HttpResponse)22 URL (java.net.URL)20