Class AbstractJStachio

java.lang.Object
io.jstach.jstachio.spi.AbstractJStachio
All Implemented Interfaces:
JStachio, Renderer<Object>, JStachioExtensions.Provider
Direct Known Subclasses:
SpringJStachio

public abstract class AbstractJStachio extends Object implements JStachio, JStachioExtensions.Provider
An abstract jstachio that just needs a JStachioExtensions container.

To extend just override JStachioExtensions.Provider.extensions().

Author:
agentgt
See Also:
  • Constructor Details

  • Method Details

    • execute

      public <A extends Output<E>, E extends Exception> A execute(Object model, A appendable) throws E
      Description copied from interface: Renderer
      Renders the passed in model.
      Specified by:
      execute in interface Renderer<Object>
      Type Parameters:
      A - output type
      E - error type
      Parameters:
      model - a model assumed never to be null.
      appendable - the output to write to.
      Returns:
      the output passed in returned for convenience.
      Throws:
      E - if there is an error writing to the output
    • write

      public <A extends Output.EncodedOutput<E>, E extends Exception> A write(Object model, A appendable) throws E
      Description copied from interface: JStachio
      Renders the passed in model directly to a binary stream possibly 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().
      Specified by:
      write in interface JStachio
      Type Parameters:
      A - output type
      E - error type
      Parameters:
      model - a model assumed never to be null.
      appendable - to write to.
      Returns:
      the passed in output for convenience
      Throws:
      E - if an error occurs while writing to output
    • findTemplate

      public final Template<Object> findTemplate(Object model)
      Description copied from interface: JStachio
      Finds a template by model. This is useful if you need metadata before writing such as charset and media type for HTTP output which the template has.

      The returned template is decorated if filtering is on and a filter that is not the template is applied.

      Passing in a TemplateModel should work as well and the returned template will be able to execute the TemplateModel as though it were a regular model.

      Specified by:
      findTemplate in interface JStachio
      Parameters:
      model - the actual model or a TemplateModel containing the model
      Returns:
      a filtered template
    • loadFilter

      protected final JStachioFilter.FilterChain loadFilter(Object model, TemplateInfo template)
      Loads the filter and checks if it can process the model and template.
      Parameters:
      model - to render
      template - loaded by template(Class)
      Returns:
      filter chain that can process model
    • supportsType

      public final boolean supportsType(Class<?> modelType)
      Description copied from interface: JStachio
      Determines if this jstachio can render the model type (the class annotated by JStache).
      Specified by:
      supportsType in interface JStachio
      Parameters:
      modelType - the models class (the one annotated with JStache and not the Templates class)
      Returns:
      true if this jstachio can render instances of modelType
    • template

      protected TemplateInfo template(Class<?> modelType)
      Finds the template by model class wrapping any exceptions.
      Parameters:
      modelType - the class of the model.
      Returns:
      found template never null.