Class 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 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

      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
      • 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​(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 class org.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 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 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.