Groovy Documentation

org.codehaus.groovy.grails.web.pages
[Java] Class GroovyPagesTemplateEngine

java.lang.Object
  groovy.text.TemplateEngine
      org.codehaus.groovy.grails.support.ResourceAwareTemplateEngine
          org.codehaus.groovy.grails.web.pages.GroovyPagesTemplateEngine
All Implemented Interfaces:
org.springframework.context.ApplicationContextAware, org.springframework.web.context.ServletContextAware, org.springframework.beans.factory.InitializingBean

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
static java.lang.String BEAN_ID

static java.lang.String CONFIG_PROPERTY_DISABLE_CACHING_RESOURCES

static java.lang.String CONFIG_PROPERTY_GSP_ENABLE_RELOAD

 
Constructor Summary
GroovyPagesTemplateEngine()

GroovyPagesTemplateEngine(javax.servlet.ServletContext servletContext)

@param servletContext The servlet context

 
Method Summary
void afterPropertiesSet()

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

int[] calculateLineNumbersForPage(javax.servlet.ServletContext context, 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

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()

Creates a Template for the currently executing Request

groovy.text.Template createTemplate(java.io.File file)

groovy.text.Template createTemplate(java.net.URL url)

groovy.text.Template createTemplate(java.io.InputStream inputStream)

protected groovy.text.Template createTemplate(java.io.InputStream inputStream, org.springframework.core.io.Resource resource, java.lang.String pageName)

Constructs a Groovy Template from the given InputStream and Spring Resource object

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 res, java.lang.String pageName)

GroovyPageScriptSource findScriptSource(java.lang.String uri)

GroovyPageScriptSource findScriptSource(java.lang.String[] uris)

protected java.lang.String getCurrentRequestUri(javax.servlet.http.HttpServletRequest request)

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

java.util.Map getDomainClassMap()

GroovyPageLocator getGroovyPageLocator()

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

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

boolean isCacheResources()

boolean isReloadEnabled()

Sets whether reloading is enabled

void setApplicationContext(org.springframework.context.ApplicationContext applicationContext)

void setCacheResources(boolean cacheResources)

void setClassLoader(java.lang.ClassLoader classLoader)

Sets the ClassLoader that the TemplateEngine should use to

void setGroovyPageLocator(GroovyPageLocator groovyPageLocator)

void setJspTagLibraryResolver(TagLibraryResolver jspTagLibraryResolver)

void setReloadEnabled(boolean b)

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

void setResourceLoader(org.springframework.core.io.ResourceLoader resourceLoader)

void setServletContext(javax.servlet.ServletContext servletContext)

void setTagLibraryLookup(TagLibraryLookup tagLibraryLookup)

 
Methods inherited from class ResourceAwareTemplateEngine
createTemplate, createTemplate, createTemplate, createTemplate, createTemplate, createTemplate, createTemplate
 
Methods inherited from class groovy.text.TemplateEngine
groovy.text.TemplateEngine#createTemplate(java.net.URL), groovy.text.TemplateEngine#createTemplate(java.io.File), groovy.text.TemplateEngine#createTemplate(java.lang.String), groovy.text.TemplateEngine#createTemplate(java.io.Reader), groovy.text.TemplateEngine#wait(), groovy.text.TemplateEngine#wait(long, int), groovy.text.TemplateEngine#wait(long), 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

BEAN_ID

public static final java.lang.String BEAN_ID


CONFIG_PROPERTY_DISABLE_CACHING_RESOURCES

public static final java.lang.String CONFIG_PROPERTY_DISABLE_CACHING_RESOURCES


CONFIG_PROPERTY_GSP_ENABLE_RELOAD

public static final java.lang.String CONFIG_PROPERTY_GSP_ENABLE_RELOAD


 
Constructor Detail

GroovyPagesTemplateEngine

public GroovyPagesTemplateEngine()


GroovyPagesTemplateEngine

public GroovyPagesTemplateEngine(ServletContext servletContext) {
public GroovyPagesTemplateEngine(javax.servlet.ServletContext servletContext)
deprecated:
here for compatibility
Parameters:
servletContext - The servlet context


 
Method Detail

afterPropertiesSet

public void afterPropertiesSet()


buildPageMetaInfo

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


calculateLineNumbersForPage

public int[] calculateLineNumbersForPage( javax.servlet.ServletContext context, 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:
context - The ServletContext instance
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


clearPageCache

public void clearPageCache()
Clears the page cache. Views will be re-compiled.


createTemplate

return createTemplate(resource, cacheResources);
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


createTemplate

if (resource == null) {
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


createTemplate

if (isReloadEnabled()) {
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


createTemplate

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


createTemplate

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


createTemplate

public groovy.text.Template createTemplate()
Creates a Template for the currently executing Request
throws:
java.io.IOException Thrown when an exception occurs Reading the Template
throws:
ClassNotFoundException Thrown when the class of the template was not found
Returns:
The Template for the currently executing request


createTemplate

* @param url The URL to use to construct the template with
public groovy.text.Template createTemplate(java.io.File file)


createTemplate

* @return The Template instance
public groovy.text.Template createTemplate(java.net.URL url)


createTemplate

*
public groovy.text.Template createTemplate(java.io.InputStream inputStream)


createTemplate

protected groovy.text.Template createTemplate(java.io.InputStream inputStream, org.springframework.core.io.Resource resource, java.lang.String pageName)
Constructs a Groovy Template from the given InputStream and Spring Resource object
Parameters:
inputStream - The InputStream to use
resource - The Resource to use
pageName - The name of the page
Returns:
The Groovy Template


createTemplateForUri

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


createTemplateForUri

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


establishPageName

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


findScriptSource

public GroovyPageScriptSource findScriptSource(java.lang.String uri)


findScriptSource

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


getCurrentRequestUri

protected java.lang.String getCurrentRequestUri(javax.servlet.http.HttpServletRequest request)
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


getDomainClassMap

public java.util.Map getDomainClassMap()


getGroovyPageLocator

public GroovyPageLocator getGroovyPageLocator()


getResourceForUri

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


getUriWithinGrailsViews

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


isCacheResources

public boolean isCacheResources()


isReloadEnabled

public boolean isReloadEnabled()
Sets whether reloading is enabled
Parameters:
b - True if it is enabled


setApplicationContext

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


setCacheResources

public void setCacheResources(boolean cacheResources)


setClassLoader

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


setGroovyPageLocator

public void setGroovyPageLocator(GroovyPageLocator groovyPageLocator)


setJspTagLibraryResolver

public void setJspTagLibraryResolver(TagLibraryResolver jspTagLibraryResolver)


setReloadEnabled

public void setReloadEnabled(boolean b)
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


setResourceLoader

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


setServletContext

public void setServletContext(javax.servlet.ServletContext servletContext)


setTagLibraryLookup

public void setTagLibraryLookup(TagLibraryLookup tagLibraryLookup)


 

Groovy Documentation