use of org.thymeleaf.TemplateEngine in project spring-boot by spring-projects.
the class ThymeleafAutoConfigurationTests method renderNonWebAppTemplate.
@Test
public void renderNonWebAppTemplate() throws Exception {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ThymeleafAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class);
assertThat(context.getBeanNamesForType(ViewResolver.class).length).isEqualTo(0);
try {
TemplateEngine engine = context.getBean(TemplateEngine.class);
Context attrs = new Context(Locale.UK, Collections.singletonMap("greeting", "Hello World"));
String result = engine.process("message", attrs);
assertThat(result).contains("Hello World");
} finally {
context.close();
}
}
use of org.thymeleaf.TemplateEngine in project sling by apache.
the class ThymeleafScriptEngineFactory method setupTemplateEngine.
private void setupTemplateEngine() {
logger.info("setting up new template engine");
templateEngine = null;
if (configuration == null) {
logger.info("configuration is null, not setting up new template engine");
return;
}
if (!configuration.useStandardEngineContextFactory() && engineContextFactory == null) {
logger.info("no engine context factory available, not setting up new template engine");
return;
}
// setup template engine
final TemplateEngine templateEngine = new TemplateEngine();
// Template Resolvers
if (this.templateResolvers != null) {
final Set<ITemplateResolver> templateResolvers = new HashSet<>(this.templateResolvers);
templateEngine.setTemplateResolvers(templateResolvers);
}
// Message Resolvers
if (this.messageResolvers != null) {
final Set<IMessageResolver> messageResolvers = new HashSet<>(this.messageResolvers);
templateEngine.setMessageResolvers(messageResolvers);
}
if (configuration.useStandardMessageResolver()) {
final IMessageResolver standardMessageResolver = new StandardMessageResolver();
templateEngine.addMessageResolver(standardMessageResolver);
}
// Link Builders
if (this.linkBuilders != null) {
final Set<ILinkBuilder> linkBuilders = new HashSet<>(this.linkBuilders);
templateEngine.setLinkBuilders(linkBuilders);
}
if (configuration.useStandardLinkBuilder()) {
final ILinkBuilder standardLinkBuilder = new StandardLinkBuilder();
templateEngine.addLinkBuilder(standardLinkBuilder);
}
// Dialects
if (this.dialects != null) {
final Set<IDialect> dialects = new HashSet<>(this.dialects);
templateEngine.setDialects(dialects);
}
if (configuration.useStandardDialect()) {
final IDialect standardDialect = new StandardDialect();
templateEngine.addDialect(standardDialect);
}
// Decoupled Template Logic Resolver
if (!configuration.useStandardDecoupledTemplateLogicResolver()) {
templateEngine.setDecoupledTemplateLogicResolver(decoupledTemplateLogicResolver);
}
// Cache Manager
if (!configuration.useStandardCacheManager()) {
templateEngine.setCacheManager(cacheManager);
}
// Engine Context Factory
if (!configuration.useStandardEngineContextFactory()) {
templateEngine.setEngineContextFactory(engineContextFactory);
}
//
this.templateEngine = templateEngine;
}
Aggregations