Interface ContextTemplate<T>

Type Parameters:
T - model type
All Known Implementing Classes:
ExampleModelRenderer, HelloModelAndViewView, HelloModelView, HelloModelView, MessagePageRenderer, MessagePageRenderer

public interface ContextTemplate<T>
A context aware template.
  • Method Summary

    Modifier and Type
    Method
    Description
    <A extends Output<E>, E extends Exception>
    A
    execute(T model, ContextNode context, A appendable)
    Renders the passed in model to an appendable like output.
    static <T> ContextTemplate<T>
    of(Template<T> template)
    Creates a context template from a regular template if is not already a context template.
    <A extends Output.EncodedOutput<E>, E extends Exception>
    A
    write(T model, ContextNode context, A output)
    Renders the passed in model directly to a binary stream leveraging pre-encoded parts of the template.
  • Method Details

    • execute

      <A extends Output<E>, E extends Exception> A execute(T model, ContextNode context, A appendable) throws E
      Renders the passed in model to an appendable like output.
      Type Parameters:
      A - output type
      E - error type
      Parameters:
      model - a model assumed never to be null.
      context - context node.
      appendable - the appendable to write to.
      Returns:
      the passed in appendable 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, ContextNode, io.jstach.jstachio.Output.EncodedOutput) as it will leverage pre-encoding if the template has it.
    • write

      <A extends Output.EncodedOutput<E>, E extends Exception> A write(T model, ContextNode context, A output) throws E
      Renders the passed in model directly to a binary stream leveraging pre-encoded parts of the template. This may improve performance when rendering UTF-8 to an OutputStream as some of the encoding is done in advance. Because the encoding is done statically you cannot pass the charset in. The chosen charset comes from JStacheConfig.charset().
      Type Parameters:
      A - output type
      E - error type
      Parameters:
      model - a model assumed never to be null.
      context - context node.
      output - to write to.
      Returns:
      the passed in output for convenience
      Throws:
      E - if an error occurs while writing to output
    • of

      static <T> ContextTemplate<T> of(Template<T> template)
      Creates a context template from a regular template if is not already a context template.
      Type Parameters:
      T - model type
      Parameters:
      template - the template to be wrapped
      Returns:
      context template