java.lang.Object
io.jstach.opt.spring.example.hello.HelloModelView
All Implemented Interfaces:
ContextTemplate<HelloModel>, Renderer<HelloModel>, JStachioFilter.FilterChain, TemplateProvider, Template<HelloModel>, Template.EncodedTemplate<HelloModel>, TemplateInfo

Generated Renderer.
  • Constructor Details

    • HelloModelView

      public HelloModelView(Function<Object,String> formatter, Function<String,String> escaper)
      Renderer constructor for manual wiring.
      Parameters:
      formatter - formatter if null the static formatter will be used.
      escaper - escaper if null the static escaper will be used
    • HelloModelView

      public HelloModelView()
      Renderer constructor for reflection (use of() instead). For programmatic consider using of() for a shared singleton.
    • HelloModelView

      public HelloModelView(TemplateConfig templateConfig)
      Renderer constructor using config.
      Parameters:
      templateConfig - config that has collaborators
  • Method Details

    • execute

      Description copied from interface: Renderer
      A convenience method that does not throw IOException when using StringBuilder.
      Specified by:
      execute in interface Renderer<HelloModel>
      Parameters:
      model - a model assumed never to be null.
      sb - should never be null.
      Returns:
      the passed in StringBuilder.
    • execute

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

      protected <A extends Output<E>, E extends Exception> void execute(HelloModel model, A a, Formatter formatter, Escaper escaper) throws E
      Renders the passed in model.
      Type Parameters:
      A - appendable type.
      E - error type.
      Parameters:
      model - a model assumed never to be null.
      a - appendable to write to.
      formatter - formats variables before they are passed to the escaper
      escaper - used to write escaped variables
      Throws:
      E - if an error occurs while writing to the appendable
    • write

      public <A extends Output.EncodedOutput<E>, E extends Exception> A write(HelloModel model, A outputStream) throws E
      Description copied from interface: Template.EncodedTemplate
      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().
      Specified by:
      write in interface Template<HelloModel>
      Specified by:
      write in interface Template.EncodedTemplate<HelloModel>
      Type Parameters:
      A - output type
      E - error type
      Parameters:
      model - a model assumed never to be null.
      outputStream - to write to.
      Returns:
      the passed in output for convenience
      Throws:
      E - if an error occurs while writing to output
    • execute

      public <A extends Output<E>, E extends Exception> A execute(HelloModel model, ContextNode context, A a) throws E
      Description copied from interface: ContextTemplate
      Renders the passed in model to an appendable like output.
      Specified by:
      execute in interface ContextTemplate<HelloModel>
      Type Parameters:
      A - output type
      E - error type
      Parameters:
      model - a model assumed never to be null.
      context - context node.
      a - the appendable to write to.
      Returns:
      the passed in appendable 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(HelloModel model, ContextNode context, A outputStream) throws E
      Description copied from interface: ContextTemplate
      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().
      Specified by:
      write in interface ContextTemplate<HelloModel>
      Type Parameters:
      A - output type
      E - error type
      Parameters:
      model - a model assumed never to be null.
      context - context node.
      outputStream - to write to.
      Returns:
      the passed in output for convenience
      Throws:
      E - if an error occurs while writing to output
    • supportsType

      public boolean supportsType(Class<?> type)
      Description copied from interface: TemplateInfo
      Checks to see if a template supports the model class.
      Specified by:
      supportsType in interface TemplateInfo
      Parameters:
      type - the class of the model.
      Returns:
      if this renderer supports the class.
    • templatePath

      public String templatePath()
      Description copied from interface: TemplateInfo
      If the template is a classpath resource file this will return the location that was originally resolved via config resolution.
      Specified by:
      templatePath in interface TemplateInfo
      Returns:
      the location of the template or empty if the template is inlined.
      See Also:
    • templateName

      public String templateName()
      Description copied from interface: TemplateInfo
      The logical name of the template which maybe different than TemplateInfo.templatePath().
      Specified by:
      templateName in interface TemplateInfo
      Returns:
      logical name of template. Never null.
    • templateCharset

      Description copied from interface: TemplateInfo
      The template Charset which is the original format of the template file and should ideally be used when encoding an HTTP response or similar. Furthermore ideally the template charset matches the chosen TemplateInfo.templateContentType() JStacheContentType.charsets() otherwise the escaper may not appropriately escape.

      IF the template is inline or charset was not set this will usually be StandardCharsets.UTF_8.

      Specified by:
      templateCharset in interface TemplateInfo
      Returns:
      the template Charset.
      See Also:
    • templateMediaType

      Description copied from interface: TemplateInfo
      The template media-type from the JStacheContentType.
      Specified by:
      templateMediaType in interface TemplateInfo
      Returns:
      media type maybe an empty string.
    • templateString

      Description copied from interface: TemplateInfo
      The raw contents of the template. Useful if the template is inline. To determine if the template is actually inline use TemplateInfo.templateSource().
      Specified by:
      templateString in interface TemplateInfo
      Returns:
      the raw contents of the template never null.
      See Also:
    • templateContentType

      Description copied from interface: TemplateInfo
      The template content type is the class annotated with JStacheContentType which also describes the escaper to be used.
      Specified by:
      templateContentType in interface TemplateInfo
      Returns:
      the template content type.
    • templateEscaper

      Description copied from interface: TemplateInfo
      The escaper to be used on the template. See Escaper.of(Function).
      Specified by:
      templateEscaper in interface TemplateInfo
      Returns:
      the escaper.
      See Also:
    • templateFormatter

      Description copied from interface: TemplateInfo
      The base formatter to be used on the template. See Formatter.of(Function).
      Specified by:
      templateFormatter in interface TemplateInfo
      Returns:
      the formatter.
      See Also:
    • templateAppender

      Appender.
      Returns:
      appender for writing unescaped variables.
    • modelClass

      public Class<?> modelClass()
      Model class.
      Specified by:
      modelClass in interface TemplateInfo
      Returns:
      class used as model (annotated with JStache).
    • of

      public static HelloModelView of()
      Convience static factory that will reuse the same singleton instance.
      Returns:
      renderer same as calling no-arg constructor but is cached with singleton instance
    • render

      public static <A extends Output<E>, E extends Exception> void render(HelloModel data, A unescapedWriter, Formatter formatter, Appender escaper, Appender appender) throws E
      Renders the passed in model.
      Type Parameters:
      A - appendable type.
      E - error type.
      Parameters:
      data - model
      unescapedWriter - appendable to write to.
      formatter - formats variables before they are passed to the escaper.
      escaper - used to write escaped variables.
      appender - used to write unescaped variables.
      Throws:
      E - if an error occurs while writing to the appendable
    • render

      protected static <A extends Output<E>, E extends Exception> void render(HelloModelView template, HelloModel data, ContextNode context, A unescapedWriter, Formatter formatter, Appender escaper, Appender appender) throws E
      Renders the passed in model.
      Type Parameters:
      A - appendable type.
      E - error type.
      Parameters:
      template - instance of template.
      data - model
      context - context
      unescapedWriter - appendable to write to.
      formatter - formats variables before they are passed to the escaper.
      escaper - used to write escaped variables.
      appender - used to write unescaped variables.
      Throws:
      E - if an error occurs while writing to the appendable
    • encode

      protected static <A extends Output.EncodedOutput<E>, E extends Exception> void encode(HelloModel data, A unescapedWriter, Formatter formatter, Escaper escaper, Appender appender) throws E
      Renders to an OutputStream use pre-encoded parts of the template.
      Type Parameters:
      A - output type.
      E - error type.
      Parameters:
      data - model
      unescapedWriter - stream to write to.
      formatter - formats variables before they are passed to the escaper.
      escaper - used to write escaped variables.
      appender - used to write unescaped variables.
      Throws:
      E - if an error occurs while writing to the appendable
    • encode

      protected static <A extends Output.EncodedOutput<E>, E extends Exception> void encode(HelloModelView template, HelloModel data, ContextNode context, A unescapedWriter, Formatter formatter, Escaper escaper, Appender appender) throws E
      Renders to an OutputStream use pre-encoded parts of the template.
      Type Parameters:
      A - output type.
      E - error type.
      Parameters:
      template - instance of template.
      data - model
      context - context
      unescapedWriter - stream to write to.
      formatter - formats variables before they are passed to the escaper.
      escaper - used to write escaped variables.
      appender - used to write unescaped variables.
      Throws:
      E - if an error occurs while writing to the appendable