Package: groovy.text.markup

## [Java] Class MarkupTemplateEngine

- groovy.text.markup.MarkupTemplateEngine

-     public class MarkupTemplateEngine
      extends TemplateEngine

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

- - ### Nested Class Summary

    Nested classes
    Modifiers | Name | Description
    --- | --- | ---
    `static class` | `MarkupTemplateEngine.CachingTemplateResolver` | A template resolver which avoids calling ClassLoader.getResource 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 and 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

  - ### Methods Summary

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

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class TemplateEngine` | `createTemplate, createTemplate, createTemplate, createTemplate, createTemplate, createTemplate`

- - ### Constructor Detail

    - #### public MarkupTemplateEngine()

      Creates an engine with the default TemplateConfiguration.

    - #### public MarkupTemplateEngine(TemplateConfiguration config)

      Creates an engine with the supplied template configuration.

      Parameters:
        `config` - template configuration to apply while compiling and rendering templates

    - #### 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

    - #### 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

    - #### 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 Detail

    - #### public Template createTemplate(Reader reader)

      Compiles a template from a reader.

      throws:
        CompilationFailedException if Groovy fails to compile the generated template
      throws:
        ClassNotFoundException if the generated template class cannot be instantiated
      throws:
        IOException if reading the template source fails
      Parameters:
        `reader` - template source
      Returns:
        a compiled markup template

    - #### public Template createTemplate(Reader reader, String sourceName)

      Compiles a template from a reader using an explicit source name.

      throws:
        CompilationFailedException if Groovy fails to compile the generated template
      throws:
        ClassNotFoundException if the generated template class cannot be instantiated
      throws:
        IOException if reading the template source fails
      Parameters:
        `reader` - template source
        `sourceName` - source name used for diagnostics and generated classes
      Returns:
        a compiled markup template

    - #### public Template createTemplate(URL resource)

      Compiles a template from a resolved resource URL.

      throws:
        CompilationFailedException if Groovy fails to compile the generated template
      throws:
        ClassNotFoundException if the generated template class cannot be instantiated
      throws:
        IOException if loading the resource fails
      Parameters:
        `resource` - template resource
      Returns:
        a compiled markup template

    - #### public Template createTemplateByPath(String templatePath)

      Resolves and compiles a template by path.

      throws:
        CompilationFailedException if Groovy fails to compile the generated template
      throws:
        ClassNotFoundException if the generated template class cannot be instantiated
      throws:
        IOException if template resolution or reading fails
      Parameters:
        `templatePath` - logical template path understood by the configured resolver
      Returns:
        a compiled markup template

    - #### public Template createTypeCheckedModelTemplate(String source, Map<String, String> modelTypes)

      Compiles inline template source with explicit model type hints.

      throws:
        CompilationFailedException if Groovy fails to compile the generated template
      throws:
        ClassNotFoundException if the generated template class cannot be instantiated
      throws:
        IOException if reading the template source fails
      Parameters:
        `source` - template source
        `modelTypes` - model variable type hints keyed by variable name
      Returns:
        a compiled markup template

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

      Compiles inline template source with explicit model type hints and a source name.

      throws:
        CompilationFailedException if Groovy fails to compile the generated template
      throws:
        ClassNotFoundException if the generated template class cannot be instantiated
      throws:
        IOException if reading the template source fails
      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

    - #### public Template createTypeCheckedModelTemplate(Reader reader, Map<String, String> modelTypes)

      Compiles template source from a reader with explicit model type hints.

      throws:
        CompilationFailedException if Groovy fails to compile the generated template
      throws:
        ClassNotFoundException if the generated template class cannot be instantiated
      throws:
        IOException if reading the template source fails
      Parameters:
        `reader` - template source
        `modelTypes` - model variable type hints keyed by variable name
      Returns:
        a compiled markup template

    - #### public 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.

      throws:
        CompilationFailedException if Groovy fails to compile the generated template
      throws:
        ClassNotFoundException if the generated template class cannot be instantiated
      throws:
        IOException if reading the template source fails
      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

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

      Compiles a template from a resolved resource URL with explicit model type hints.

      throws:
        CompilationFailedException if Groovy fails to compile the generated template
      throws:
        ClassNotFoundException if the generated template class cannot be instantiated
      throws:
        IOException if loading the resource fails
      Parameters:
        `resource` - template resource
        `modelTypes` - model variable type hints keyed by variable name
      Returns:
        a compiled markup template

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

      Resolves and compiles a template by path with explicit model type hints.

      throws:
        CompilationFailedException if Groovy fails to compile the generated template
      throws:
        ClassNotFoundException if the generated template class cannot be instantiated
      throws:
        IOException if template resolution or reading fails
      Parameters:
        `templatePath` - logical template path understood by the configured resolver
        `modelTypes` - model variable type hints keyed by variable name
      Returns:
        a compiled markup template

    - #### public CompilerConfiguration getCompilerConfiguration()

      Returns the Groovy compiler configuration used for generated template classes.

      Returns:
        the compiler configuration

    - #### public TemplateConfiguration getTemplateConfiguration()

      Returns the rendering configuration used by this engine.

      Returns:
        the template configuration

    - #### public GroovyClassLoader getTemplateLoader()

      Returns the class loader used to compile generated template classes.

      Returns:
        the template class loader

    - #### public URL resolveTemplate(String templatePath)

      Resolves a logical template path into a concrete resource URL.

      throws:
        IOException if the template cannot be resolved
      Parameters:
        `templatePath` - logical template path
      Returns:
        the resolved template resource