Class TemplateRepresentation


  • public class TemplateRepresentation
    extends org.restlet.representation.WriterRepresentation
    FreeMarker template representation. Useful for dynamic string-based representations.
    Author:
    Jerome Louvel
    See Also:
    FreeMarker home page
    • Field Summary

      • Fields inherited from class org.restlet.representation.Representation

        UNKNOWN_SIZE
    • Constructor Summary

      Constructors 
      Constructor Description
      TemplateRepresentation​(freemarker.template.Template template, java.lang.Object dataModel, org.restlet.data.MediaType mediaType)
      Constructor.
      TemplateRepresentation​(freemarker.template.Template template, org.restlet.data.MediaType mediaType)
      Constructor.
      TemplateRepresentation​(java.lang.String templateName, freemarker.template.Configuration config, java.lang.Object dataModel, org.restlet.data.MediaType mediaType)
      Constructor.
      TemplateRepresentation​(java.lang.String templateName, freemarker.template.Configuration config, org.restlet.data.MediaType mediaType)
      Constructor.
      TemplateRepresentation​(org.restlet.representation.Representation templateRepresentation, freemarker.template.Configuration config, java.lang.Object dataModel, org.restlet.data.MediaType mediaType)
      Constructor.
      TemplateRepresentation​(org.restlet.representation.Representation templateRepresentation, freemarker.template.Configuration config, org.restlet.data.MediaType mediaType)
      Constructor.
      TemplateRepresentation​(org.restlet.representation.Representation templateRepresentation, java.lang.Object dataModel, org.restlet.data.MediaType mediaType)
      Constructor.
      TemplateRepresentation​(org.restlet.representation.Representation templateRepresentation, org.restlet.data.MediaType mediaType)
      Constructor.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.Object getDataModel()
      Returns the template's data model.
      freemarker.template.Template getTemplate()
      Returns the FreeMarker template.
      static freemarker.template.Template getTemplate​(freemarker.template.Configuration config, java.lang.String templateName)
      Returns a FreeMarker template from its name and a configuration.
      static freemarker.template.Template getTemplate​(freemarker.template.Configuration config, org.restlet.representation.Representation templateRepresentation)
      Returns a FreeMarker template from a representation and a configuration.
      java.lang.Object setDataModel​(java.lang.Object dataModel)
      Sets the template's data model.
      java.lang.Object setDataModel​(org.restlet.Request request, org.restlet.Response response)
      Sets the template's data model from a request/response pair.
      java.lang.Object setDataModel​(org.restlet.util.Resolver<java.lang.Object> resolver)
      Sets the template's data model from a resolver.
      void setTemplate​(freemarker.template.Template template)
      Sets the FreeMarker template.
      void write​(java.io.Writer writer)
      Writes the datum as a stream of characters.
      • Methods inherited from class org.restlet.representation.WriterRepresentation

        getReader
      • Methods inherited from class org.restlet.representation.CharacterRepresentation

        getChannel, getStream, write, write
      • Methods inherited from class org.restlet.representation.Representation

        append, exhaust, getAvailableSize, getDigest, getDisposition, getExpirationDate, getRange, getRegistration, getSize, getText, hasKnownSize, isAvailable, isEmpty, isSelectable, isTransient, release, setAvailable, setDigest, setDisposition, setExpirationDate, setListener, setRange, setSize, setTransient
      • Methods inherited from class org.restlet.representation.RepresentationInfo

        getModificationDate, getTag, setModificationDate, setTag
      • Methods inherited from class org.restlet.representation.Variant

        createClientInfo, equals, getCharacterSet, getEncodings, getLanguages, getLocationRef, getMediaType, hashCode, includes, isCompatible, setCharacterSet, setEncodings, setLanguages, setLocationRef, setLocationRef, setMediaType, toString
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • TemplateRepresentation

        public TemplateRepresentation​(org.restlet.representation.Representation templateRepresentation,
                                      freemarker.template.Configuration config,
                                      org.restlet.data.MediaType mediaType)
        Constructor.
        Parameters:
        templateRepresentation - The FreeMarker template provided via a representation.
        config - The FreeMarker configuration.
        mediaType - The representation's media type.
      • TemplateRepresentation

        public TemplateRepresentation​(org.restlet.representation.Representation templateRepresentation,
                                      freemarker.template.Configuration config,
                                      java.lang.Object dataModel,
                                      org.restlet.data.MediaType mediaType)
        Constructor.
        Parameters:
        templateRepresentation - The FreeMarker template provided via a representation.
        config - The FreeMarker configuration.
        dataModel - The template's data model.
        mediaType - The representation's media type.
      • TemplateRepresentation

        public TemplateRepresentation​(org.restlet.representation.Representation templateRepresentation,
                                      org.restlet.data.MediaType mediaType)
        Constructor.
        Parameters:
        templateRepresentation - The FreeMarker template provided via a representation.
        mediaType - The representation's media type.
      • TemplateRepresentation

        public TemplateRepresentation​(org.restlet.representation.Representation templateRepresentation,
                                      java.lang.Object dataModel,
                                      org.restlet.data.MediaType mediaType)
        Constructor. Uses a default FreeMarker configuration.
        Parameters:
        templateRepresentation - The FreeMarker template provided via a representation.
        dataModel - The template's data model.
        mediaType - The representation's media type.
      • TemplateRepresentation

        public TemplateRepresentation​(java.lang.String templateName,
                                      freemarker.template.Configuration config,
                                      org.restlet.data.MediaType mediaType)
        Constructor.
        Parameters:
        templateName - The FreeMarker template's name. The full path is resolved by the configuration.
        config - The FreeMarker configuration.
        mediaType - The representation's media type.
      • TemplateRepresentation

        public TemplateRepresentation​(java.lang.String templateName,
                                      freemarker.template.Configuration config,
                                      java.lang.Object dataModel,
                                      org.restlet.data.MediaType mediaType)
        Constructor.
        Parameters:
        templateName - The FreeMarker template's name. The full path is resolved by the configuration.
        config - The FreeMarker configuration.
        dataModel - The template's data model.
        mediaType - The representation's media type.
      • TemplateRepresentation

        public TemplateRepresentation​(freemarker.template.Template template,
                                      org.restlet.data.MediaType mediaType)
        Constructor.
        Parameters:
        template - The FreeMarker template.
        mediaType - The representation's media type.
      • TemplateRepresentation

        public TemplateRepresentation​(freemarker.template.Template template,
                                      java.lang.Object dataModel,
                                      org.restlet.data.MediaType mediaType)
        Constructor.
        Parameters:
        template - The FreeMarker template.
        dataModel - The template's data model.
        mediaType - The representation's media type.
    • Method Detail

      • getTemplate

        public static freemarker.template.Template getTemplate​(freemarker.template.Configuration config,
                                                               org.restlet.representation.Representation templateRepresentation)
        Returns a FreeMarker template from a representation and a configuration.
        Parameters:
        config - The FreeMarker configuration.
        templateRepresentation - The template representation.
        Returns:
        The template or null if not found.
      • getTemplate

        public static freemarker.template.Template getTemplate​(freemarker.template.Configuration config,
                                                               java.lang.String templateName)
        Returns a FreeMarker template from its name and a configuration.
        Parameters:
        config - The FreeMarker configuration.
        templateName - The template name.
        Returns:
        The template or null if not found.
      • getDataModel

        public java.lang.Object getDataModel()
        Returns the template's data model.
        Returns:
        The template's data model.
      • getTemplate

        public freemarker.template.Template getTemplate()
        Returns the FreeMarker template.
        Returns:
        The FreeMarker template.
      • setDataModel

        public java.lang.Object setDataModel​(java.lang.Object dataModel)
        Sets the template's data model.
        Parameters:
        dataModel - The template's data model.
        Returns:
        The template's data model.
      • setDataModel

        public java.lang.Object setDataModel​(org.restlet.Request request,
                                             org.restlet.Response response)
        Sets the template's data model from a request/response pair. This default implementation uses a Resolver.
        Parameters:
        request - The request where data are located.
        response - The response where data are located.
        Returns:
        The template's data model.
        See Also:
        Resolver, Resolver.createResolver(Request, Response)
      • setDataModel

        public java.lang.Object setDataModel​(org.restlet.util.Resolver<java.lang.Object> resolver)
        Sets the template's data model from a resolver.
        Parameters:
        resolver - The resolver.
        Returns:
        The template's data model.
      • setTemplate

        public void setTemplate​(freemarker.template.Template template)
        Sets the FreeMarker template.
        Parameters:
        template - The FreeMarker template.
      • write

        public void write​(java.io.Writer writer)
                   throws java.io.IOException
        Writes the datum as a stream of characters.
        Specified by:
        write in class org.restlet.representation.Representation
        Parameters:
        writer - The writer to use when writing.
        Throws:
        java.io.IOException