Package groovy.text.markup

# Class MarkupTemplateEngine

java.lang.Object
groovy.text.TemplateEngine
groovy.text.markup.MarkupTemplateEngine

public class MarkupTemplateEngine extends TemplateEngine
A template engine which leverages `StreamingMarkupBuilder` to generate XML/XHTML.

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `static class`
  `MarkupTemplateEngine.CachingTemplateResolver`
  A template resolver which avoids calling `ClassLoader.getResource(String)` if a template path already has been queried before.
  `static class`
  `MarkupTemplateEngine.DefaultTemplateResolver`
  Default resolver that loads templates from the configured template class loader and applies locale fallback rules.
  `static class`
  `MarkupTemplateEngine.TemplateResource`
  Describes a template resource name split into base name, optional locale suffix, and extension.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `MarkupTemplateEngine()`
  Creates an engine with the default `TemplateConfiguration`.
  `MarkupTemplateEngine(TemplateConfiguration config)`
  Creates an engine with the supplied template configuration.
  `MarkupTemplateEngine(ClassLoader parentLoader, TemplateConfiguration config)`
  Creates an engine with the supplied parent loader and template configuration.
  `MarkupTemplateEngine(ClassLoader parentLoader, TemplateConfiguration config, TemplateResolver resolver)`
  Creates an engine with full control over the class loader, configuration, and resolver strategy.
  `MarkupTemplateEngine(ClassLoader parentLoader, File templateDirectory, TemplateConfiguration tplConfig)`
  Convenience constructor to build a template engine which searches for templates into a directory

- ## Method Summary

  Modifier and Type
  Method
  Description
  `Template`
  `createTemplate(Reader reader)`
  Compiles a template from a reader.
  `Template`
  `createTemplate(Reader reader, String sourceName)`
  Compiles a template from a reader using an explicit source name.
  `Template`
  `createTemplate(URL resource)`
  Compiles a template from a resolved resource URL.
  `Template`
  `createTemplateByPath(String templatePath)`
  Resolves and compiles a template by path.
  `Template`
  `createTypeCheckedModelTemplate(Reader reader, String sourceName, Map<String,String> modelTypes)`
  Compiles template source from a reader with explicit model type hints and a source name.
  `Template`
  `createTypeCheckedModelTemplate(Reader reader, Map<String,String> modelTypes)`
  Compiles template source from a reader with explicit model type hints.
  `Template`
  `createTypeCheckedModelTemplate(String source, String sourceName, Map<String,String> modelTypes)`
  Compiles inline template source with explicit model type hints and a source name.
  `Template`
  `createTypeCheckedModelTemplate(String source, Map<String,String> modelTypes)`
  Compiles inline template source with explicit model type hints.
  `Template`
  `createTypeCheckedModelTemplate(URL resource, Map<String,String> modelTypes)`
  Compiles a template from a resolved resource URL with explicit model type hints.
  `Template`
  `createTypeCheckedModelTemplateByPath(String templatePath, Map<String,String> modelTypes)`
  Resolves and compiles a template by path with explicit model type hints.
  `CompilerConfiguration`
  `getCompilerConfiguration()`
  Returns the Groovy compiler configuration used for generated template classes.
  `TemplateConfiguration`
  `getTemplateConfiguration()`
  Returns the rendering configuration used by this engine.
  `GroovyClassLoader`
  `getTemplateLoader()`
  Returns the class loader used to compile generated template classes.
  `URL`
  `resolveTemplate(String templatePath)`
  Resolves a logical template path into a concrete resource URL.

  ### Methods inherited from class groovy.text.TemplateEngine

  `createTemplate, createTemplate, createTemplate, createTemplate`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### MarkupTemplateEngine

    public MarkupTemplateEngine()
    Creates an engine with the default `TemplateConfiguration`.

  - ### MarkupTemplateEngine

    public MarkupTemplateEngine(TemplateConfiguration config)
    Creates an engine with the supplied template configuration.
    Parameters:
      `config` - template configuration to apply while compiling and rendering templates

  - ### MarkupTemplateEngine

    public MarkupTemplateEngine(ClassLoader parentLoader, TemplateConfiguration config)
    Creates an engine with the supplied parent loader and template configuration.
    Parameters:
      `parentLoader` - class loader used to compile generated template classes
      `config` - template configuration to apply while compiling and rendering templates

  - ### MarkupTemplateEngine

    public MarkupTemplateEngine(ClassLoader parentLoader, TemplateConfiguration config, TemplateResolver resolver)
    Creates an engine with full control over the class loader, configuration, and resolver strategy.
    Parameters:
      `parentLoader` - class loader used to compile generated template classes
      `config` - template configuration to apply while compiling and rendering templates
      `resolver` - template resolver to use, or `null` for the default resolver

  - ### MarkupTemplateEngine

    public MarkupTemplateEngine(ClassLoader parentLoader, File templateDirectory, TemplateConfiguration tplConfig)
    Convenience constructor to build a template engine which searches for templates into a directory
    Parameters:
      `templateDirectory` - directory where to find templates
      `tplConfig` - template engine configuration

- ## Method Details

  - ### createTemplate

    public Template createTemplate(Reader reader) throws CompilationFailedException, ClassNotFoundException, IOException
    Compiles a template from a reader.
    Specified by:
      `createTemplate` in class `TemplateEngine`
    Parameters:
      `reader` - template source
    Returns:
      a compiled markup template
    Throws:
      `CompilationFailedException` - if Groovy fails to compile the generated template
      `ClassNotFoundException` - if the generated template class cannot be instantiated
      `IOException` - if reading the template source fails

  - ### createTemplate

    public Template createTemplate(Reader reader, String sourceName) throws CompilationFailedException, ClassNotFoundException, IOException
    Compiles a template from a reader using an explicit source name.
    Parameters:
      `reader` - template source
      `sourceName` - source name used for diagnostics and generated classes
    Returns:
      a compiled markup template
    Throws:
      `CompilationFailedException` - if Groovy fails to compile the generated template
      `ClassNotFoundException` - if the generated template class cannot be instantiated
      `IOException` - if reading the template source fails

  - ### createTemplateByPath

    public Template createTemplateByPath(String templatePath) throws CompilationFailedException, ClassNotFoundException, IOException
    Resolves and compiles a template by path.
    Parameters:
      `templatePath` - logical template path understood by the configured resolver
    Returns:
      a compiled markup template
    Throws:
      `CompilationFailedException` - if Groovy fails to compile the generated template
      `ClassNotFoundException` - if the generated template class cannot be instantiated
      `IOException` - if template resolution or reading fails

  - ### createTypeCheckedModelTemplate

    public Template createTypeCheckedModelTemplate(String source, Map<String,String> modelTypes) throws CompilationFailedException, ClassNotFoundException, IOException
    Compiles inline template source with explicit model type hints.
    Parameters:
      `source` - template source
      `modelTypes` - model variable type hints keyed by variable name
    Returns:
      a compiled markup template
    Throws:
      `CompilationFailedException` - if Groovy fails to compile the generated template
      `ClassNotFoundException` - if the generated template class cannot be instantiated
      `IOException` - if reading the template source fails

  - ### createTypeCheckedModelTemplate

    public Template createTypeCheckedModelTemplate(String source, String sourceName, Map<String,String> modelTypes) throws CompilationFailedException, ClassNotFoundException, IOException
    Compiles inline template source with explicit model type hints and a source name.
    Parameters:
      `source` - template source
      `sourceName` - source name used for diagnostics and generated classes
      `modelTypes` - model variable type hints keyed by variable name
    Returns:
      a compiled markup template
    Throws:
      `CompilationFailedException` - if Groovy fails to compile the generated template
      `ClassNotFoundException` - if the generated template class cannot be instantiated
      `IOException` - if reading the template source fails

  - ### createTypeCheckedModelTemplate

    public Template createTypeCheckedModelTemplate(Reader reader, Map<String,String> modelTypes) throws CompilationFailedException, ClassNotFoundException, IOException
    Compiles template source from a reader with explicit model type hints.
    Parameters:
      `reader` - template source
      `modelTypes` - model variable type hints keyed by variable name
    Returns:
      a compiled markup template
    Throws:
      `CompilationFailedException` - if Groovy fails to compile the generated template
      `ClassNotFoundException` - if the generated template class cannot be instantiated
      `IOException` - if reading the template source fails

  - ### createTypeCheckedModelTemplate

    public Template createTypeCheckedModelTemplate(Reader reader, String sourceName, Map<String,String> modelTypes) throws CompilationFailedException, ClassNotFoundException, IOException
    Compiles template source from a reader with explicit model type hints and a source name.
    Parameters:
      `reader` - template source
      `sourceName` - source name used for diagnostics and generated classes
      `modelTypes` - model variable type hints keyed by variable name
    Returns:
      a compiled markup template
    Throws:
      `CompilationFailedException` - if Groovy fails to compile the generated template
      `ClassNotFoundException` - if the generated template class cannot be instantiated
      `IOException` - if reading the template source fails

  - ### createTypeCheckedModelTemplateByPath

    public Template createTypeCheckedModelTemplateByPath(String templatePath, Map<String,String> modelTypes) throws CompilationFailedException, ClassNotFoundException, IOException
    Resolves and compiles a template by path with explicit model type hints.
    Parameters:
      `templatePath` - logical template path understood by the configured resolver
      `modelTypes` - model variable type hints keyed by variable name
    Returns:
      a compiled markup template
    Throws:
      `CompilationFailedException` - if Groovy fails to compile the generated template
      `ClassNotFoundException` - if the generated template class cannot be instantiated
      `IOException` - if template resolution or reading fails

  - ### createTemplate

    public Template createTemplate(URL resource) throws CompilationFailedException, ClassNotFoundException, IOException
    Compiles a template from a resolved resource URL.
    Overrides:
      `createTemplate` in class `TemplateEngine`
    Parameters:
      `resource` - template resource
    Returns:
      a compiled markup template
    Throws:
      `CompilationFailedException` - if Groovy fails to compile the generated template
      `ClassNotFoundException` - if the generated template class cannot be instantiated
      `IOException` - if loading the resource fails

  - ### createTypeCheckedModelTemplate

    public Template createTypeCheckedModelTemplate(URL resource, Map<String,String> modelTypes) throws CompilationFailedException, ClassNotFoundException, IOException
    Compiles a template from a resolved resource URL with explicit model type hints.
    Parameters:
      `resource` - template resource
      `modelTypes` - model variable type hints keyed by variable name
    Returns:
      a compiled markup template
    Throws:
      `CompilationFailedException` - if Groovy fails to compile the generated template
      `ClassNotFoundException` - if the generated template class cannot be instantiated
      `IOException` - if loading the resource fails

  - ### getTemplateLoader

    public GroovyClassLoader getTemplateLoader()
    Returns the class loader used to compile generated template classes.
    Returns:
      the template class loader

  - ### getCompilerConfiguration

    public CompilerConfiguration getCompilerConfiguration()
    Returns the Groovy compiler configuration used for generated template classes.
    Returns:
      the compiler configuration

  - ### getTemplateConfiguration

    public TemplateConfiguration getTemplateConfiguration()
    Returns the rendering configuration used by this engine.
    Returns:
      the template configuration

  - ### resolveTemplate

    public URL resolveTemplate(String templatePath) throws IOException
    Resolves a logical template path into a concrete resource URL.
    Parameters:
      `templatePath` - logical template path
    Returns:
      the resolved template resource
    Throws:
      `IOException` - if the template cannot be resolved