Top Description Inners Fields Constructors Methods
org.springframework.web.servlet.view.groovy

public Class GroovyMarkupConfigurer

extends TemplateConfiguration
implements GroovyMarkupConfig, ApplicationContextAware, InitializingBean
Class Inheritance
All Implemented Interfaces
org.springframework.beans.factory.InitializingBean, org.springframework.context.ApplicationContextAware, org.springframework.beans.factory.Aware, org.springframework.web.servlet.view.groovy.GroovyMarkupConfig
Imports
java.io.IOException, java.net.URL, .URLClassLoader, java.util.ArrayList, .List, .Locale, groovy.text.markup.MarkupTemplateEngine, .TemplateConfiguration, .TemplateResolver, org.springframework.beans.factory.InitializingBean, org.springframework.context.ApplicationContext, .ApplicationContextAware, org.springframework.context.i18n.LocaleContextHolder, org.springframework.core.io.Resource, org.springframework.lang.Nullable, org.springframework.util.Assert, .StringUtils

An extension of Groovy's 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: You can provide the 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.

Authors
Brian Clozel, Rossen Stoyanchev
Since
4.1
See Also
GroovyMarkupView, Groovy Markup Template engine documentation

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class

Field Summary

Modifier and TypeField and Description
private ApplicationContext
private String
private MarkupTemplateEngine

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
afterPropertiesSet()

Implements org.springframework.beans.factory.InitializingBean.afterPropertiesSet.

Invoked by the containing BeanFactory after it has set all bean properties and satisfied BeanFactoryAware, ApplicationContextAware etc.

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
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.springframework.context.ApplicationContextAware.setApplicationContext.

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.text.markup.TemplateConfiguration.setLocale.

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.

Inherited from groovy.text.markup.TemplateConfiguration:
getAutoIndentStringgetBaseTemplateClassgetDeclarationEncodinggetLocalegetNewLineStringisAutoEscapeisAutoIndentisAutoNewLineisCacheTemplatesisExpandEmptyElementsisUseDoubleQuotessetAutoEscapesetAutoIndentsetAutoIndentStringsetAutoNewLinesetBaseTemplateClasssetCacheTemplatessetDeclarationEncodingsetExpandEmptyElementssetNewLineStringsetUseDoubleQuotes

Field Detail

applicationContextback to summary
private ApplicationContext applicationContext
Annotations
@Nullable
resourceLoaderPathback to summary
private String resourceLoaderPath
templateEngineback to summary
private MarkupTemplateEngine templateEngine
Annotations
@Nullable

Constructor Detail

GroovyMarkupConfigurerback to summary
public GroovyMarkupConfigurer()

Method Detail

afterPropertiesSetback to summary
public void afterPropertiesSet() throws Exception

Implements org.springframework.beans.factory.InitializingBean.afterPropertiesSet.

Doc from org.springframework.beans.factory.InitializingBean.afterPropertiesSet.

Invoked by the containing BeanFactory after it has set all bean properties and satisfied BeanFactoryAware, ApplicationContextAware etc.

This method allows the bean instance to perform validation of its overall configuration and final initialization when all bean properties have been set.

Annotations
@Override
Exceptions
Exception:
in the event of misconfiguration (such as failure to set an essential property) or if initialization fails for any other reason
createTemplateClassLoaderback to summary
protected ClassLoader createTemplateClassLoader() throws IOException

Create a parent ClassLoader for Groovy to use as parent ClassLoader when loading and compiling templates.

createTemplateEngineback to summary
protected MarkupTemplateEngine createTemplateEngine() throws IOException
getApplicationContextback to summary
protected ApplicationContext getApplicationContext()
getResourceLoaderPathback to summary
public String getResourceLoaderPath()
getTemplateEngineback to summary
public MarkupTemplateEngine getTemplateEngine()

Implements org.springframework.web.servlet.view.groovy.GroovyMarkupConfig.getTemplateEngine.

Doc from org.springframework.web.servlet.view.groovy.GroovyMarkupConfig.getTemplateEngine.

Return the Groovy MarkupTemplateEngine for the current web application context. May be unique to one servlet, or shared in the root context.

Returns:MarkupTemplateEngine

the Groovy MarkupTemplateEngine engine

Annotations
@Override
resolveTemplateback 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 LocaleContextHolder, to find the template file. Effectively the locale configured at the engine level is ignored.

See Also
LocaleContextHolder, setLocale
setApplicationContextback to summary
public void setApplicationContext(ApplicationContext applicationContext)

Implements org.springframework.context.ApplicationContextAware.setApplicationContext.

Doc from org.springframework.context.ApplicationContextAware.setApplicationContext.

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 org.springframework.beans.factory.InitializingBean#afterPropertiesSet() or a custom init-method. Invoked after ResourceLoaderAware#setResourceLoader, ApplicationEventPublisherAware#setApplicationEventPublisher and MessageSourceAware, if applicable.

Parameters
applicationContext:ApplicationContext

the ApplicationContext object to be used by this object

Annotations
@Override
setLocaleback to summary
public void setLocale(Locale locale)

Overrides groovy.text.markup.TemplateConfiguration.setLocale.

This method should not be used, since the considered Locale for resolving templates is the Locale for the current HTTP request.

Annotations
@Override
setResourceLoaderPathback 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 org.springframework.core.io.ResourceLoader. Relative paths are allowed when running in an ApplicationContext.

setTemplateEngineback 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.

org.springframework.web.servlet.view.groovy back to summary

private Class GroovyMarkupConfigurer.LocaleTemplateResolver

extends Object
implements TemplateResolver
Class Inheritance
  • java.lang.Object
  • org.springframework.web.servlet.view.groovy.GroovyMarkupConfigurer.LocaleTemplateResolver
All Implemented Interfaces
groovy.text.markup.TemplateResolver

Custom template resolver that simply delegates to resolveTemplate(ClassLoader, String)..

Field Summary

Modifier and TypeField and Description
private ClassLoader

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod 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.text.markup.TemplateResolver.configure.

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.text.markup.TemplateResolver.resolveTemplate.

Resolvers must implement this method in order to resolve a template, given a template path.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

classLoaderback to summary
private ClassLoader classLoader
Annotations
@Nullable

Constructor Detail

LocaleTemplateResolverback to summary
private LocaleTemplateResolver()

Method Detail

configureback to summary
public void configure(ClassLoader templateClassLoader, TemplateConfiguration configuration)

Implements groovy.text.markup.TemplateResolver.configure.

Doc from groovy.text.markup.TemplateResolver.configure.

This method is called once the template engine is initialized, providing the resolver with the template engine configuration and its template class loader.

Parameters
templateClassLoader:ClassLoader

the classloader where templates will be searched for

configuration:TemplateConfiguration

the configuration of the template engine

Annotations
@Override
resolveTemplateback to summary
public URL resolveTemplate(String templatePath) throws IOException

Implements groovy.text.markup.TemplateResolver.resolveTemplate.

Doc from groovy.text.markup.TemplateResolver.resolveTemplate.

Resolvers must implement this method in order to resolve a template, given a template path. They must return a valid URL or an IOException.

Parameters
templatePath:String

path to the template

Returns:URL

the template URL, that will be used to load the template

Annotations
@Override