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();
}
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();
}
}
Aggregations