Package org.restlet.ext.freemarker
Class TemplateFilter
- java.lang.Object
-
- org.restlet.Restlet
-
- org.restlet.routing.Filter
-
- org.restlet.ext.freemarker.TemplateFilter
-
- All Implemented Interfaces:
org.restlet.Uniform
public class TemplateFilter extends org.restlet.routing.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 theEncoding.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
-
-
Constructor Summary
Constructors Constructor Description TemplateFilter()
Constructor.TemplateFilter(org.restlet.Context context)
Constructor.TemplateFilter(org.restlet.Context context, org.restlet.Restlet next)
Constructor.TemplateFilter(org.restlet.Context context, org.restlet.Restlet next, java.lang.Object dataModel)
Constructor.TemplateFilter(org.restlet.Context context, org.restlet.Restlet next, org.restlet.util.Resolver<java.lang.Object> dataModel)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
afterHandle(org.restlet.Request request, org.restlet.Response response)
protected java.lang.Object
createDataModel(org.restlet.Request request, org.restlet.Response response)
Creates the FreeMarker data model for a given call.freemarker.template.Configuration
getConfiguration()
Returns the FreeMarker configuration.java.lang.Object
getDataModel()
Returns the template data model common to all calls.void
setConfiguration(freemarker.template.Configuration config)
Sets the FreeMarker configuration.void
setDataModel(java.lang.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
-
-
-
-
Constructor Detail
-
TemplateFilter
public TemplateFilter()
Constructor.
-
TemplateFilter
public TemplateFilter(org.restlet.Context context)
Constructor.- Parameters:
context
- The context.
-
TemplateFilter
public TemplateFilter(org.restlet.Context context, org.restlet.Restlet next)
Constructor.- Parameters:
context
- The context.next
- The next Restlet.
-
TemplateFilter
public TemplateFilter(org.restlet.Context context, org.restlet.Restlet next, java.lang.Object dataModel)
Constructor.- Parameters:
context
- The context.next
- The next Restlet.dataModel
- The filter's data model.
-
TemplateFilter
public TemplateFilter(org.restlet.Context context, org.restlet.Restlet next, org.restlet.util.Resolver<java.lang.Object> dataModel)
Constructor.- Parameters:
context
- The context.next
- The next Restlet.dataModel
- The filter's data model.
-
-
Method Detail
-
afterHandle
protected void afterHandle(org.restlet.Request request, org.restlet.Response response)
- Overrides:
afterHandle
in classorg.restlet.routing.Filter
-
createDataModel
protected java.lang.Object createDataModel(org.restlet.Request request, org.restlet.Response response)
Creates the FreeMarker data model for a given call. By default, it will create aTemplateHashModel
based on the result ofResolver.createResolver(Request, Response)
. If thegetDataModel()
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 freemarker.template.Configuration getConfiguration()
Returns the FreeMarker configuration.- Returns:
- The FreeMarker configuration.
-
getDataModel
public java.lang.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(freemarker.template.Configuration config)
Sets the FreeMarker configuration.- Parameters:
config
- FreeMarker configuration.
-
setDataModel
public void setDataModel(java.lang.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.
-
-