![JAR search and dependency download from the Maven repository](/logo.png)
fr.sii.ogham.template.thymeleaf.buider.ThymeleafEmailBuilder Maven / Gradle / Ivy
package fr.sii.ogham.template.thymeleaf.buider;
import org.thymeleaf.TemplateEngine;
import fr.sii.ogham.core.builder.env.EnvironmentBuilder;
import fr.sii.ogham.email.builder.EmailBuilder;
/**
* Configures parsing of templates using Thymeleaf.
*
* Specific resource resolution can be configured to use template prefix/suffix
* paths:
*
*
*
* .classpath()
* .pathPrefix("email/")
* .pathSuffix(".html")
* .and()
* .file()
* .pathPrefix("/data/myapplication/templates/email")
* .pathSuffix(".html")
*
*
*
* You can customize default Thymeleaf {@link TemplateEngine}:
*
*
*
* .engine()
* .addDialect("foo", myDialect)
* .addMessageResolver(myMessageResolver)
*
*
*
* Or you can use a particular Thymeleaf {@link TemplateEngine}:
*
*
*
* .engine(new MyTemplateEngine())
*
*
*
*
* Email protocol supports several contents (main and alternative). The main
* content is often an HTML email to display a beautiful email to users. The
* alternative content is often a textual fallback (when email client can't
* display HTML version like mobile phones that tries to display a summary of
* the email). You can configure which file extensions are supported by
* Thymeleaf to automatically load variants (HTML: main, TEXT: alternative):
*
*
*
* .variant(EmailVariant.HTML, "html")
* .variant(EmailVariant.TEXT, "txt")
*
*
*
* Thanks to that configuration, you can send an email without specifying the
* extension:
*
*
*
* service.send(new Email()
* .content(new MultiTemplateContent("email/sample", new SampleBean("foo", 42)))
* .to("[email protected]"))
*
*
*
* Ogham will then be able to detect which files exist and choose the right
* behavior:
*
* - If you provide an ".html" file (either in classpath or on filesytem), the
* HTML template is used as main content
* - If you provide an ".txt" file (either in classpath or on filesytem), the
* text template is used as main content
* - If you provide both files, the HTML template is used as main content and
* text template as alternative
*
*
*
* @author Aurélien Baudet
*
*/
public class ThymeleafEmailBuilder extends AbstractThymeleafMultiContentBuilder {
/**
* Initializes the builder with a parent builder. The parent builder is used
* when calling {@link #and()} method. The {@link EnvironmentBuilder} is
* used to evaluate properties when {@link #build()} method is called.
*
* @param parent
* the parent builder
* @param environmentBuilder
* the configuration for property resolution and evaluation
*/
public ThymeleafEmailBuilder(EmailBuilder parent, EnvironmentBuilder> environmentBuilder) {
super(ThymeleafEmailBuilder.class, parent, environmentBuilder);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy