Search in sources :

Example 1 with MessageNode

use of org.olat.modules.fo.archiver.MessageNode 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 2 with MessageNode

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

the class ForumStreamedRTFFormatter 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) {
        // important!
        fileName = "Thread_" + mn.getKey().toString() + ".rtf";
        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) {
        sb.append("{\\pard \\f0\\fs15 Attachment(s): ");
        boolean commaFlag = false;
        for (VFSItem attachment : attachments) {
            if (commaFlag)
                sb.append(", ");
            sb.append(attachment.getName());
            commaFlag = true;
            ZipUtil.addToZip(attachment, path + "/attachments", exportStream);
        }
        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 3 with MessageNode

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

the class ForumOpenXMLFormatter method visit.

@Override
public void visit(INode node) {
    MessageNode m = (MessageNode) node;
    StringBuilder creatorAndDate = new StringBuilder();
    Identity creator = m.getCreator();
    if (StringHelper.containsNonWhitespace(m.getPseudonym())) {
        creatorAndDate.append(m.getPseudonym()).append(" ");
        if (m.isGuest()) {
            creatorAndDate.append(translator.translate("guest.suffix"));
        } else {
            creatorAndDate.append(translator.translate("pseudonym.suffix"));
        }
    } else if (m.isGuest()) {
        creatorAndDate.append(translator.translate("guest"));
    } else if (creator != null) {
        creatorAndDate.append(creator.getUser().getProperty(UserConstants.FIRSTNAME, null));
        creatorAndDate.append(" ");
        creatorAndDate.append(creator.getUser().getProperty(UserConstants.LASTNAME, null));
    } else {
        creatorAndDate.append("???");
    }
    creatorAndDate.append(" ");
    creatorAndDate.append(formatter.formatDateAndTime(m.getCreationDate()));
    if (isTopThread) {
        document.appendHeading1(m.getTitle(), creatorAndDate.toString());
        isTopThread = false;
    } else {
        document.appendHeading2(m.getTitle(), creatorAndDate.toString());
    }
    Identity modifier = m.getModifier();
    if (modifier != null) {
        StringBuilder modSb = new StringBuilder();
        if (modifier.equals(creator) && StringHelper.containsNonWhitespace(m.getPseudonym())) {
            modSb.append(m.getPseudonym()).append(" ");
            if (m.isGuest()) {
                modSb.append(translator.translate("guest.suffix"));
            } else {
                modSb.append(translator.translate("pseudonym.suffix"));
            }
        } else {
            modSb.append(translator.translate("msg.modified")).append(": ").append(modifier.getUser().getProperty(UserConstants.FIRSTNAME, null)).append(" ").append(modifier.getUser().getProperty(UserConstants.LASTNAME, null)).append(" ").append(formatter.formatDateAndTime(m.getModifiedDate()));
        }
        document.appendSubtitle(modSb.toString());
    }
    String body = m.getBody();
    if (body != null) {
        body = body.replace("<p>&nbsp;", "<p>");
    }
    document.appendHtmlText(body, new Spacing(180, 0));
    // message attachments
    VFSItem attachmentsItem = forumContainer.resolve(m.getKey().toString());
    if (attachmentsItem instanceof VFSContainer) {
        processAttachments((VFSContainer) attachmentsItem);
    }
}
Also used : MessageNode(org.olat.modules.fo.archiver.MessageNode) VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem) Spacing(org.olat.core.util.openxml.OpenXMLDocument.Spacing) Identity(org.olat.core.id.Identity)

Example 4 with MessageNode

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

the class ForumOpenXMLFormatter method visit.

@Override
public void visit(INode node) {
    MessageNode m = (MessageNode) node;
    StringBuilder creatorAndDate = new StringBuilder();
    Identity creator = m.getCreator();
    if (StringHelper.containsNonWhitespace(m.getPseudonym())) {
        creatorAndDate.append(m.getPseudonym()).append(" ");
        if (m.isGuest()) {
            creatorAndDate.append(translator.translate("guest.suffix"));
        } else {
            creatorAndDate.append(translator.translate("pseudonym.suffix"));
        }
    } else if (m.isGuest()) {
        creatorAndDate.append(translator.translate("guest"));
    } else if (creator != null) {
        creatorAndDate.append(creator.getUser().getProperty(UserConstants.FIRSTNAME, null));
        creatorAndDate.append(" ");
        creatorAndDate.append(creator.getUser().getProperty(UserConstants.LASTNAME, null));
    } else {
        creatorAndDate.append("???");
    }
    creatorAndDate.append(" ");
    creatorAndDate.append(formatter.formatDateAndTime(m.getCreationDate()));
    if (isTopThread) {
        document.appendHeading1(m.getTitle(), creatorAndDate.toString());
        isTopThread = false;
    } else {
        document.appendHeading2(m.getTitle(), creatorAndDate.toString());
    }
    Identity modifier = m.getModifier();
    if (modifier != null) {
        StringBuilder modSb = new StringBuilder();
        if (modifier.equals(creator) && StringHelper.containsNonWhitespace(m.getPseudonym())) {
            modSb.append(m.getPseudonym()).append(" ");
            if (m.isGuest()) {
                modSb.append(translator.translate("guest.suffix"));
            } else {
                modSb.append(translator.translate("pseudonym.suffix"));
            }
        } else {
            modSb.append(translator.translate("msg.modified")).append(": ").append(modifier.getUser().getProperty(UserConstants.FIRSTNAME, null)).append(" ").append(modifier.getUser().getProperty(UserConstants.LASTNAME, null)).append(" ").append(formatter.formatDateAndTime(m.getModifiedDate()));
        }
        document.appendSubtitle(modSb.toString());
    }
    String body = m.getBody();
    if (body != null) {
        body = body.replace("<p>&nbsp;", "<p>");
    }
    document.appendHtmlText(body, new Spacing(180, 0));
    // message attachments
    VFSItem attachmentsItem = forumContainer.resolve(m.getKey().toString());
    if (attachmentsItem instanceof VFSContainer) {
        processAttachments((VFSContainer) attachmentsItem);
    }
}
Also used : MessageNode(org.olat.modules.fo.archiver.MessageNode) VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem) Spacing(org.olat.core.util.openxml.OpenXMLDocument.Spacing) Identity(org.olat.core.id.Identity)

Example 5 with MessageNode

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

the class ForumStreamedRTFFormatter 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) {
        // important!
        fileName = "Thread_" + mn.getKey().toString() + ".rtf";
        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) {
        sb.append("{\\pard \\f0\\fs15 Attachment(s): ");
        boolean commaFlag = false;
        for (VFSItem attachment : attachments) {
            if (commaFlag)
                sb.append(", ");
            sb.append(attachment.getName());
            commaFlag = true;
            ZipUtil.addToZip(attachment, path + "/attachments", exportStream);
        }
        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