org.restlet.ext.freemarker
Class TemplateFilter

java.lang.Object
  extended by org.restlet.Restlet
      extended by org.restlet.routing.Filter
          extended by org.restlet.ext.freemarker.TemplateFilter
All Implemented Interfaces:
Uniform

public class TemplateFilter
extends Filter

Filter response's entity and wrap it with a FreeMarker's template representation. By default, the template representation provides a data model based on the request and response objects. In order for the wrapping to happen, the representations must have the Encoding.FREEMARKER encoding set.

Concurrency note: instances of this class or its subclasses can be invoked by several threads at the same time and therefore must be thread-safe. You should be especially careful when storing state in member variables.

Author:
Thierry Boileau

Field Summary
 
Fields inherited from class org.restlet.routing.Filter
CONTINUE, SKIP, STOP
 
Constructor Summary
TemplateFilter()
          Constructor.
TemplateFilter(Context context)
          Constructor.
TemplateFilter(Context context, Restlet next)
          Constructor.
TemplateFilter(Context context, Restlet next, Object dataModel)
          Constructor.
TemplateFilter(Context context, Restlet next, Resolver<Object> dataModel)
          Constructor.
 
Method Summary
protected  void afterHandle(Request request, Response response)
           
protected  Object createDataModel(Request request, Response response)
          Creates the FreeMarker data model for a given call.
 Configuration getConfiguration()
          Returns the FreeMarker configuration.
 Object getDataModel()
          Returns the template data model common to all calls.
 void setConfiguration(Configuration config)
          Sets the FreeMarker configuration.
 void setDataModel(Object dataModel)
          Sets the template data model common to all calls.
 
Methods inherited from class org.restlet.routing.Filter
beforeHandle, doHandle, getNext, handle, hasNext, setNext, setNext, start, stop
 
Methods inherited from class org.restlet.Restlet
createFinder, finalize, getApplication, getAuthor, getContext, getDescription, getFinderClass, getLogger, getName, getOwner, handle, handle, handle, isStarted, isStopped, setAuthor, setContext, setDescription, setFinderClass, setName, setOwner
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TemplateFilter

public TemplateFilter()
Constructor.


TemplateFilter

public TemplateFilter(Context context)
Constructor.

Parameters:
context - The context.

TemplateFilter

public TemplateFilter(Context context,
                      Restlet next)
Constructor.

Parameters:
context - The context.
next - The next Restlet.

TemplateFilter

public TemplateFilter(Context context,
                      Restlet next,
                      Object dataModel)
Constructor.

Parameters:
context - The context.
next - The next Restlet.
dataModel - The filter's data model.

TemplateFilter

public TemplateFilter(Context context,
                      Restlet next,
                      Resolver<Object> dataModel)
Constructor.

Parameters:
context - The context.
next - The next Restlet.
dataModel - The filter's data model.
Method Detail

afterHandle

protected void afterHandle(Request request,
                           Response response)
Overrides:
afterHandle in class Filter

createDataModel

protected Object createDataModel(Request request,
                                 Response response)
Creates the FreeMarker data model for a given call. By default, it will create a TemplateHashModel based on the result of Resolver.createResolver(Request, Response). If the getDataModel() method has a non null value, it will be used.

Parameters:
request - The handled request.
response - The handled response.
Returns:
The FreeMarker data model for the given call.

getConfiguration

public Configuration getConfiguration()
Returns the FreeMarker configuration.

Returns:
The FreeMarker configuration.

getDataModel

public Object getDataModel()
Returns the template data model common to all calls. If each call should have a specific model, you should set this property to null.

Returns:
The template data model common to all calls.

setConfiguration

public void setConfiguration(Configuration config)
Sets the FreeMarker configuration.

Parameters:
config - FreeMarker configuration.

setDataModel

public void setDataModel(Object dataModel)
Sets the template data model common to all calls. If each call should have a specific model, you should set this property to null.

Parameters:
dataModel - The template data model common to all calls.


Copyright © 2005-2013 Restlet.