Search in sources :

Example 1 with StringTemplateStaticImpl

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);
    }
}
Also used : Locale(java.util.Locale) EmailMessageBuilderImpl(org.summerb.email.impl.EmailMessageBuilderImpl) LocaleAwareEmailMessageBuilderImpl(org.summerb.email.impl.LocaleAwareEmailMessageBuilderImpl) Article(org.summerb.minicms.api.dto.Article) StringTemplateStaticImpl(org.summerb.stringtemplate.impl.StringTemplateStaticImpl) LocaleAwareEmailMessageBuilderImpl(org.summerb.email.impl.LocaleAwareEmailMessageBuilderImpl)

Aggregations

Locale (java.util.Locale)1 EmailMessageBuilderImpl (org.summerb.email.impl.EmailMessageBuilderImpl)1 LocaleAwareEmailMessageBuilderImpl (org.summerb.email.impl.LocaleAwareEmailMessageBuilderImpl)1 Article (org.summerb.minicms.api.dto.Article)1 StringTemplateStaticImpl (org.summerb.stringtemplate.impl.StringTemplateStaticImpl)1