org.thymeleaf.templateresolver.ITemplateResolver Java Examples
The following examples show how to use
org.thymeleaf.templateresolver.ITemplateResolver.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WebConfig.java From Spring5Tutorial with GNU Lesser General Public License v3.0 | 6 votes |
@Bean public ITemplateResolver templateResolver() { // 透過此實例進行相關設定,後續用來建立模版引擎物件 SpringResourceTemplateResolver resolver = new SpringResourceTemplateResolver(); resolver.setApplicationContext(applicationContext); // 開發階段可設定為不快取模版內容,修改模版才能即時反應變更 resolver.setCacheable(false); // 搭配控制器傳回值的前置名稱 resolver.setPrefix("/WEB-INF/templates/"); // 搭配控制器傳回值的後置名稱 resolver.setSuffix(".html"); // HTML 頁面編碼 resolver.setCharacterEncoding("UTF-8"); // 這是一份 HTML 文件 resolver.setTemplateMode(TemplateMode.HTML); return resolver; }
Example #2
Source File: WebConfig.java From Spring5Tutorial with GNU Lesser General Public License v3.0 | 6 votes |
@Bean public ITemplateResolver templateResolver() { // 透過此實例進行相關設定,後續用來建立模版引擎物件 SpringResourceTemplateResolver resolver = new SpringResourceTemplateResolver(); resolver.setApplicationContext(applicationContext); // 開發階段可設定為不快取模版內容,修改模版才能即時反應變更 resolver.setCacheable(false); // 搭配控制器傳回值的前置名稱 resolver.setPrefix("/WEB-INF/templates/"); // 搭配控制器傳回值的後置名稱 resolver.setSuffix(".html"); // HTML 頁面編碼 resolver.setCharacterEncoding("UTF-8"); // 這是一份 HTML 文件 resolver.setTemplateMode(TemplateMode.HTML); return resolver; }
Example #3
Source File: WallRideThymeleafConfiguration.java From wallride with Apache License 2.0 | 6 votes |
@Bean public SpringTemplateEngine templateEngine(WallRideThymeleafDialect wallRideThymeleafDialect) { SpringTemplateEngine engine = new SpringTemplateEngine(); // engine.setTemplateResolver(templateResolver()); Set<ITemplateResolver> templateResolvers = new LinkedHashSet<>(); templateResolvers.add(homePathTemplateResolver()); templateResolvers.add(classPathTemplateResolver()); engine.setTemplateResolvers(templateResolvers); Set<IDialect> dialects = new HashSet<>(); dialects.add(new SpringSecurityDialect()); dialects.add(new Java8TimeDialect()); dialects.add(wallRideThymeleafDialect); engine.setAdditionalDialects(dialects); return engine; }
Example #4
Source File: WebConfig.java From Spring5Tutorial with GNU Lesser General Public License v3.0 | 6 votes |
@Bean public ITemplateResolver templateResolver() { // 透過此實例進行相關設定,後續用來建立模版引擎物件 SpringResourceTemplateResolver resolver = new SpringResourceTemplateResolver(); resolver.setApplicationContext(applicationContext); // 開發階段可設定為不快取模版內容,修改模版才能即時反應變更 resolver.setCacheable(false); // 搭配控制器傳回值的前置名稱 resolver.setPrefix("/WEB-INF/templates/"); // 搭配控制器傳回值的後置名稱 resolver.setSuffix(".html"); // HTML 頁面編碼 resolver.setCharacterEncoding("UTF-8"); // 這是一份 HTML 文件 resolver.setTemplateMode(TemplateMode.HTML); return resolver; }
Example #5
Source File: WebConfig.java From Spring5Tutorial with GNU Lesser General Public License v3.0 | 6 votes |
@Bean public ITemplateResolver templateResolver() { // 透過此實例進行相關設定,後續用來建立模版引擎物件 SpringResourceTemplateResolver resolver = new SpringResourceTemplateResolver(); resolver.setApplicationContext(applicationContext); // 開發階段可設定為不快取模版內容,修改模版才能即時反應變更 resolver.setCacheable(false); // 搭配控制器傳回值的前置名稱 resolver.setPrefix("/WEB-INF/templates/"); // 搭配控制器傳回值的後置名稱 resolver.setSuffix(".html"); // HTML 頁面編碼 resolver.setCharacterEncoding("UTF-8"); // 這是一份 HTML 文件 resolver.setTemplateMode(TemplateMode.HTML); return resolver; }
Example #6
Source File: WebConfig.java From Spring5Tutorial with GNU Lesser General Public License v3.0 | 6 votes |
@Bean public ITemplateResolver templateResolver() { // 透過此實例進行相關設定,後續用來建立模版引擎物件 SpringResourceTemplateResolver resolver = new SpringResourceTemplateResolver(); resolver.setApplicationContext(applicationContext); // 開發階段可設定為不快取模版內容,修改模版才能即時反應變更 resolver.setCacheable(false); // 搭配控制器傳回值的前置名稱 resolver.setPrefix("/WEB-INF/templates/"); // 搭配控制器傳回值的後置名稱 resolver.setSuffix(".html"); // HTML 頁面編碼 resolver.setCharacterEncoding("UTF-8"); // 這是一份 HTML 文件 resolver.setTemplateMode(TemplateMode.HTML); return resolver; }
Example #7
Source File: ThymeLeafV2FirstSupportingTemplateResolver.java From ogham with Apache License 2.0 | 6 votes |
@Override public TemplateResolution resolveTemplate(TemplateProcessingParameters templateProcessingParameters) { String unresolvedTemplateName = templateProcessingParameters.getTemplateName(); ResourceResolver supportingResolver = resolver.getSupportingResolver(new UnresolvedPath(unresolvedTemplateName)); ITemplateResolver templateResolver; try { templateResolver = resolverAdapter.adapt(supportingResolver); if (forceInitialize) { // we must initialize the new templateResolver templateResolver.initialize(); } String resolvedPath = supportingResolver.resolve(new UnresolvedPath(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); } }
Example #8
Source File: ThymeLeafV3FirstSupportingTemplateResolver.java From ogham with Apache License 2.0 | 6 votes |
@Override public TemplateResolution resolveTemplate(IEngineConfiguration configuration, String ownerTemplate, String template, Map<String, Object> templateResolutionAttributes) { try { ResourceResolver supportingResolver = resolver.getSupportingResolver(new UnresolvedPath(template)); ITemplateResolver templateResolver = resolverAdapter.adapt(supportingResolver); ResolvedPath resourcePath = supportingResolver.resolve(new UnresolvedPath(template)); String resolvedPath = resourcePath.getResolvedPath(); TemplateResolution resolution = templateResolver.resolveTemplate(configuration, ownerTemplate, resolvedPath, templateResolutionAttributes); if(!templateExists(resolution)) { throw new TemplateResolutionException("Failed to find template "+template+" ("+resolvedPath+")", template, resourcePath); } return resolution; } catch (NoResolverAdapterException e) { throw new ResolverAdapterNotFoundException("Unable to resolve template cause no adapter supporting template name '" + template + "' was found.", e); } }
Example #9
Source File: ThymeleafConfiguration.java From graviteeio-access-management with Apache License 2.0 | 5 votes |
private ITemplateResolver defaultTemplateResolver() { ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver(); templateResolver.setPrefix("/views/"); templateResolver.setSuffix(".html"); templateResolver.setTemplateMode("HTML"); return templateResolver; }
Example #10
Source File: WebAdminConfiguration.java From wallride with Apache License 2.0 | 5 votes |
@Bean public SpringTemplateEngine templateEngine() { SpringTemplateEngine engine = new SpringTemplateEngine(); Set<ITemplateResolver> resolvers = new HashSet<>(); resolvers.add(adminTemplateResolver()); engine.setTemplateResolvers(resolvers); Set<IDialect> dialects = new HashSet<>(); dialects.add(new SpringSecurityDialect()); dialects.add(new Java8TimeDialect()); dialects.add(wallRideThymeleafDialect); engine.setAdditionalDialects(dialects); return engine; }
Example #11
Source File: WebAdminConfiguration.java From wallride with Apache License 2.0 | 5 votes |
@Bean(name = "guestTemplateResolver") public ITemplateResolver guestTemplateResolver() { WallRideResourceTemplateResolver resolver = new WallRideResourceTemplateResolver(); // resolver.setResourceResolver(wallRideResourceResourceResolver); resolver.setApplicationContext(getApplicationContext()); resolver.setPrefix(environment.getRequiredProperty("spring.thymeleaf.prefix.guest")); resolver.setSuffix(this.properties.getSuffix()); resolver.setTemplateMode(this.properties.getMode()); resolver.setCharacterEncoding(this.properties.getEncoding().name()); resolver.setCacheable(this.properties.isCache()); resolver.setOrder(2); return resolver; }
Example #12
Source File: WallRideMailConfiguration.java From wallride with Apache License 2.0 | 5 votes |
@Bean(name = "emailTemplateResolver") public ITemplateResolver emailTemplateResolver() { SpringResourceTemplateResolver resolver = new SpringResourceTemplateResolver(); // resolver.setResourceResolver(wallRideResourceResourceResolver); resolver.setApplicationContext(applicationContext); resolver.setPrefix(environment.getRequiredProperty("spring.thymeleaf.prefix.mail")); resolver.setSuffix(this.properties.getSuffix()); resolver.setTemplateMode(this.properties.getMode()); resolver.setCharacterEncoding(this.properties.getEncoding().name()); resolver.setCacheable(this.properties.isCache()); resolver.setOrder(1); return resolver; }
Example #13
Source File: WebConfig.java From tutorials with MIT License | 5 votes |
private ITemplateResolver templateResolver() { SpringResourceTemplateResolver resolver = new SpringResourceTemplateResolver(); resolver.setApplicationContext(applicationContext); resolver.setPrefix("/WEB-INF/templates/"); resolver.setSuffix(".html"); resolver.setTemplateMode(TemplateMode.HTML); return resolver; }
Example #14
Source File: WebMVCConfig.java From tutorials with MIT License | 5 votes |
private ISpringTemplateEngine templateEngine(ITemplateResolver templateResolver) { SpringTemplateEngine engine = new SpringTemplateEngine(); engine.addDialect(new LayoutDialect(new GroupingStrategy())); engine.addDialect(new Java8TimeDialect()); engine.setTemplateResolver(templateResolver); engine.setTemplateEngineMessageSource(messageSource()); return engine; }
Example #15
Source File: WebMVCConfig.java From tutorials with MIT License | 5 votes |
private ITemplateResolver htmlTemplateResolver() { SpringResourceTemplateResolver resolver = new SpringResourceTemplateResolver(); resolver.setApplicationContext(applicationContext); resolver.setPrefix("/WEB-INF/views/"); resolver.setCacheable(false); resolver.setTemplateMode(TemplateMode.HTML); return resolver; }
Example #16
Source File: WebMVCConfig.java From tutorials with MIT License | 5 votes |
private ITemplateResolver javascriptTemplateResolver() { SpringResourceTemplateResolver resolver = new SpringResourceTemplateResolver(); resolver.setApplicationContext(applicationContext); resolver.setPrefix("/WEB-INF/js/"); resolver.setCacheable(false); resolver.setTemplateMode(TemplateMode.JAVASCRIPT); return resolver; }
Example #17
Source File: WebMVCConfig.java From tutorials with MIT License | 5 votes |
private ITemplateResolver plainTemplateResolver() { SpringResourceTemplateResolver resolver = new SpringResourceTemplateResolver(); resolver.setApplicationContext(applicationContext); resolver.setPrefix("/WEB-INF/txt/"); resolver.setCacheable(false); resolver.setTemplateMode(TemplateMode.TEXT); return resolver; }
Example #18
Source File: DefaultTemplateEngineProducer.java From krazo with Apache License 2.0 | 5 votes |
@Produces @ViewEngineConfig public TemplateEngine getTemplateEngine() { ITemplateResolver resolver = new ServletContextTemplateResolver(this.servletContext); TemplateEngine engine = new TemplateEngine(); engine.setTemplateResolver(resolver); return engine; }
Example #19
Source File: Config.java From tutorials with MIT License | 5 votes |
@Bean public ITemplateResolver templateResolver() { ClassLoaderTemplateResolver resolver = new ClassLoaderTemplateResolver(); resolver.setPrefix("templates/sessionattrs/"); resolver.setSuffix(".html"); resolver.setTemplateMode(TemplateMode.HTML); resolver.setCharacterEncoding("UTF-8"); return resolver; }
Example #20
Source File: ThymeleafV3TemplateOptionsApplier.java From ogham with Apache License 2.0 | 5 votes |
@Override public void apply(ITemplateResolver templateResolver, TemplateResolverOptions options) { if (templateResolver instanceof AbstractConfigurableTemplateResolver) { // TODO: handle other options ? AbstractConfigurableTemplateResolver resolver = (AbstractConfigurableTemplateResolver) templateResolver; set(resolver::setTemplateMode, options.getTemplateMode()); set(resolver::setCacheable, options.getCacheable()); } }
Example #21
Source File: WebMvcConfig.java From thymeleafexamples-layouts with Apache License 2.0 | 5 votes |
@Bean public ITemplateResolver templateResolver() { SpringResourceTemplateResolver resolver = new SpringResourceTemplateResolver(); resolver.setPrefix(VIEWS); resolver.setSuffix(".html"); resolver.setTemplateMode(TemplateMode.HTML); resolver.setCharacterEncoding("UTF-8"); resolver.setCacheable(false); return resolver; }
Example #22
Source File: SpringMailConfig.java From konker-platform with Apache License 2.0 | 5 votes |
private ITemplateResolver textTemplateResolver() { final ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver(); templateResolver.setOrder(1); templateResolver.setResolvablePatterns(Collections.singleton("text/*")); templateResolver.setPrefix("/mail/"); templateResolver.setSuffix(".txt"); templateResolver.setTemplateMode(TemplateMode.TEXT); templateResolver.setCharacterEncoding("UTF-8"); templateResolver.setCacheable(false); return templateResolver; }
Example #23
Source File: WallRideThymeleafConfiguration.java From wallride with Apache License 2.0 | 5 votes |
@Bean public ITemplateResolver classPathTemplateResolver() { WallRideResourceTemplateResolver resolver = new WallRideResourceTemplateResolver(); // resolver.setResourceResolver(wallRideResourceResourceResolver); resolver.setApplicationContext(applicationContext); resolver.setPrefix(environment.getRequiredProperty("spring.thymeleaf.prefix.guest")); resolver.setSuffix(this.thymeleafProperties.getSuffix()); resolver.setTemplateMode(this.thymeleafProperties.getMode()); resolver.setCharacterEncoding(this.thymeleafProperties.getEncoding().name()); resolver.setCacheable(this.thymeleafProperties.isCache()); resolver.setOrder(2); return resolver; }
Example #24
Source File: SpringMailConfig.java From konker-platform with Apache License 2.0 | 5 votes |
private ITemplateResolver htmlTemplateResolver() { final ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver(); templateResolver.setOrder(2); templateResolver.setResolvablePatterns(Collections.singleton("html/*")); templateResolver.setPrefix("/mail/"); templateResolver.setSuffix(".html"); templateResolver.setTemplateMode(TemplateMode.HTML); templateResolver.setCharacterEncoding("UTF-8"); templateResolver.setCacheable(false); return templateResolver; }
Example #25
Source File: WallRideThymeleafConfiguration.java From wallride with Apache License 2.0 | 5 votes |
@Bean(name = {"defaultTemplateResolver", "homePathTemplateResolver"}) public ITemplateResolver homePathTemplateResolver() { WallRideResourceTemplateResolver resolver = new WallRideResourceTemplateResolver(); // resolver.setResourceResolver(wallRideResourceResourceResolver); resolver.setApplicationContext(applicationContext); resolver.setPrefix(wallRideProperties.getHome() + "themes/default/templates/"); resolver.setSuffix(this.thymeleafProperties.getSuffix()); resolver.setTemplateMode(this.thymeleafProperties.getMode()); resolver.setCharacterEncoding(this.thymeleafProperties.getEncoding().name()); resolver.setCacheable(this.thymeleafProperties.isCache()); resolver.setOrder(1); return resolver; }
Example #26
Source File: SpringMailConfig.java From konker-platform with Apache License 2.0 | 5 votes |
private ITemplateResolver stringTemplateResolver() { final ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver(); templateResolver.setOrder(3); templateResolver.setTemplateMode(TemplateMode.HTML5); templateResolver.setCacheable(false); return templateResolver; }
Example #27
Source File: ThymeleafTemplateEngine.java From spark-template-engines with Apache License 2.0 | 5 votes |
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; }
Example #28
Source File: ThymeleafV2TemplateOptionsApplier.java From ogham with Apache License 2.0 | 5 votes |
@Override public void apply(ITemplateResolver templateResolver, TemplateResolverOptions options) { if (templateResolver instanceof TemplateResolver) { // TODO: handle other options ? TemplateResolver resolver = (TemplateResolver) templateResolver; set(resolver::setTemplateMode, options.getTemplateMode()); set(resolver::setCacheable, options.getCacheable()); } }
Example #29
Source File: DefaultTemplateEngineProducer.java From ozark with Apache License 2.0 | 5 votes |
@Produces @ViewEngineConfig public TemplateEngine getTemplateEngine() { ITemplateResolver resolver = new ServletContextTemplateResolver(this.servletContext); TemplateEngine engine = new TemplateEngine(); engine.setTemplateResolver(resolver); return engine; }
Example #30
Source File: FirstSupportingResolverAdapter.java From ogham with Apache License 2.0 | 5 votes |
@Override public ITemplateResolver adapt(ResourceResolver resolver) throws NoResolverAdapterException { for (TemplateResolverAdapter adapter : adapters) { if (adapter.supports(resolver)) { return adapter.adapt(resolver); } } throw new NoResolverAdapterException("No resolver adapter found for the provided resolver: " + resolver.getClass().getSimpleName(), resolver); }