info.magnolia.freemarker
Class FreemarkerHelper

java.lang.Object
  extended by info.magnolia.freemarker.FreemarkerHelper

public class FreemarkerHelper
extends java.lang.Object

A generic helper to render Content instances with Freemarker templates. Is used to render both paragraphs and templates. TODO : expose Configuration#clearTemplateCache()

Version:
$Revision: $ ($Author: $)
Author:
gjoseph

Constructor Summary
FreemarkerHelper()
           
FreemarkerHelper(FreemarkerConfig freemarkerConfig)
           
 
Method Summary
protected  void addDefaultData(java.util.Map<java.lang.String,java.lang.Object> data, java.util.Locale locale, java.lang.String i18nBasename)
           
protected  void addTaglibSupportData(java.util.Map<java.lang.String,java.lang.Object> data, WebContext webCtx)
           
protected  java.util.Locale checkLocale(java.util.Locale locale)
          Returns the passed Locale if non-null, otherwise attempts to get the Locale from the current context.
protected  freemarker.ext.servlet.ServletContextHashModel checkServletContextModel(javax.servlet.ServletContext servletContext)
           
protected  freemarker.ext.jsp.TaglibFactory checkTaglibFactory(javax.servlet.ServletContext servletContext)
           
protected  freemarker.template.Configuration getConfiguration()
           
static FreemarkerHelper getInstance()
           
protected  void prepareRendering(java.util.Locale checkedLocale, java.lang.String i18nBasename, java.lang.Object root)
          Call checkLocale() before calling this method, to ensure it is not null.
protected  void render(java.io.Reader template, java.util.Locale locale, java.lang.String i18nBasename, java.lang.Object root, java.io.Writer out)
           
 void render(java.io.Reader template, java.lang.Object root, java.io.Writer out)
          Renders the template read by the given Reader instance.
 void render(java.lang.String templatePath, java.util.Locale locale, java.lang.String i18nBasename, java.lang.Object root, java.io.Writer out)
          Renders the given template, using the given root object (can be a map, or any other type of object handled by MagnoliaContentWrapper) to the given Writer.
 void render(java.lang.String templatePath, java.lang.Object root, java.io.Writer out)
           
 void resetObjectWrapper()
          Deprecated. not needed anymore since 4.3
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FreemarkerHelper

public FreemarkerHelper()

FreemarkerHelper

public FreemarkerHelper(FreemarkerConfig freemarkerConfig)
Method Detail

getInstance

public static FreemarkerHelper getInstance()

resetObjectWrapper

public void resetObjectWrapper()
Deprecated. not needed anymore since 4.3


render

public void render(java.lang.String templatePath,
                   java.lang.Object root,
                   java.io.Writer out)
            throws freemarker.template.TemplateException,
                   java.io.IOException
Throws:
freemarker.template.TemplateException
java.io.IOException
See Also:
render(String, Locale, String, Object, java.io.Writer)

render

public void render(java.lang.String templatePath,
                   java.util.Locale locale,
                   java.lang.String i18nBasename,
                   java.lang.Object root,
                   java.io.Writer out)
            throws freemarker.template.TemplateException,
                   java.io.IOException
Renders the given template, using the given root object (can be a map, or any other type of object handled by MagnoliaContentWrapper) to the given Writer. If the root is an instance of a Map, the following elements are added to it: - ctx, the current Context instance retrieved from MgnlContext - contextPath, if we have an available WebContext (@deprecated) - defaultBaseUrl, as per Server.getDefaultBaseUrl()

Throws:
freemarker.template.TemplateException
java.io.IOException
See Also:
ServerConfiguration.getDefaultBaseUrl()

render

public void render(java.io.Reader template,
                   java.lang.Object root,
                   java.io.Writer out)
            throws freemarker.template.TemplateException,
                   java.io.IOException
Renders the template read by the given Reader instance. It should be noted that this method completely bypasses Freemarker's caching mechanism. The template will be parsed everytime, which might have a performance impact.

Throws:
freemarker.template.TemplateException
java.io.IOException
See Also:
render(Reader, Locale, String, Object, Writer)

render

protected void render(java.io.Reader template,
                      java.util.Locale locale,
                      java.lang.String i18nBasename,
                      java.lang.Object root,
                      java.io.Writer out)
               throws freemarker.template.TemplateException,
                      java.io.IOException
Throws:
freemarker.template.TemplateException
java.io.IOException

checkLocale

protected java.util.Locale checkLocale(java.util.Locale locale)
Returns the passed Locale if non-null, otherwise attempts to get the Locale from the current context.


prepareRendering

protected void prepareRendering(java.util.Locale checkedLocale,
                                java.lang.String i18nBasename,
                                java.lang.Object root)
Call checkLocale() before calling this method, to ensure it is not null.


addDefaultData

protected void addDefaultData(java.util.Map<java.lang.String,java.lang.Object> data,
                              java.util.Locale locale,
                              java.lang.String i18nBasename)

addTaglibSupportData

protected void addTaglibSupportData(java.util.Map<java.lang.String,java.lang.Object> data,
                                    WebContext webCtx)

checkTaglibFactory

protected freemarker.ext.jsp.TaglibFactory checkTaglibFactory(javax.servlet.ServletContext servletContext)

checkServletContextModel

protected freemarker.ext.servlet.ServletContextHashModel checkServletContextModel(javax.servlet.ServletContext servletContext)
                                                                           throws javax.servlet.ServletException
Throws:
javax.servlet.ServletException

getConfiguration

protected freemarker.template.Configuration getConfiguration()


Copyright © 2003-2011 Magnolia International Ltd.. All Rights Reserved.