groovy.text.markup.TemplateConfiguration and
an implementation of Spring MVC's GroovyMarkupConfig for creating
a MarkupTemplateEngine for use in a web application. The most basic
way to configure this class is to set the "resourceLoaderPath". For example:
// Add the following to an @Configuration class
@Bean
public GroovyMarkupConfig groovyMarkupConfigurer() {
GroovyMarkupConfigurer configurer = new GroovyMarkupConfigurer();
configurer.setResourceLoaderPath("classpath:/WEB-INF/groovymarkup/");
return configurer;
}
By default this bean will create a MarkupTemplateEngine with:
TemplateConfiguration
groovy.text.markup.TemplateResolver for resolving template files
MarkupTemplateEngine instance directly to this bean
in which case all other properties will not be effectively ignored.
This bean must be included in the application context of any application
using the Spring MVC GroovyMarkupView for rendering. It exists purely
for the purpose of configuring Groovy's Markup templates. It is not meant to be
referenced by application components directly. It implements GroovyMarkupConfig
to be found by GroovyMarkupView without depending on a bean name. Each
DispatcherServlet can define its own GroovyMarkupConfigurer if desired.
Note that resource caching is enabled by default in MarkupTemplateEngine.
Use the setCacheTemplates(boolean) to configure that as necessary.
Spring's Groovy Markup template support requires Groovy 2.3.1 or higher.
GroovyMarkupView, Groovy Markup Template engine documentation
| Modifier and Type | Class and Description |
|---|---|
| private class | GroovyMarkupConfigurer.
Custom |
| Modifier and Type | Field and Description |
|---|---|
| private ApplicationContext | |
| private String | |
| private MarkupTemplateEngine |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | afterPropertiesSet()
Implements org. Invoked by the containing This method allows the bean instance to perform validation of its overall configuration and final initialization when all bean properties have been set. |
| protected ClassLoader | createTemplateClassLoader()
Create a parent ClassLoader for Groovy to use as parent ClassLoader when loading and compiling templates. |
| protected MarkupTemplateEngine | |
| protected ApplicationContext | |
| public String | |
| public MarkupTemplateEngine | getTemplateEngine()
Implements org. Return the Groovy |
| protected URL | resolveTemplate(ClassLoader classLoader, String templatePath)
Resolve a template from the given template path. |
| public void | setApplicationContext(ApplicationContext
the ApplicationContext object to be used by this object applicationContext)Implements org. Set the ApplicationContext that this object runs in. Normally this call will be used to initialize the object. |
| public void | setLocale(Locale locale)
Overrides groovy. This method should not be used, since the considered Locale for resolving templates is the Locale for the current HTTP request. |
| public void | setResourceLoaderPath(String resourceLoaderPath)
Set the Groovy Markup Template resource loader path(s) via a Spring resource location. |
| public void | setTemplateEngine(MarkupTemplateEngine templateEngine)
Set a pre-configured MarkupTemplateEngine to use for the Groovy Markup Template web configuration. |
| applicationContext | back to summary |
|---|---|
| private ApplicationContext applicationContext
| |
| resourceLoaderPath | back to summary |
|---|---|
| private String resourceLoaderPath | |
| templateEngine | back to summary |
|---|---|
| private MarkupTemplateEngine templateEngine
| |
| GroovyMarkupConfigurer | back to summary |
|---|---|
| public GroovyMarkupConfigurer() | |
| afterPropertiesSet | back to summary |
|---|---|
| public void afterPropertiesSet() throws Exception Implements org. Doc from org. Invoked by the containing This method allows the bean instance to perform validation of its overall configuration and final initialization when all bean properties have been set. | |
| createTemplateClassLoader | back to summary |
|---|---|
| protected ClassLoader createTemplateClassLoader() throws IOException Create a parent ClassLoader for Groovy to use as parent ClassLoader when loading and compiling templates. | |
| createTemplateEngine | back to summary |
|---|---|
| protected MarkupTemplateEngine createTemplateEngine() throws IOException | |
| getApplicationContext | back to summary |
|---|---|
| protected ApplicationContext getApplicationContext() | |
| getResourceLoaderPath | back to summary |
|---|---|
| public String getResourceLoaderPath() | |
| getTemplateEngine | back to summary |
|---|---|
| public MarkupTemplateEngine getTemplateEngine() Implements org. Doc from org. Return the Groovy
| |
| resolveTemplate | back to summary |
|---|---|
| protected URL resolveTemplate(ClassLoader classLoader, String templatePath) throws IOException Resolve a template from the given template path. The default implementation uses the Locale associated with the current request,
as obtained through
| |
| setApplicationContext | back to summary |
|---|---|
| public void setApplicationContext(ApplicationContext applicationContext) Implements org. Doc from org. Set the ApplicationContext that this object runs in. Normally this call will be used to initialize the object. Invoked after population of normal bean properties but before an init callback such
as
| |
| setLocale | back to summary |
|---|---|
| public void setLocale(Locale locale) Overrides groovy. This method should not be used, since the considered Locale for resolving templates is the Locale for the current HTTP request.
| |
| setResourceLoaderPath | back to summary |
|---|---|
| public void setResourceLoaderPath(String resourceLoaderPath) Set the Groovy Markup Template resource loader path(s) via a Spring resource
location. Accepts multiple locations as a comma-separated list of paths.
Standard URLs like "file:" and "classpath:" and pseudo URLs are supported
as understood by Spring's | |
| setTemplateEngine | back to summary |
|---|---|
| public void setTemplateEngine(MarkupTemplateEngine templateEngine) Set a pre-configured MarkupTemplateEngine to use for the Groovy Markup Template web configuration. Note that this engine instance has to be manually configured, since all other bean properties of this configurer will be ignored. | |
template resolver that simply delegates to
resolveTemplate(ClassLoader, String)..
| Modifier and Type | Field and Description |
|---|---|
| private ClassLoader |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public void | configure(ClassLoader
the classloader where templates will be searched for templateClassLoader, TemplateConfiguration the configuration of the template engine configuration)Implements groovy. This method is called once the template engine is initialized, providing the resolver with the template engine configuration and its template class loader. |
| public URL | resolveTemplate(String
path to the template templatePath)Implements groovy. Resolvers must implement this method in order to resolve a template, given a template path. |
| classLoader | back to summary |
|---|---|
| private ClassLoader classLoader
| |
| LocaleTemplateResolver | back to summary |
|---|---|
| private LocaleTemplateResolver() | |
| configure | back to summary |
|---|---|
| public void configure(ClassLoader templateClassLoader, TemplateConfiguration configuration) Implements groovy. Doc from groovy. This method is called once the template engine is initialized, providing the resolver with the template engine configuration and its template class loader.
| |
| resolveTemplate | back to summary |
|---|---|
| public URL resolveTemplate(String templatePath) throws IOException Implements groovy. Doc from groovy. Resolvers must implement this method in order to resolve a template, given a template path. They must return a valid URL or an IOException. | |