Interface Template<T>

Type Parameters:
T - the model type
All Superinterfaces:
Renderer<T>, TemplateInfo
All Known Subinterfaces:
Template.EncodedTemplate<T>, ViewableTemplate<T>
All Known Implementing Classes:
ExampleModelRenderer, HelloModelAndViewView, HelloModelView, HelloModelView, MessagePageRenderer, MessagePageRenderer

public interface Template<T> extends Renderer<T>, TemplateInfo
A JStachio Template is a renderer that has template meta data.

Generated code implements this interface.

While many of the methods allow passing in custom Escapers care must be taken to choose a proper escaper that supports the original media type and charset of the template. There is currently no runtime checking that the escaper supports the template's media type and charset.

Author:
agentgt
  • Method Details

    • execute

      <A extends Output<E>, E extends Exception> A execute(T model, A appendable) throws E
      Renders the passed in model to an appendable like output.
      Specified by:
      execute in interface Renderer<T>
      Type Parameters:
      A - output type
      E - error type
      Parameters:
      model - a model assumed never to be null.
      appendable - the appendable to write to.
      Returns:
      the output passed in returned for convenience.
      Throws:
      E - if there is an error writing to the output
      API Note
      if the eventual output is to be bytes use write(Object, io.jstach.jstachio.Output.EncodedOutput) as it will leverage pre-encoding if the template has it.
    • write

      default <A extends Output.EncodedOutput<E>, E extends Exception> A write(T model, A output) throws E
      Renders the passed in model directly to a binary stream possibly leveraging pre-encoded parts of the template.
      Type Parameters:
      A - output type
      E - error type
      Parameters:
      model - a model assumed never to be null.
      output - to write to.
      Returns:
      the passed in output for convenience
      Throws:
      E - if an error occurs while writing to output
      API Note
      for performance and code generation reasons templates do not do validation that the encoded output has the correct charset.
    • write

      default void write(T model, OutputStream outputStream) throws IOException
      Renders the passed in model directly to a binary stream using the TemplateInfo.templateCharset() for encoding. If the template is pre-encoded the pre-encoded parts of the template will be written to the stream for performance otherwise an OutputStreamWriter will wrap the outputstream.
      Parameters:
      model - a model assumed never to be null.
      outputStream - to write to.
      Throws:
      IOException - if an error occurs while writing to the outputStream
      See Also:
      API Note
      The stream will not be closed but might be flushed by this call.
    • model

      default TemplateModel model(T model)
      Creates a template model pair.
      Parameters:
      model - never null model.
      Returns:
      executable template model pair.