Search in sources :

Example 6 with ThymeleafMessageResolver

use of com.tvd12.ezyhttp.server.thymeleaf.ThymeleafMessageResolver in project ezyhttp by youngmonkeys.

the class ThymeleafViewContext method createTemplateEngine.

private TemplateEngine createTemplateEngine() {
    ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver();
    TemplateMode templateMode = TemplateMode.valueOf(metadata.getTemplateMode());
    templateResolver.setTemplateMode(templateMode);
    templateResolver.setPrefix(metadata.getPrefix());
    templateResolver.setSuffix(metadata.getSuffix());
    templateResolver.setCacheTTLMs((long) metadata.getCacheTTLMs());
    templateResolver.setCacheable(metadata.isCacheable());
    ThymeleafMessageResolver messageResolver = ThymeleafMessageResolver.builder().messageLocation(metadata.getMessagesLocation()).messageProviders(messageProviders).absentMessageResolver(absentMessageResolver).build();
    TemplateEngine templateEngine = new TemplateEngine();
    templateEngine.setTemplateResolver(templateResolver);
    templateEngine.setMessageResolver(messageResolver);
    templateEngine.addDialect(new LayoutDialect());
    for (ViewDialect dialect : viewDialects) {
        if (dialect instanceof IDialect) {
            templateEngine.addDialect((IDialect) dialect);
        }
    }
    return templateEngine;
}
Also used : ClassLoaderTemplateResolver(org.thymeleaf.templateresolver.ClassLoaderTemplateResolver) TemplateMode(org.thymeleaf.templatemode.TemplateMode) TemplateEngine(org.thymeleaf.TemplateEngine) ViewDialect(com.tvd12.ezyhttp.server.core.view.ViewDialect) IDialect(org.thymeleaf.dialect.IDialect) LayoutDialect(nz.net.ultraq.thymeleaf.layoutdialect.LayoutDialect)

Aggregations

MessageProvider (com.tvd12.ezyhttp.server.core.view.MessageProvider)5 ThymeleafMessageResolver (com.tvd12.ezyhttp.server.thymeleaf.ThymeleafMessageResolver)5 Locale (java.util.Locale)5 Properties (java.util.Properties)5 Test (org.testng.annotations.Test)5 ITemplateContext (org.thymeleaf.context.ITemplateContext)5 ViewDialect (com.tvd12.ezyhttp.server.core.view.ViewDialect)1 LayoutDialect (nz.net.ultraq.thymeleaf.layoutdialect.LayoutDialect)1 TemplateEngine (org.thymeleaf.TemplateEngine)1 IDialect (org.thymeleaf.dialect.IDialect)1 TemplateMode (org.thymeleaf.templatemode.TemplateMode)1 ClassLoaderTemplateResolver (org.thymeleaf.templateresolver.ClassLoaderTemplateResolver)1