Search in sources :

Example 6 with MessageNode

use of org.olat.modules.fo.archiver.MessageNode in project openolat by klemens.

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)

Aggregations

Identity (org.olat.core.id.Identity)6 VFSContainer (org.olat.core.util.vfs.VFSContainer)6 VFSItem (org.olat.core.util.vfs.VFSItem)6 MessageNode (org.olat.modules.fo.archiver.MessageNode)6 Spacing (org.olat.core.util.openxml.OpenXMLDocument.Spacing)2