Class TemplateRepresentation

    • Field Detail

      • context

        private volatile org.apache.velocity.context.Context context
        The template's data model.
      • engine

        private volatile org.apache.velocity.app.VelocityEngine engine
        The Velocity engine.
      • template

        private volatile org.apache.velocity.Template template
        The template.
      • templateName

        private volatile java.lang.String templateName
        The template name.
    • Constructor Detail

      • TemplateRepresentation

        public TemplateRepresentation​(Representation templateRepresentation,
                                      java.util.Map<java.lang.String,​java.lang.Object> dataModel,
                                      MediaType mediaType)
                               throws org.apache.velocity.exception.ResourceNotFoundException,
                                      org.apache.velocity.exception.ParseErrorException,
                                      java.io.IOException
        Constructor based on a Velocity 'encoded' representation.
        Parameters:
        templateRepresentation - The representation to 'decode'.
        dataModel - The Velocity template's data model.
        mediaType - The representation's media type.
        Throws:
        java.io.IOException
        org.apache.velocity.exception.ParseErrorException
        org.apache.velocity.exception.ResourceNotFoundException
      • TemplateRepresentation

        public TemplateRepresentation​(Representation templateRepresentation,
                                      MediaType mediaType)
                               throws org.apache.velocity.exception.ResourceNotFoundException,
                                      org.apache.velocity.exception.ParseErrorException,
                                      java.io.IOException
        Constructor based on a Velocity 'encoded' representation.
        Parameters:
        templateRepresentation - The representation to 'decode'.
        mediaType - The representation's media type.
        Throws:
        java.io.IOException
        org.apache.velocity.exception.ParseErrorException
        org.apache.velocity.exception.ResourceNotFoundException
      • TemplateRepresentation

        public TemplateRepresentation​(java.lang.String templateName,
                                      java.util.Map<java.lang.String,​java.lang.Object> dataModel,
                                      MediaType mediaType)
        Constructor.
        Parameters:
        templateName - The Velocity template's name. The actual template is retrieved using the Velocity configuration.
        dataModel - The Velocity template's data model.
        mediaType - The representation's media type.
      • TemplateRepresentation

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

        public TemplateRepresentation​(org.apache.velocity.Template template,
                                      java.util.Map<java.lang.String,​java.lang.Object> dataModel,
                                      MediaType mediaType)
        Constructor.
        Parameters:
        template - The Velocity template.
        dataModel - The Velocity template's data model.
        mediaType - The representation's media type.
      • TemplateRepresentation

        public TemplateRepresentation​(org.apache.velocity.Template template,
                                      MediaType mediaType)
        Constructor.
        Parameters:
        template - The Velocity template.
        mediaType - The representation's media type.
    • Method Detail

      • getContext

        private org.apache.velocity.context.Context getContext()
        Returns the Velocity context.
        Returns:
        The Velocity context.
      • getEngine

        public org.apache.velocity.app.VelocityEngine getEngine()
        Returns the Velocity engine.
        Returns:
        The Velocity engine.
      • getTemplate

        public org.apache.velocity.Template getTemplate()
        Returns the Velocity template.
        Returns:
        The Velocity template.
      • setContext

        private void setContext​(org.apache.velocity.context.Context context)
        Sets the Velocity context.
        Parameters:
        context - The Velocity context
      • setDataModel

        public void setDataModel​(java.util.Map<java.lang.String,​java.lang.Object> dataModel)
        Sets the template's data model.
        Parameters:
        dataModel - The template's data model.
      • setDataModel

        public void setDataModel​(Request request,
                                 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.
        See Also:
        Resolver, Resolver.createResolver(Request, Response)
      • setDataModel

        public void setDataModel​(Resolver<java.lang.Object> resolver)
        Sets the template's data model from a resolver.
        Parameters:
        resolver - The resolver.
      • 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 Representation
        Parameters:
        writer - The writer to use when writing.
        Throws:
        java.io.IOException