use of org.summerb.stringtemplate.impl.StringTemplateStaticImpl in project summerb by skarpushin.
the class SecurityMailsMessageBuilderFactoryImpl method createEmailMessageBuilderFromArticle.
@Override
public EmailMessageBuilder createEmailMessageBuilderFromArticle(String articleKey, User sender) {
try {
Map<Locale, Article> options = articleService.findArticleLocalizations(articleKey);
if (options == null || options.size() == 0) {
log.error("Emails will not be sent! Article not found: " + articleKey);
}
LocaleAwareEmailMessageBuilderImpl ret = new LocaleAwareEmailMessageBuilderImpl();
for (Entry<Locale, Article> entry : options.entrySet()) {
EmailMessageBuilderImpl builder = new EmailMessageBuilderImpl();
builder.setLocale(entry.getKey());
builder.setFromNameTemplate(new StringTemplateStaticImpl(sender.getDisplayName()));
builder.setToNameTemplate(stringTemplateCompiler.compile("${to.displayName}"));
builder.setSubjectTemplate(new StringTemplateStaticImpl(entry.getValue().getTitle()));
builder.setBodyTemplate(stringTemplateCompiler.compile(entry.getValue().getContent()));
ret.getLocaleSpecificBuilders().add(builder);
}
return ret;
} catch (Throwable t) {
throw new RuntimeException("Failed to create email message builder using article id: " + articleKey, t);
}
}
Aggregations