Package: org.grails.gsp

## [Java] Class GroovyPagesTemplateEngine

- org.grails.gsp.GroovyPagesTemplateEngine

- All Implemented Interfaces and Traits:
    org.springframework.context.ResourceLoaderAware, org.springframework.context.ApplicationContextAware, org.springframework.beans.factory.InitializingBean, org.springframework.beans.factory.BeanClassLoaderAware

      public class GroovyPagesTemplateEngine
      extends ResourceAwareTemplateEngine

  Based on (but not extending) the existing TemplateEngine implementations within Groovy. It allows GSP pages to be re-used in different context using code like the below: `Template t = new GroovyPagesTemplateEngine() .createTemplate(context,request,response); t.make() .writeTo(out);`

  Authors:
    Graeme Rocher
    Lari Hotari
  Since:
    0.1

- - ### Field Summary

    Fields
    Modifiers | Name | Description
    --- | --- | ---
    `static java.lang.String` | `BEAN_ID` |
    `static java.lang.String` | `CONFIG_PROPERTY_DISABLE_CACHING_RESOURCES` |
    `static java.lang.String` | `CONFIG_PROPERTY_GSP_ENABLE_RELOAD` |

  - Inherited fields
    Fields inherited from class | Fields
    --- | ---
    `class ResourceAwareTemplateEngine` | `BEAN_ID`

  - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `java.lang.Object` | `GroovyPagesTemplateEngine()`
    `` | `void` | `afterPropertiesSet()`
    `` | `protected GroovyPageMetaInfo` | `buildPageMetaInfo(org.springframework.core.io.Resource resource, java.lang.String pageName)`
    `` | `protected GroovyPageMetaInfo` | `buildPageMetaInfo(java.io.InputStream inputStream, org.springframework.core.io.Resource res, java.lang.String pageName)` Constructs a GroovyPageMetaInfo instance which holds the script class, modified date and so on
    `` | `int[]` | `calculateLineNumbersForPage(java.lang.String url)` Retrieves a line number matrix for the specified page that can be used to retrieve the actual line number within the GSP page if the line number within the compiled GSP is known
    `` | `void` | `clearPageCache()` Clears the page cache.
    `` | `groovy.text.Template` | `createTemplate(org.springframework.core.io.Resource resource)` Creates a Template for the given Spring Resource instance
    `` | `groovy.text.Template` | `createTemplate(org.springframework.core.io.Resource resource, boolean cacheable)` Creates a Template for the given Spring Resource instance
    `` | `protected groovy.text.Template` | `createTemplate(org.springframework.core.io.Resource resource, java.lang.String pageName, boolean cacheable)`
    `` | `groovy.text.Template` | `createTemplate(java.lang.String uri)` Creates a Template using the given URI.
    `` | `groovy.text.Template` | `createTemplate(org.springframework.scripting.ScriptSource scriptSource)`
    `` | `groovy.text.Template` | `createTemplate(java.lang.String txt, java.lang.String pageName)` Creates a Template using the given text for the Template and the given name.
    `` | `groovy.text.Template` | `createTemplate(java.io.File file)` Creates a Template for the given file
    `` | `groovy.text.Template` | `createTemplate(java.net.URL url)` Creates a Template for the given URL
    `` | `groovy.text.Template` | `createTemplate(java.io.InputStream inputStream)` Create a Template for the given InputStream
    `` | `groovy.text.Template` | `createTemplateForUri(java.lang.String uri)`
    `` | `groovy.text.Template` | `createTemplateForUri(java.lang.String[] uris)`
    `` | `protected java.lang.String` | `establishPageName(org.springframework.core.io.Resource resource, boolean cacheable)`
    `` | `protected java.lang.String` | `establishPageName(org.springframework.core.io.Resource res, java.lang.String pageName)` Establishes the name to use for the given resource
    `` | `GroovyPageScriptSource` | `findScriptSource(java.lang.String uri)`
    `` | `GroovyPageScriptSource` | `findScriptSource(java.lang.String[] uris)`
    `` | `java.util.Map<java.lang.String, java.lang.Class<?>>` | `getDomainClassMap()`
    `` | `GroovyPageLocator` | `getGroovyPageLocator()`
    `` | `java.util.List<GroovyPageSourceDecorator>` | `getGroovyPageSourceDecorators()`
    `` | `java.lang.String` | `getGspEncoding()`
    `` | `org.springframework.core.io.Resource` | `getResourceForUri(java.lang.String uri)` Attempts to retrieve a reference to a GSP as a Spring Resource instance for the given URI.
    `` | `protected java.lang.String` | `getUriWithinGrailsViews(java.lang.String relativeUri)` Returns the path to the view of the relative URI within the Grails views directory
    `` | `boolean` | `isCacheResources()`
    `` | `boolean` | `isReloadEnabled()` Return whether reload is enabled for the GroovyPagesTemplateEngine
    `` | `int` | `mapStackLineNumber(java.lang.String url, int lineNumber)`
    `` | `void` | `setApplicationContext(org.springframework.context.ApplicationContext applicationContext)` Sets the ResourceLoader from the ApplicationContext
    `` | `void` | `setBeanClassLoader(java.lang.ClassLoader beanClassLoader)`
    `` | `void` | `setCacheResources(boolean cacheResources)`
    `` | `void` | `setClassLoader(java.lang.ClassLoader classLoader)` Sets the ClassLoader that the TemplateEngine should use to
    `` | `void` | `setGroovyPageLocator(GroovyPageLocator groovyPageLocator)`
    `` | `void` | `setGroovyPageSourceDecorators(java.util.List<GroovyPageSourceDecorator> groovyPageSourceDecorators)`
    `` | `void` | `setJspTagLibraryResolver(TagLibraryResolver jspTagLibraryResolver)`
    `` | `void` | `setReloadEnabled(boolean b)` Sets whether reloading is enabled
    `` | `void` | `setResourceLoader(org.springframework.core.io.ResourceLoader resourceLoader)`
    `` | `void` | `setTagLibraryLookup(TagLibraryLookup tagLibraryLookup)`

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class ResourceAwareTemplateEngine` | `createTemplate, createTemplate, createTemplate, createTemplate, createTemplate, createTemplate, createTemplate, createTemplateForUri, mapStackLineNumber`
    `class groovy.text.TemplateEngine` | `groovy.text.TemplateEngine#createTemplate(java.io.File), groovy.text.TemplateEngine#createTemplate(java.net.URL), groovy.text.TemplateEngine#createTemplate(java.io.Reader), groovy.text.TemplateEngine#createTemplate(java.lang.String), groovy.text.TemplateEngine#wait(long, int), groovy.text.TemplateEngine#wait(long), groovy.text.TemplateEngine#wait(), groovy.text.TemplateEngine#equals(java.lang.Object), groovy.text.TemplateEngine#toString(), groovy.text.TemplateEngine#hashCode(), groovy.text.TemplateEngine#getClass(), groovy.text.TemplateEngine#notify(), groovy.text.TemplateEngine#notifyAll()`

- - ### Field Detail

    - #### public static final java.lang.String BEAN_ID

    - #### public static final java.lang.String CONFIG_PROPERTY_DISABLE_CACHING_RESOURCES

    - #### public static final java.lang.String CONFIG_PROPERTY_GSP_ENABLE_RELOAD

  - ### Method Detail

    - #### public java.lang.Object GroovyPagesTemplateEngine()

    - #### public void afterPropertiesSet()

    - #### protected GroovyPageMetaInfo buildPageMetaInfo(org.springframework.core.io.Resource resource, java.lang.String pageName)

    - #### protected GroovyPageMetaInfo buildPageMetaInfo(java.io.InputStream inputStream, org.springframework.core.io.Resource res, java.lang.String pageName)

      Constructs a GroovyPageMetaInfo instance which holds the script class, modified date and so on

      Parameters:
        `inputStream` - The InputStream to construct the GroovyPageMetaInfo instance from
        `res` - The Spring Resource to construct the MetaInfo from
        `pageName` - The name of the page (can be null, in which case method responsible for calculating appropriate alternative)
      Returns:
        The GroovyPageMetaInfo instance

    - #### public int[] calculateLineNumbersForPage(java.lang.String url)

      Retrieves a line number matrix for the specified page that can be used to retrieve the actual line number within the GSP page if the line number within the compiled GSP is known

      Parameters:
        `url` - The URL of the page
      Returns:
        An array where the index is the line number witin the compiled GSP and the value is the line number within the source

    - #### public void clearPageCache()

      Clears the page cache. Views will be re-compiled.

    - #### @java.lang.Override public groovy.text.Template createTemplate(org.springframework.core.io.Resource resource)

      Creates a Template for the given Spring Resource instance

      Parameters:
        `resource` - The Resource to create the Template for
      Returns:
        The Template instance

    - #### @java.lang.Override public groovy.text.Template createTemplate(org.springframework.core.io.Resource resource, boolean cacheable)

      Creates a Template for the given Spring Resource instance

      Parameters:
        `resource` - The Resource to create the Template for
        `cacheable` - The resource can be cached or not
      Returns:
        The Template instance

    - #### protected groovy.text.Template createTemplate(org.springframework.core.io.Resource resource, java.lang.String pageName, boolean cacheable)

    - #### @java.lang.Override public groovy.text.Template createTemplate(java.lang.String uri)

      Creates a Template using the given URI.

      throws:
        CompilationFailedException
      Parameters:
        `uri` - The URI of the page to create the template for
      Returns:
        The Template instance

    - #### public groovy.text.Template createTemplate(org.springframework.scripting.ScriptSource scriptSource)

    - #### public groovy.text.Template createTemplate(java.lang.String txt, java.lang.String pageName)

      Creates a Template using the given text for the Template and the given name. The name of the template is required

      throws:
        CompilationFailedException
      throws:
        IOException Thrown if an IO exception occurs creating the Template
      Parameters:
        `txt` - The URI of the page to create the template for
        `pageName` - The name of the page being parsed
      Returns:
        The Template instance

    - #### @java.lang.Override public groovy.text.Template createTemplate(java.io.File file)

      Creates a Template for the given file

      throws:
        CompilationFailedException When an error occured compiling the Template
      throws:
        ClassNotFoundException When a Class cannot be found within the given Template
      throws:
        IOException When a I/O Exception occurs reading the Template
      Parameters:
        `file` - The File to use to construct the template with
      Returns:
        A Groovy Template instance

    - #### @java.lang.Override public groovy.text.Template createTemplate(java.net.URL url)

      Creates a Template for the given URL

      throws:
        CompilationFailedException When an error occured compiling the Template
      throws:
        ClassNotFoundException When a Class cannot be found within the given Template
      throws:
        IOException When a I/O Exception occurs reading the Template
      Parameters:
        `url` - The URL to use to construct the template with
      Returns:
        A Groovy Template instance

    - #### @java.lang.Override public groovy.text.Template createTemplate(java.io.InputStream inputStream)

      Create a Template for the given InputStream

      Parameters:
        `inputStream` - The InputStream to create the Template for
      Returns:
        The Template instance

    - #### public groovy.text.Template createTemplateForUri(java.lang.String uri)

    - #### public groovy.text.Template createTemplateForUri(java.lang.String[] uris)

    - #### protected java.lang.String establishPageName(org.springframework.core.io.Resource resource, boolean cacheable)

    - #### protected java.lang.String establishPageName(org.springframework.core.io.Resource res, java.lang.String pageName)

      Establishes the name to use for the given resource

      Parameters:
        `res` - The Resource to calculate the name for
        `pageName` - The name of the page, can be null, in which case method responsible for calculation
      Returns:
        The name as a String

    - #### public GroovyPageScriptSource findScriptSource(java.lang.String uri)

    - #### public GroovyPageScriptSource findScriptSource(java.lang.String[] uris)

    - #### public java.util.Map<java.lang.String, java.lang.Class<?>> getDomainClassMap()

    - #### public GroovyPageLocator getGroovyPageLocator()

    - #### public java.util.List<GroovyPageSourceDecorator> getGroovyPageSourceDecorators()

    - #### public java.lang.String getGspEncoding()

    - #### public org.springframework.core.io.Resource getResourceForUri(java.lang.String uri)

      Attempts to retrieve a reference to a GSP as a Spring Resource instance for the given URI.

      Parameters:
        `uri` - The URI to check
      Returns:
        A Resource instance

    - #### protected java.lang.String getUriWithinGrailsViews(java.lang.String relativeUri)

      Returns the path to the view of the relative URI within the Grails views directory

      Parameters:
        `relativeUri` - The relative URI
      Returns:
        The path of the URI within the Grails view directory

    - #### public boolean isCacheResources()

    - #### public boolean isReloadEnabled()

      Return whether reload is enabled for the GroovyPagesTemplateEngine

      Returns:
        true if it is

    - #### public int mapStackLineNumber(java.lang.String url, int lineNumber)

    - #### public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext)

      Sets the ResourceLoader from the ApplicationContext

      throws:
        BeansException Thrown when an error occurs with the ApplicationContext
      Parameters:
        `applicationContext` - The ApplicationContext

    - #### @java.lang.Override public void setBeanClassLoader(java.lang.ClassLoader beanClassLoader)

    - #### public void setCacheResources(boolean cacheResources)

    - #### public void setClassLoader(java.lang.ClassLoader classLoader)

      Sets the ClassLoader that the TemplateEngine should use to

      Parameters:
        `classLoader` - The ClassLoader to use when compilation of Groovy Pages occurs

    - #### public void setGroovyPageLocator(GroovyPageLocator groovyPageLocator)

    - #### public void setGroovyPageSourceDecorators(java.util.List<GroovyPageSourceDecorator> groovyPageSourceDecorators)

    - #### public void setJspTagLibraryResolver(TagLibraryResolver jspTagLibraryResolver)

    - #### public void setReloadEnabled(boolean b)

      Sets whether reloading is enabled

      Parameters:
        `b` - True if it is enabled

    - #### public void setResourceLoader(org.springframework.core.io.ResourceLoader resourceLoader)

    - #### public void setTagLibraryLookup(TagLibraryLookup tagLibraryLookup)