本文整理汇总了Java中org.thymeleaf.templateresolver.ITemplateResolver类的典型用法代码示例。如果您正苦于以下问题:Java ITemplateResolver类的具体用法?Java ITemplateResolver怎么用?Java ITemplateResolver使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ITemplateResolver类属于org.thymeleaf.templateresolver包,在下文中一共展示了ITemplateResolver类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: mailPreviewTemplateResolver
import org.thymeleaf.templateresolver.ITemplateResolver; //导入依赖的package包/类
/**
* Template resolver for mail preview pages that include email templates (maybe I could just use emailTemplateResolver())
* @return
*/
public ITemplateResolver mailPreviewTemplateResolver() {
// ServletContextTemplateResolver resolver = new ServletContextTemplateResolver();
SpringResourceTemplateResolver resolver = new SpringResourceTemplateResolver();
resolver.setApplicationContext(applicationContext);
resolver.setPrefix("/WEB-INF/classes/" + YadaConstants.EMAIL_TEMPLATES_PREFIX);
// The final slash is not needed because all email template paths must start with "/email/" as specified in the "patterns.add()" statement below
// resolver.setPrefix("/WEB-INF/classes/" + YadaConstants.EMAIL_TEMPLATES_PREFIX + "/");
/* From the tutorial:
When several template resolvers are applied, it is recommended to specify patterns
for each template resolver so that Thymeleaf can quickly discard those template resolvers
that are not meant to resolve the template, enhancing performance. Doing this is not a
requirement, but a recommendation
*/
Set<String> patterns = new HashSet<>();
patterns.add("/email/*"); // Start with "/email/"
resolver.setResolvablePatterns(patterns);
resolver.setSuffix(".html");
resolver.setCharacterEncoding("UTF-8");
resolver.setTemplateMode(TemplateMode.HTML);
resolver.setCacheable(config.isProductionEnvironment());
resolver.setOrder(20);
return resolver;
}
示例2: configure
import org.thymeleaf.templateresolver.ITemplateResolver; //导入依赖的package包/类
protected void configure() {
if (viewResolverConfiguration != null) {
org.thymeleaf.TemplateEngine engine = new org.thymeleaf.TemplateEngine();
Set<ITemplateResolver> resolvers = new HashSet<>();
for (String prefix : viewResolverConfiguration.getPrefixes()) {
ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver();
templateResolver.setPrefix(prefix);
templateResolver.setSuffix(viewResolverConfiguration.getSuffix());
templateResolver.setTemplateMode(TemplateMode.HTML);
templateResolver.setCheckExistence(true);
resolvers.add(templateResolver);
}
engine.setTemplateResolvers(configureTemplateResolvers(resolvers));
this.templateEngine = engine;
configured = true;
}
}
示例3: supports
import org.thymeleaf.templateresolver.ITemplateResolver; //导入依赖的package包/类
protected boolean supports(TemplateEngineModel data) {
if (!configured) {
return false;
}
String contentType = getContentTypeFromModel(data.getInlineContentItem());
if (contentType == null) {
return false;
}
Set<ITemplateResolver> templateResolvers = templateEngine.getTemplateResolvers();
for (ITemplateResolver resolver : templateResolvers) {
if (resolver instanceof AbstractTemplateResolver) {
TemplateResolution templateResolution = resolver.resolveTemplate(templateEngine.getConfiguration(), null, contentType, null);
if (templateResolution != null && templateResolution.getTemplateResource().exists()) {
return true;
}
}
}
return false;
}
示例4: webTemplateResolver
import org.thymeleaf.templateresolver.ITemplateResolver; //导入依赖的package包/类
@Bean
public ITemplateResolver webTemplateResolver() {
// ServletContextTemplateResolver resolver = new ServletContextTemplateResolver();
SpringResourceTemplateResolver resolver = new SpringResourceTemplateResolver();
resolver.setApplicationContext(applicationContext);
// Relative paths never work, with or without trailing slash, so better to be consistent without and always use "absolute" paths [xtian]
resolver.setPrefix("/WEB-INF/views");
// resolver.setPrefix("/WEB-INF/views/");
resolver.setSuffix(".html");
// Set<String> patterns = new HashSet<>();
// patterns.add("^(?!/yada/).*"); // Do not start with "yada" - DOES NOT WORK because it doesn't accept a regexp
// resolver.setResolvablePatterns(patterns);
resolver.setCharacterEncoding("UTF-8");
// NB, selecting HTML5 as the template mode.
resolver.setTemplateMode(TemplateMode.HTML);
resolver.setCacheable(config.isProductionEnvironment());
resolver.setOrder(30); // The last one, because it doesn't have any ResolvablePatterns
return resolver;
}
示例5: xmlTemplateResolver
import org.thymeleaf.templateresolver.ITemplateResolver; //导入依赖的package包/类
@Bean
public ITemplateResolver xmlTemplateResolver() {
// ServletContextTemplateResolver resolver = new ServletContextTemplateResolver();
SpringResourceTemplateResolver resolver = new SpringResourceTemplateResolver();
resolver.setApplicationContext(applicationContext);
// Relative paths never work, with or without trailing slash, so better to be consistent without and always use "absolute" paths [xtian]
resolver.setPrefix("/WEB-INF/views");
// resolver.setPrefix("/WEB-INF/views/");
Set<String> patterns = new HashSet<>();
patterns.add("/xml/*"); // Start with "xml"
resolver.setResolvablePatterns(patterns);
resolver.setSuffix(".xml");
resolver.setCharacterEncoding("UTF-8");
// NB, selecting HTML5 as the template mode.
resolver.setTemplateMode("XML");
resolver.setCacheable(config.isProductionEnvironment());
// resolver.setOrder(30); // Order not needed because resolver on different ViewResolver
return resolver;
}
示例6: overrideCharacterEncoding
import org.thymeleaf.templateresolver.ITemplateResolver; //导入依赖的package包/类
@Test
public void overrideCharacterEncoding() throws Exception {
EnvironmentTestUtils.addEnvironment(this.context,
"spring.thymeleaf.encoding:UTF-16");
this.context.register(ThymeleafAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class);
this.context.refresh();
this.context.getBean(TemplateEngine.class).initialize();
ITemplateResolver resolver = this.context.getBean(ITemplateResolver.class);
assertThat(resolver instanceof TemplateResolver).isTrue();
assertThat(((TemplateResolver) resolver).getCharacterEncoding())
.isEqualTo("UTF-16");
ThymeleafViewResolver views = this.context.getBean(ThymeleafViewResolver.class);
assertThat(views.getCharacterEncoding()).isEqualTo("UTF-16");
assertThat(views.getContentType()).isEqualTo("text/html;charset=UTF-16");
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:17,代码来源:ThymeleafAutoConfigurationTests.java
示例7: getTemplateEngine
import org.thymeleaf.templateresolver.ITemplateResolver; //导入依赖的package包/类
/**
* Producer method building and configuring the {@link TemplateEngine} instance to be used in the application. The
* engine's template resolver is set up to follow MVC requirements. JAX-RS parameter conversion bridges are
* detected, and if one is present, the engine is set up to use it.
*
* Subclasses can override and {@link javax.enterprise.inject.Specializes specialize} this method to add additional
* configuration (e.g. call {@link TemplateEngine#addDialect(org.thymeleaf.dialect.IDialect)} to add a dialect).
*
* @return the newly created and configured {@link TemplateEngine} instance
*/
@Produces public TemplateEngine getTemplateEngine() {
final TemplateEngine engine = new TemplateEngine();
final ITemplateResolver tr = new MVCTemplateResolver(servletContext, mvcContext);
engine.setTemplateResolver(tr);
try {
final Class<?> pcbClass = Class.forName("hu.inbuss.thymeleaf.jaxrs.ParamConverterBridge");
final Bean<?> pcbBean = beanManager.resolve(beanManager.getBeans(pcbClass));
final CreationalContext pcbContext = beanManager.createCreationalContext(pcbBean);
final ParamConverterBridge pcb = (ParamConverterBridge) beanManager.getReference(pcbBean, pcbClass, pcbContext);
pcb.installInto(engine);
} catch (final ClassNotFoundException cnfe) {
// the Jersey integration module is not present, do nothing
}
return engine;
}
示例8: resolveTemplate
import org.thymeleaf.templateresolver.ITemplateResolver; //导入依赖的package包/类
@Override
public TemplateResolution resolveTemplate(TemplateProcessingParameters templateProcessingParameters) {
String unresolvedTemplateName = templateProcessingParameters.getTemplateName();
ResourceResolver supportingResolver = resolver.getSupportingResolver(unresolvedTemplateName);
ITemplateResolver templateResolver;
try {
templateResolver = resolverAdapter.adapt(supportingResolver);
if (forceInitialize) {
// we must initialize the new templateResolver
templateResolver.initialize();
}
String resolvedPath = supportingResolver.getResourcePath(unresolvedTemplateName).getResolvedPath();
TemplateProcessingParameters resolvedTemplateProcessingParameters = new TemplateProcessingParameters(templateProcessingParameters.getConfiguration(), resolvedPath,
templateProcessingParameters.getContext());
return templateResolver.resolveTemplate(resolvedTemplateProcessingParameters);
} catch (NoResolverAdapterException e) {
throw new ResolverAdapterNotFoundException("Unable to resolver template cause no adapter supporting template name '" + unresolvedTemplateName + "' was found. ", e);
}
}
示例9: testEngine
import org.thymeleaf.templateresolver.ITemplateResolver; //导入依赖的package包/类
@Bean
@DependsOn("propertyConfigurer")
public ThymeleafTestEngine testEngine() {
ThymeleafTestEngine engine = new ThymeleafTestEngine();
engine.setCacheManager(thymeleafCacheManager());
engine.setTemplateModeHandlers(templateModeHandlers());
engine.setAdditionalDialects(additionalDialects());
Set<ITemplateResolver> templateResolvers = new HashSet<ITemplateResolver>();
templateResolvers.add(servletContextTemplateResolver());
templateResolvers.add(fileTemplateResolver());
engine.setTemplateResolvers(templateResolvers);
engine.setServletContext(servletContext);
engine.setApplicationContext(applicationContext);
return engine;
}
示例10: defaultTemplateResolver
import org.thymeleaf.templateresolver.ITemplateResolver; //导入依赖的package包/类
@Bean
public ITemplateResolver defaultTemplateResolver() {
final TemplateResolver resolver = new TemplateResolver();
resolver.setResourceResolver(thymeleafResourceResolver());
resolver.setPrefix(this.environment.getProperty("prefix", DEFAULT_PREFIX));
resolver.setSuffix(this.environment.getProperty("suffix", DEFAULT_SUFFIX));
resolver.setTemplateMode(this.environment.getProperty("mode", "HTML5"));
resolver.setCharacterEncoding(this.environment.getProperty("encoding", "UTF-8"));
final Boolean cache = this.environment.getProperty("cache", Boolean.class, true);
resolver.setCacheable(cache);
if (!cache) {
resolver.setCacheTTLMs(0L);
}
return resolver;
}
示例11: get
import org.thymeleaf.templateresolver.ITemplateResolver; //导入依赖的package包/类
@Override
public ITemplateResolver get()
{
ServletContextTemplateResolver resolver = new ServletContextTemplateResolver();
resolver.setTemplateMode("HTML5");
// Load templates from WEB-INF/templates/{name}.html
resolver.setPrefix("/WEB-INF/template/");
resolver.setSuffix(".html");
if (cacheTTL.getMilliseconds() > 0)
{
// cache templates for an hour
resolver.setCacheTTLMs(cacheTTL.getMilliseconds());
resolver.setCacheable(true);
}
else
{
// Don't cache
resolver.setCacheable(false);
}
return resolver;
}
示例12: templateResolver
import org.thymeleaf.templateresolver.ITemplateResolver; //导入依赖的package包/类
@Bean
ITemplateResolver templateResolver()
{
SpringResourceTemplateResolver resolver = new SpringResourceTemplateResolver();
resolver.setPrefix("/WEB-INF/templates/");
resolver.setSuffix(".html");
resolver.setTemplateMode(TemplateMode.HTML);
//debug
resolver.setCacheable(false);
return resolver;
}
示例13: templateResolver
import org.thymeleaf.templateresolver.ITemplateResolver; //导入依赖的package包/类
private ITemplateResolver templateResolver() {
SpringResourceTemplateResolver resolver = new SpringResourceTemplateResolver();
resolver.setApplicationContext(applicationContext);
resolver.setSuffix(".html");
resolver.setPrefix("/WEB-INF/templates/");
resolver.setTemplateMode(TemplateMode.HTML);
return resolver;
}
示例14: htmlTemplateResolver
import org.thymeleaf.templateresolver.ITemplateResolver; //导入依赖的package包/类
private ITemplateResolver htmlTemplateResolver() {
final ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver();
templateResolver.setPrefix("/templates/mail/");
templateResolver.setSuffix(".html");
templateResolver.setTemplateMode(TemplateMode.HTML);
templateResolver.setCacheable(false);
return templateResolver;
}
示例15: createDefaultTemplateResolver
import org.thymeleaf.templateresolver.ITemplateResolver; //导入依赖的package包/类
private static ITemplateResolver createDefaultTemplateResolver(String prefix, String suffix) {
final ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver();
templateResolver.setTemplateMode(TemplateMode.HTML);
templateResolver.setPrefix(
prefix != null ? prefix : DEFAULT_PREFIX
);
templateResolver.setSuffix(
suffix != null ? suffix : DEFAULT_SUFFIX
);
templateResolver.setCacheTTLMs(DEFAULT_CACHE_TTL_MS);
return templateResolver;
}