Class AbstractTemplateSet

java.lang.Object
io.inverno.mod.irt.AbstractTemplateSet
All Implemented Interfaces:
TemplateSet
Direct Known Subclasses:
AbstractByteBufPublisherTemplateSet, AbstractByteBufTemplateSet, AbstractCompositeByteBufTemplateSet, AbstractStreamTemplateSet, AbstractStringPublisherTemplateSet, AbstractStringTemplateSet

public abstract class AbstractTemplateSet extends Object implements TemplateSet

Base TemplateSet implementation.

This class especially provides general implementations for applyTemplate methods which allow to apply templates on the elements of an array, an iterable, a stream and a publisher while making sure the rendering process is non-blocking following reactive programming principles.

Since:
1.2
Author:
Jeremy Kuhn
  • Field Details

    • charset

      protected final Charset charset
      The charset to use to encode rendered data.
  • Constructor Details

    • AbstractTemplateSet

      public AbstractTemplateSet(Charset charset)

      Creates a template set.

      Parameters:
      charset - the charset to use to encode data
  • Method Details

    • render

      public CompletableFuture<Void> render(Object value)
      Description copied from interface: TemplateSet

      Renders an object to the output.

      This method might invoke specialized methods based on the actual type of the object. If no specific method is found the string representation of the object must be rendered.

      Specified by:
      render in interface TemplateSet
      Parameters:
      value - the object to render
      Returns:
      a future which completes once the value is rendered
    • applyTemplate

      public <T> TemplateSet.Renderable<T> applyTemplate(T value)
      Description copied from interface: TemplateSet

      Invokes a template defined in the template set implementation on the specified object.

      Specified by:
      applyTemplate in interface TemplateSet
      Type Parameters:
      T - the type of the object
      Parameters:
      value - the value onto which template should be applied
      Returns:
      a renderable object which can invoke the template method matching the object type
    • applyTemplate

      public <T> TemplateSet.IndexableRenderable<T> applyTemplate(T[] array)
      Description copied from interface: TemplateSet

      Invokes a template defined in the template set implementation on each element of the specified array.

      Elements are guaranteed to be rendered in sequence.

      Specified by:
      applyTemplate in interface TemplateSet
      Type Parameters:
      T - the type of the object
      Parameters:
      array - the array of elements onto which template should be applied
      Returns:
      an indexable renderable object which can invoke the template method matching the object type
    • applyTemplate

      public <T> TemplateSet.IndexableRenderable<T> applyTemplate(Publisher<T> publisher)
      Description copied from interface: TemplateSet

      Invokes a template defined in the template set implementation on each element emitted in the specified publisher until the publisher completes.

      Elements are guaranteed to be rendered in sequence.

      Specified by:
      applyTemplate in interface TemplateSet
      Type Parameters:
      T - the type of the object
      Parameters:
      publisher - the stream of elements onto which template should be applied
      Returns:
      an indexable renderable object which can invoke the template method matching the object type
    • applyTemplate

      public <T> TemplateSet.IndexableRenderable<T> applyTemplate(Iterable<T> iterable)
      Description copied from interface: TemplateSet

      Invokes a template defined in the template set implementation on each element of the specified iterable.

      Elements are guaranteed to be rendered in sequence.

      Specified by:
      applyTemplate in interface TemplateSet
      Type Parameters:
      T - the type of the object
      Parameters:
      iterable - the iterable providing the elements onto which template should be applied
      Returns:
      an indexable renderable object which can invoke the template method matching the object type
    • applyTemplate

      public <T> TemplateSet.IndexableRenderable<T> applyTemplate(Stream<T> stream)
      Description copied from interface: TemplateSet

      Invokes a template defined in the template set implementation on each element of the specified stream.

      Elements are guaranteed to be rendered in sequence.

      Specified by:
      applyTemplate in interface TemplateSet
      Type Parameters:
      T - the type of the object
      Parameters:
      stream - the stream of elements onto which template should be applied
      Returns:
      an indexable renderable object which can invoke the template method matching the object type