Search in sources :

Example 1 with HtmlWriter

use of org.activityinfo.server.util.html.HtmlWriter in project activityinfo by bedatadriven.

the class ReportMailerHelper method composeHtmlEmail.

static String composeHtmlEmail(ReportSubscription sub, Report report) {
    // load our resource bundle with localized messages
    ResourceBundle mailMessages = ResourceBundle.getBundle("org.activityinfo.server.mail.MailMessages", sub.getUser().getLocaleObject());
    HtmlWriter htmlWriter = new HtmlWriter();
    htmlWriter.startDocument();
    htmlWriter.startDocumentBody();
    String greeting = MessageFormat.format(mailMessages.getString("greeting"), sub.getUser().getName());
    htmlWriter.paragraph(greeting);
    String intro;
    if (sub.getInvitingUser() != null) {
        intro = MessageFormat.format(mailMessages.getString("reportIntroInvited"), sub.getInvitingUser().getName(), sub.getInvitingUser().getEmail(), report.getTitle(), frequencyString(mailMessages, sub.getEmailDelivery()));
    } else {
        intro = MessageFormat.format(mailMessages.getString("reportIntro"), report.getTitle(), frequencyString(mailMessages, sub.getEmailDelivery()));
    }
    htmlWriter.paragraph(intro);
    htmlWriter.paragraph(MessageFormat.format(mailMessages.getString("viewLive"), Integer.toString(sub.getTemplate().getId())));
    htmlWriter.paragraph(mailMessages.getString("signature"));
    htmlWriter.endDocumentBody();
    htmlWriter.endDocument();
    return htmlWriter.toString();
}
Also used : HtmlWriter(org.activityinfo.server.util.html.HtmlWriter) ResourceBundle(java.util.ResourceBundle)

Example 2 with HtmlWriter

use of org.activityinfo.server.util.html.HtmlWriter in project activityinfo by bedatadriven.

the class DigestMessageBuilder method build.

public Message build() throws IOException, MessagingException {
    Preconditions.checkNotNull(userDigest);
    Preconditions.checkNotNull(userDigest.getUser());
    // set the locale of the messages
    ThreadLocalLocaleProvider.pushLocale(userDigest.getUser().getLocaleObject());
    try {
        DigestModel model = digestModelBuilder.createModel(userDigest);
        if (!model.hasData()) {
            return null;
        }
        // create message, set recipient & bcc
        Message message = new Message();
        message.to(userDigest.getUser().getEmail(), userDigest.getUser().getName());
        String subject = I18N.MESSAGES.digestSubject(userDigest.getDate());
        message.subject(subject);
        // create the html body
        HtmlWriter htmlWriter = new HtmlWriter();
        htmlWriter.startDocument();
        htmlWriter.startDocumentHeader();
        htmlWriter.documentTitle(subject);
        htmlWriter.open(new HtmlTag("style")).at("type", "text/css").text("body { font-family:Helvetica; } a {color: black; text-decoration:none;} ").close();
        htmlWriter.endDocumentHeader();
        htmlWriter.startDocumentBody();
        htmlWriter.paragraph(I18N.MESSAGES.digestGreeting(userDigest.getUser().getName()));
        // the digest content
        htmlWriter.paragraph(digestRenderer.renderHtml(model));
        String signature = I18N.MESSAGES.digestSignature();
        htmlWriter.paragraph(signature);
        htmlWriter.endDocumentBody();
        htmlWriter.endDocument();
        LOGGER.finest("digest:\n" + htmlWriter.toString());
        message.htmlBody(htmlWriter.toString());
        return message;
    } finally {
        ThreadLocalLocaleProvider.popLocale();
    }
}
Also used : Message(org.activityinfo.server.mail.Message) HtmlWriter(org.activityinfo.server.util.html.HtmlWriter) HtmlTag(org.activityinfo.server.util.html.HtmlTag)

Aggregations

HtmlWriter (org.activityinfo.server.util.html.HtmlWriter)2 ResourceBundle (java.util.ResourceBundle)1 Message (org.activityinfo.server.mail.Message)1 HtmlTag (org.activityinfo.server.util.html.HtmlTag)1