Top Description Inners Fields Constructors Methods
groovy.text.markup

public Class MarkupTemplateEngine

extends TemplateEngine
Class Inheritance
Imports
groovy.lang.GroovyClassLoader, .GroovyCodeSource, .Writable, groovy.text.Template, .TemplateEngine, groovy.transform.TypeChecked, org.codehaus.groovy.ast.ClassHelper, .ClassNode, org.codehaus.groovy.classgen.GeneratorContext, org.codehaus.groovy.classgen.asm.BytecodeDumper, org.codehaus.groovy.control.CompilationFailedException, .CompilePhase, .CompilerConfiguration, .SourceUnit, org.codehaus.groovy.control.customizers.ASTTransformationCustomizer, org.codehaus.groovy.control.customizers.CompilationCustomizer, org.codehaus.groovy.runtime.DefaultGroovyMethods, java.io.File, .IOException, .Reader, .StringReader, java.net.MalformedURLException, .URL, .URLClassLoader, java.security.AccessController, .PrivilegedAction, java.util.Collections, .LinkedHashMap, .List, .Map, java.util.concurrent.ConcurrentHashMap, java.util.concurrent.atomic.AtomicLong, java.util.regex.Matcher, .Pattern

A template engine which leverages groovy.xml.StreamingMarkupBuilder to generate XML/XHTML.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
MarkupTemplateEngine.CachingTemplateResolver

A template resolver which avoids calling ClassLoader#getResource(String) if a template path already has been queried before.

public static class
private class
MarkupTemplateEngine.MarkupTemplateMaker

Implements the groovy.text.Template interface by caching a compiled template script and keeping a reference to the optional map of types of the model elements.

pack-priv static class
MarkupTemplateEngine.TemplateGroovyClassLoader

A specialized GroovyClassLoader which will support passing values to the type checking extension thanks to a thread local.

public static class

Field Summary

Modifier and TypeField and Description
private final Map<String, GroovyCodeSource>
private final CompilerConfiguration
private static final AtomicLong
private static final boolean
private final MarkupTemplateEngine.TemplateGroovyClassLoader
private static final Pattern
pack-priv static final ClassNode
pack-priv static final String
private final TemplateConfiguration
private final TemplateResolver

Constructor Summary

AccessConstructor and Description
public
public
public
MarkupTemplateEngine(final ClassLoader parentLoader, final TemplateConfiguration config)

public
MarkupTemplateEngine(final ClassLoader parentLoader, final TemplateConfiguration config, final TemplateResolver resolver)

public
MarkupTemplateEngine(final ClassLoader parentLoader, final File
directory where to find templates
templateDirectory
,
TemplateConfiguration
template engine configuration
tplConfig
)

Convenience constructor to build a template engine which searches for templates into a directory

Method Summary

Modifier and TypeMethod and Description
private static URL[]
buildURLs(final File templateDirectory)

public Template
createTemplate(final Reader reader)

Implements abstract groovy.text.TemplateEngine.createTemplate.

Creates a template by reading content from the Reader.

public Template
createTemplate(final Reader reader, String sourceName)

public Template
createTemplate(final URL resource)

Overrides groovy.text.TemplateEngine.createTemplate.

Creates a template from the content found at the URL using the default encoding.

public Template
createTemplateByPath(final String templatePath)

public Template
public Template
createTypeCheckedModelTemplate(final String source, String sourceName, Map<String, String> modelTypes)

public Template
public Template
createTypeCheckedModelTemplate(final Reader reader, String sourceName, Map<String, String> modelTypes)

public Template
createTypeCheckedModelTemplate(final URL resource, Map<String, String> modelTypes)

public Template
createTypeCheckedModelTemplateByPath(final String templatePath, Map<String, String> modelTypes)

public CompilerConfiguration
public TemplateConfiguration
public GroovyClassLoader
public URL
resolveTemplate(String templatePath)

Inherited from groovy.text.TemplateEngine:
createTemplatecreateTemplatecreateTemplatecreateTemplate

Field Detail

codeSourceCacheback to summary
private final Map<String, GroovyCodeSource> codeSourceCache
compilerConfigurationback to summary
private final CompilerConfiguration compilerConfiguration
counterback to summary
private static final AtomicLong counter
DEBUG_BYTECODEback to summary
private static final boolean DEBUG_BYTECODE
groovyClassLoaderback to summary
private final MarkupTemplateEngine.TemplateGroovyClassLoader groovyClassLoader
LOCALIZED_RESOURCE_PATTERNback to summary
private static final Pattern LOCALIZED_RESOURCE_PATTERN
MARKUPTEMPLATEENGINE_CLASSNODEback to summary
pack-priv static final ClassNode MARKUPTEMPLATEENGINE_CLASSNODE
MODELTYPES_ASTKEYback to summary
pack-priv static final String MODELTYPES_ASTKEY
templateConfigurationback to summary
private final TemplateConfiguration templateConfiguration
templateResolverback to summary
private final TemplateResolver templateResolver

Constructor Detail

MarkupTemplateEngineback to summary
public MarkupTemplateEngine()
MarkupTemplateEngineback to summary
public MarkupTemplateEngine(final TemplateConfiguration config)
MarkupTemplateEngineback to summary
public MarkupTemplateEngine(final ClassLoader parentLoader, final TemplateConfiguration config)
MarkupTemplateEngineback to summary
public MarkupTemplateEngine(final ClassLoader parentLoader, final TemplateConfiguration config, final TemplateResolver resolver)
MarkupTemplateEngineback to summary
public MarkupTemplateEngine(final ClassLoader parentLoader, final File templateDirectory, TemplateConfiguration tplConfig)

Convenience constructor to build a template engine which searches for templates into a directory

Parameters
templateDirectory:File

directory where to find templates

tplConfig:TemplateConfiguration

template engine configuration

Method Detail

buildURLsback to summary
private static URL[] buildURLs(final File templateDirectory)
createTemplateback to summary
public Template createTemplate(final Reader reader) throws CompilationFailedException, ClassNotFoundException, IOException

Implements abstract groovy.text.TemplateEngine.createTemplate.

Doc from groovy.text.TemplateEngine.createTemplate.

Creates a template by reading content from the Reader.

createTemplateback to summary
public Template createTemplate(final Reader reader, String sourceName) throws CompilationFailedException, ClassNotFoundException, IOException
createTemplateback to summary
public Template createTemplate(final URL resource) throws CompilationFailedException, ClassNotFoundException, IOException

Overrides groovy.text.TemplateEngine.createTemplate.

Doc from groovy.text.TemplateEngine.createTemplate.

Creates a template from the content found at the URL using the default encoding. Please consider using createTemplate(URL, Charset).

Annotations
@Override
createTemplateByPathback to summary
public Template createTemplateByPath(final String templatePath) throws CompilationFailedException, ClassNotFoundException, IOException
createTypeCheckedModelTemplateback to summary
public Template createTypeCheckedModelTemplate(final String source, Map<String, String> modelTypes) throws CompilationFailedException, ClassNotFoundException, IOException
createTypeCheckedModelTemplateback to summary
public Template createTypeCheckedModelTemplate(final String source, String sourceName, Map<String, String> modelTypes) throws CompilationFailedException, ClassNotFoundException, IOException
createTypeCheckedModelTemplateback to summary
public Template createTypeCheckedModelTemplate(final Reader reader, Map<String, String> modelTypes) throws CompilationFailedException, ClassNotFoundException, IOException
createTypeCheckedModelTemplateback to summary
public Template createTypeCheckedModelTemplate(final Reader reader, String sourceName, Map<String, String> modelTypes) throws CompilationFailedException, ClassNotFoundException, IOException
createTypeCheckedModelTemplateback to summary
public Template createTypeCheckedModelTemplate(final URL resource, Map<String, String> modelTypes) throws CompilationFailedException, ClassNotFoundException, IOException
createTypeCheckedModelTemplateByPathback to summary
public Template createTypeCheckedModelTemplateByPath(final String templatePath, Map<String, String> modelTypes) throws CompilationFailedException, ClassNotFoundException, IOException
getCompilerConfigurationback to summary
public CompilerConfiguration getCompilerConfiguration()
getTemplateConfigurationback to summary
public TemplateConfiguration getTemplateConfiguration()
getTemplateLoaderback to summary
public GroovyClassLoader getTemplateLoader()
resolveTemplateback to summary
public URL resolveTemplate(String templatePath) throws IOException
groovy.text.markup back to summary

public Class MarkupTemplateEngine.CachingTemplateResolver

extends DefaultTemplateResolver
Class Inheritance

A template resolver which avoids calling ClassLoader#getResource(String) if a template path already has been queried before. This improves performance if caching is enabled in the configuration.

Field Summary

Modifier and TypeField and Description
protected final Map<String, URL>
protected boolean

Constructor Summary

AccessConstructor and Description
public
CachingTemplateResolver(final Map<String, URL>
the backing cache
cache
)

Creates a new caching template resolver.

public
CachingTemplateResolver()

Creates a new caching template resolver using a concurrent hash map as the backing cache.

Method Summary

Modifier and TypeMethod and Description
public void
configure(final ClassLoader
the classloader where templates will be searched for
templateClassLoader
,
final TemplateConfiguration
the configuration of the template engine
configuration
)

Overrides groovy.text.markup.MarkupTemplateEngine.DefaultTemplateResolver.configure.

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(final String
path to the template
templatePath
)

Overrides groovy.text.markup.MarkupTemplateEngine.DefaultTemplateResolver.resolveTemplate.

Implements groovy.text.markup.TemplateResolver.resolveTemplate.

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

Field Detail

cacheback to summary
protected final Map<String, URL> cache
useCacheback to summary
protected boolean useCache

Constructor Detail

CachingTemplateResolverback to summary
public CachingTemplateResolver(final Map<String, URL> cache)

Creates a new caching template resolver. The cache implementation being used depends on the use of the template engine. If multiple templates can be rendered in parallel, it must be using a thread-safe cache.

Parameters
cache:Map<String, URL>

the backing cache

CachingTemplateResolverback to summary
public CachingTemplateResolver()

Creates a new caching template resolver using a concurrent hash map as the backing cache.

Method Detail

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

Overrides groovy.text.markup.MarkupTemplateEngine.DefaultTemplateResolver.configure.

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(final String templatePath) throws IOException

Overrides groovy.text.markup.MarkupTemplateEngine.DefaultTemplateResolver.resolveTemplate.

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
groovy.text.markup back to summary

public Class MarkupTemplateEngine.DefaultTemplateResolver

extends Object
implements TemplateResolver
Class Inheritance
  • java.lang.Object
  • groovy.text.markup.MarkupTemplateEngine.DefaultTemplateResolver
All Implemented Interfaces
groovy.text.markup.TemplateResolver
Known Direct Subclasses
groovy.text.markup.MarkupTemplateEngine.CachingTemplateResolver

Field Summary

Modifier and TypeField and Description
private ClassLoader
private TemplateConfiguration

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
configure(final ClassLoader
the classloader where templates will be searched for
templateClassLoader
,
final 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(final 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

templateClassLoaderback to summary
private ClassLoader templateClassLoader
templateConfigurationback to summary
private TemplateConfiguration templateConfiguration

Constructor Detail

DefaultTemplateResolverback to summary
public DefaultTemplateResolver()

Method Detail

configureback to summary
public void configure(final ClassLoader templateClassLoader, final 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

resolveTemplateback to summary
public URL resolveTemplate(final 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

groovy.text.markup back to summary

private Class MarkupTemplateEngine.MarkupTemplateMaker

extends Object
implements Template
Class Inheritance
All Implemented Interfaces
groovy.text.Template

Implements the groovy.text.Template interface by caching a compiled template script and keeping a reference to the optional map of types of the model elements.

Field Summary

Modifier and TypeField and Description
pack-priv final Map<String, String>
pack-priv final Class<BaseTemplate>

Constructor Summary

AccessConstructor and Description
public
MarkupTemplateMaker(final Reader reader, String sourceName, Map<String, String> modelTypes)

public
MarkupTemplateMaker(final URL resource, Map<String, String> modelTypes)

Method Summary

Modifier and TypeMethod and Description
public Writable
public Writable
make(final Map<K, V> binding)

Implements groovy.text.Template.make.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

modeltypesback to summary
pack-priv final Map<String, String> modeltypes
templateClassback to summary
pack-priv final Class<BaseTemplate> templateClass

Constructor Detail

MarkupTemplateMakerback to summary
public MarkupTemplateMaker(final Reader reader, String sourceName, Map<String, String> modelTypes)
Annotations
@SuppressWarnings:unchecked
MarkupTemplateMakerback to summary
public MarkupTemplateMaker(final URL resource, Map<String, String> modelTypes) throws IOException
Annotations
@SuppressWarnings:unchecked

Method Detail

makeback to summary
public Writable make()

Implements groovy.text.Template.make.

makeback to summary
public Writable make(final Map<K, V> binding)

Implements groovy.text.Template.make.

groovy.text.markup back to summary

pack-priv Class MarkupTemplateEngine.TemplateGroovyClassLoader

extends GroovyClassLoader
Class Inheritance

A specialized GroovyClassLoader which will support passing values to the type checking extension thanks to a thread local.

Field Summary

Modifier and TypeField and Description
pack-priv static final ThreadLocal<Map<String, String>>
Inherited from groovy.lang.GroovyClassLoader:
classCachesourceCache

Constructor Summary

AccessConstructor and Description
public
TemplateGroovyClassLoader(final ClassLoader parentLoader, final CompilerConfiguration compilerConfiguration)

Method Summary

Modifier and TypeMethod and Description
public Class<T>
parseClass(final GroovyCodeSource codeSource, Map<String, String> hints)

Inherited from groovy.lang.GroovyClassLoader:
addClasspathaddURLclearCacheclosecreateCollectorcreateCompilationUnitdefineClassdefineClassgenerateScriptNamegetClassCacheEntrygetClassPathgetLoadedClassesgetPermissionsgetResourceLoadergetTimeStamphasCompatibleConfigurationisRecompilableisShouldRecompileisSourceNewerloadClassloadClassloadClassloadClassparseClassparseClassparseClassparseClassparseClassparseClassparseClassrecompileremoveClassCacheEntrysetClassCacheEntrysetResourceLoadersetShouldRecompile

Field Detail

modelTypesback to summary
pack-priv static final ThreadLocal<Map<String, String>> modelTypes

Constructor Detail

TemplateGroovyClassLoaderback to summary
public TemplateGroovyClassLoader(final ClassLoader parentLoader, final CompilerConfiguration compilerConfiguration)

Method Detail

parseClassback to summary
public Class<T> parseClass(final GroovyCodeSource codeSource, Map<String, String> hints) throws CompilationFailedException
groovy.text.markup back to summary

public Class MarkupTemplateEngine.TemplateResource

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final String
private final String
private final String

Constructor Summary

AccessConstructor and Description
private
TemplateResource(final String baseName, final String locale, final String extension)

Method Summary

Modifier and TypeMethod and Description
public boolean
public static MarkupTemplateEngine.TemplateResource
parse(String fullPath)

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

public MarkupTemplateEngine.TemplateResource
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

baseNameback to summary
private final String baseName
extensionback to summary
private final String extension
localeback to summary
private final String locale

Constructor Detail

TemplateResourceback to summary
private TemplateResource(final String baseName, final String locale, final String extension)

Method Detail

hasLocaleback to summary
public boolean hasLocale()
parseback to summary
public static MarkupTemplateEngine.TemplateResource parse(String fullPath)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

withLocaleback to summary
public MarkupTemplateEngine.TemplateResource withLocale(String locale)