Search in sources :

Example 26 with ClassLoaderTemplateResolver

use of org.thymeleaf.templateresolver.ClassLoaderTemplateResolver in project xm-ms-entity by xm-online.

the class ThymeleafConfiguration method emailTemplateResolver.

@Bean
@Description("Thymeleaf template resolver serving HTML 5 emails")
public ClassLoaderTemplateResolver emailTemplateResolver() {
    ClassLoaderTemplateResolver emailTemplateResolver = new ClassLoaderTemplateResolver();
    emailTemplateResolver.setPrefix("mails/");
    emailTemplateResolver.setSuffix(".html");
    emailTemplateResolver.setTemplateMode("HTML5");
    emailTemplateResolver.setCharacterEncoding(CharEncoding.UTF_8);
    emailTemplateResolver.setOrder(1);
    return emailTemplateResolver;
}
Also used : ClassLoaderTemplateResolver(org.thymeleaf.templateresolver.ClassLoaderTemplateResolver)

Example 27 with ClassLoaderTemplateResolver

use of org.thymeleaf.templateresolver.ClassLoaderTemplateResolver in project irida by phac-nml.

the class IridaApiServicesConfig method exportUploadTemplateEngine.

/*
	 * Template engine for constructing ncbi export submissions
	 */
@Bean(name = "exportUploadTemplateEngine")
public SpringTemplateEngine exportUploadTemplateEngine() {
    SpringTemplateEngine exportUploadTemplateEngine = new SpringTemplateEngine();
    ClassLoaderTemplateResolver classLoaderTemplateResolver = new ClassLoaderTemplateResolver();
    classLoaderTemplateResolver.setPrefix("/ca/corefacility/bioinformatics/irida/export/");
    classLoaderTemplateResolver.setSuffix(".xml");
    classLoaderTemplateResolver.setTemplateMode(TemplateMode.XML);
    classLoaderTemplateResolver.setCharacterEncoding("UTF-8");
    exportUploadTemplateEngine.addTemplateResolver(classLoaderTemplateResolver);
    return exportUploadTemplateEngine;
}
Also used : SpringTemplateEngine(org.thymeleaf.spring4.SpringTemplateEngine) ClassLoaderTemplateResolver(org.thymeleaf.templateresolver.ClassLoaderTemplateResolver) LocalValidatorFactoryBean(org.springframework.validation.beanvalidation.LocalValidatorFactoryBean)

Example 28 with ClassLoaderTemplateResolver

use of org.thymeleaf.templateresolver.ClassLoaderTemplateResolver in project irida by phac-nml.

the class WebEmailConfig method classLoaderTemplateResolver.

/**
 * Configure the template resolver
 * @return A ClassLoaderTemplateResolver
 */
public ClassLoaderTemplateResolver classLoaderTemplateResolver() {
    ClassLoaderTemplateResolver classLoaderTemplateResolver = new ClassLoaderTemplateResolver();
    classLoaderTemplateResolver.setPrefix(MAIL_TEMPLATE_PREFIX);
    classLoaderTemplateResolver.setSuffix(TEMPLATE_SUFFIX);
    classLoaderTemplateResolver.setTemplateMode(TemplateMode.HTML);
    classLoaderTemplateResolver.setCharacterEncoding(CHARACER_ENCODING);
    return classLoaderTemplateResolver;
}
Also used : ClassLoaderTemplateResolver(org.thymeleaf.templateresolver.ClassLoaderTemplateResolver)

Example 29 with ClassLoaderTemplateResolver

use of org.thymeleaf.templateresolver.ClassLoaderTemplateResolver in project contribution by checkstyle.

the class TemplateProcessor method generateWithThymeleaf.

/**
 * Generates output file with release notes using Thymeleaf.
 * @param variables the map which represents template variables.
 * @param outputFile output file.
 * @param templateFilename template name.
 * @throws IOException if I/O error occurs.
 */
public static void generateWithThymeleaf(Map<String, Object> variables, String outputFile, String templateFilename) throws IOException {
    final TemplateEngine engine = new TemplateEngine();
    final AbstractConfigurableTemplateResolver resolver = new ClassLoaderTemplateResolver();
    resolver.setPrefix(TEMPLATE_FOLDER_PATH);
    engine.setTemplateResolver(resolver);
    final IContext ctx = new Context(Locale.US, variables);
    try (Writer fileWriter = new OutputStreamWriter(new FileOutputStream(outputFile), StandardCharsets.UTF_8)) {
        engine.process(templateFilename, ctx, fileWriter);
    }
}
Also used : IContext(org.thymeleaf.context.IContext) Context(org.thymeleaf.context.Context) TemplateEngine(org.thymeleaf.TemplateEngine) ClassLoaderTemplateResolver(org.thymeleaf.templateresolver.ClassLoaderTemplateResolver) IContext(org.thymeleaf.context.IContext) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) AbstractConfigurableTemplateResolver(org.thymeleaf.templateresolver.AbstractConfigurableTemplateResolver)

Example 30 with ClassLoaderTemplateResolver

use of org.thymeleaf.templateresolver.ClassLoaderTemplateResolver in project contribution by checkstyle.

the class SiteGenerator method getTemplateEngine.

/**
 * Creates thymeleaf template engine.
 *
 * @return template engine.
 */
private static TemplateEngine getTemplateEngine() {
    final ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver();
    templateResolver.setTemplateMode("HTML");
    templateResolver.setPrefix("/");
    templateResolver.setSuffix(".template");
    final TemplateEngine tplEngine = new TemplateEngine();
    tplEngine.setTemplateResolver(templateResolver);
    return tplEngine;
}
Also used : ClassLoaderTemplateResolver(org.thymeleaf.templateresolver.ClassLoaderTemplateResolver) TemplateEngine(org.thymeleaf.TemplateEngine)

Aggregations

ClassLoaderTemplateResolver (org.thymeleaf.templateresolver.ClassLoaderTemplateResolver)50 Test (org.junit.Test)18 SpringTemplateEngine (org.thymeleaf.spring5.SpringTemplateEngine)17 ArrayList (java.util.ArrayList)13 TemplateEngine (org.thymeleaf.TemplateEngine)13 Context (org.thymeleaf.context.Context)12 ITemplateResolver (org.thymeleaf.templateresolver.ITemplateResolver)12 FileTemplateResolver (org.thymeleaf.templateresolver.FileTemplateResolver)8 DefaultTemplateResolver (org.thymeleaf.templateresolver.DefaultTemplateResolver)4 Bean (org.springframework.context.annotation.Bean)3 HashMap (java.util.HashMap)2 LinkedHashSet (java.util.LinkedHashSet)2 Map (java.util.Map)2 IExpressionContext (org.thymeleaf.context.IExpressionContext)2 StandardLinkBuilder (org.thymeleaf.linkbuilder.StandardLinkBuilder)2 SpringWebFluxTemplateEngine (org.thymeleaf.spring5.SpringWebFluxTemplateEngine)2 AbstractConfigurableTemplateResolver (org.thymeleaf.templateresolver.AbstractConfigurableTemplateResolver)2 FileOutputStream (java.io.FileOutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Writer (java.io.Writer)1