public class GroovyMarkupConfigurer extends groovy.text.markup.TemplateConfiguration implements GroovyMarkupConfig, ApplicationContextAware, InitializingBean
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
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 TemplateConfiguration.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 documentationConstructor and Description |
---|
GroovyMarkupConfigurer() |
Modifier and Type | Method and Description |
---|---|
void |
afterPropertiesSet()
Invoked by a BeanFactory after it has set all bean properties supplied
(and satisfied BeanFactoryAware and ApplicationContextAware).
|
protected java.lang.ClassLoader |
createTemplateClassLoader()
Create a parent ClassLoader for Groovy to use as parent ClassLoader
when loading and compiling templates.
|
protected groovy.text.markup.MarkupTemplateEngine |
createTemplateEngine() |
protected ApplicationContext |
getApplicationContext() |
java.lang.String |
getResourceLoaderPath() |
groovy.text.markup.MarkupTemplateEngine |
getTemplateEngine()
Return the Groovy
MarkupTemplateEngine for the current
web application context. |
protected java.net.URL |
resolveTemplate(java.lang.ClassLoader classLoader,
java.lang.String templatePath)
Resolve a template from the given template path.
|
void |
setApplicationContext(ApplicationContext applicationContext)
Set the ApplicationContext that this object runs in.
|
void |
setLocale(java.util.Locale locale)
This method should not be used, since the considered Locale for resolving
templates is the Locale for the current HTTP request.
|
void |
setResourceLoaderPath(java.lang.String resourceLoaderPath)
Set the Groovy Markup Template resource loader path(s) via a Spring resource
location.
|
void |
setTemplateEngine(groovy.text.markup.MarkupTemplateEngine templateEngine)
Set a pre-configured MarkupTemplateEngine to use for the Groovy Markup
Template web configuration.
|
getAutoIndentString, getBaseTemplateClass, getDeclarationEncoding, getLocale, getNewLineString, isAutoEscape, isAutoIndent, isAutoNewLine, isCacheTemplates, isExpandEmptyElements, isUseDoubleQuotes, setAutoEscape, setAutoIndent, setAutoIndentString, setAutoNewLine, setBaseTemplateClass, setCacheTemplates, setDeclarationEncoding, setExpandEmptyElements, setNewLineString, setUseDoubleQuotes
public void setResourceLoaderPath(java.lang.String resourceLoaderPath)
ResourceLoader
.
Relative paths are allowed when running in an ApplicationContext.public java.lang.String getResourceLoaderPath()
public void setTemplateEngine(groovy.text.markup.MarkupTemplateEngine templateEngine)
Note that this engine instance has to be manually configured, since all other bean properties of this configurer will be ignored.
public groovy.text.markup.MarkupTemplateEngine getTemplateEngine()
GroovyMarkupConfig
MarkupTemplateEngine
for the current
web application context. May be unique to one servlet, or shared
in the root context.getTemplateEngine
in interface GroovyMarkupConfig
public void setApplicationContext(ApplicationContext applicationContext)
ApplicationContextAware
Invoked after population of normal bean properties but before an init callback such
as InitializingBean.afterPropertiesSet()
or a custom init-method. Invoked after ResourceLoaderAware.setResourceLoader(org.springframework.core.io.ResourceLoader)
,
ApplicationEventPublisherAware.setApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher)
and
MessageSourceAware
, if applicable.
setApplicationContext
in interface ApplicationContextAware
applicationContext
- the ApplicationContext object to be used by this objectBeanInitializationException
protected ApplicationContext getApplicationContext()
public void setLocale(java.util.Locale locale)
setLocale
in class groovy.text.markup.TemplateConfiguration
public void afterPropertiesSet() throws java.lang.Exception
InitializingBean
This method allows the bean instance to perform initialization only possible when all bean properties have been set and to throw an exception in the event of misconfiguration.
afterPropertiesSet
in interface InitializingBean
java.lang.Exception
- in the event of misconfiguration (such
as failure to set an essential property) or if initialization fails.protected groovy.text.markup.MarkupTemplateEngine createTemplateEngine() throws java.io.IOException
java.io.IOException
protected java.lang.ClassLoader createTemplateClassLoader() throws java.io.IOException
java.io.IOException
protected java.net.URL resolveTemplate(java.lang.ClassLoader classLoader, java.lang.String templatePath) throws java.io.IOException
The default implementation uses the Locale associated with the current request,
as obtained through LocaleContextHolder
,
to find the template file. Effectively the locale configured at the engine level is ignored.
java.io.IOException
LocaleContextHolder
,
setLocale(java.util.Locale)