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
public class HelloModelView
extends Object
implements Template.EncodedTemplate<HelloModel>, ContextTemplate<HelloModel>, TemplateProvider, JStachioFilter.FilterChain
Generated Renderer.
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.jstach.jstachio.Template
Template.EncodedTemplate<T>Nested classes/interfaces inherited from interface io.jstach.jstachio.TemplateInfo
TemplateInfo.TemplateSourceNested classes/interfaces inherited from interface io.jstach.jstachio.spi.TemplateProvider
TemplateProvider.GeneratedTemplateProvider -
Field Summary
Fields inherited from interface io.jstach.jstachio.TemplateInfo
TEMPLATE_BINDING_NAME -
Constructor Summary
ConstructorsConstructorDescriptionRenderer constructor for reflection (use of() instead).HelloModelView(TemplateConfig templateConfig) Renderer constructor using config.Renderer constructor for manual wiring. -
Method Summary
Modifier and TypeMethodDescriptionprotected static <A extends Output.EncodedOutput<E>,E extends Exception>
voidencode(HelloModel data, A unescapedWriter, Formatter formatter, Escaper escaper, Appender appender) Renders to an OutputStream use pre-encoded parts of the template.protected static <A extends Output.EncodedOutput<E>,E extends Exception>
voidencode(HelloModelView template, HelloModel data, ContextNode context, A unescapedWriter, Formatter formatter, Escaper escaper, Appender appender) Renders to an OutputStream use pre-encoded parts of the template.execute(HelloModel model, A a) Renders the passed in model to an appendable like output.execute(HelloModel model, A a, Formatter formatter, Escaper escaper) Renders the passed in model.execute(HelloModel model, ContextNode context, A a) Renders the passed in model to an appendable like output.execute(HelloModel model, StringBuilder sb) A convenience method that does not throwIOExceptionwhen using StringBuilder.Class<?>Model class.static HelloModelViewof()Convience static factory that will reuse the same singleton instance.render(HelloModel data, A unescapedWriter, Formatter formatter, Appender escaper, Appender appender) Renders the passed in model.render(HelloModelView template, HelloModel data, ContextNode context, A unescapedWriter, Formatter formatter, Appender escaper, Appender appender) Renders the passed in model.booleansupportsType(Class<?> type) Checks to see if a template supports the model class.Appender.The templateCharsetwhich is the original format of the template file and should ideally be used when encoding an HTTP response or similar.Class<?>The template content type is the class annotated withJStacheContentTypewhich also describes the escaper to be used.The escaper to be used on the template.The base formatter to be used on the template.The template media-type from theJStacheContentType.The logical name of the template which maybe different thanTemplateInfo.templatePath().If the template is a classpath resource file this will return the location that was originally resolved via config resolution.The raw contents of the template.<A extends Output.EncodedOutput<E>,E extends Exception>
Awrite(HelloModel model, A outputStream) Renders the passed in model directly to a binary stream leveraging pre-encoded parts of the template.<A extends Output.EncodedOutput<E>,E extends Exception>
Awrite(HelloModel model, ContextNode context, A outputStream) Renders the passed in model directly to a binary stream leveraging pre-encoded parts of the template.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.jstach.jstachio.Template.EncodedTemplate
model, writeMethods inherited from interface io.jstach.jstachio.TemplateInfo
description, lastLoaded, normalizePath, templateSourceMethods inherited from interface io.jstach.jstachio.spi.TemplateProvider
provideTemplates
-
Constructor Details
-
HelloModelView
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 usingof()for a shared singleton. -
HelloModelView
Renderer constructor using config.- Parameters:
templateConfig- config that has collaborators
-
-
Method Details
-
execute
Description copied from interface:RendererA convenience method that does not throwIOExceptionwhen using StringBuilder.- Specified by:
executein interfaceRenderer<HelloModel>- Parameters:
model- a model assumed never to be null.sb- should never be null.- Returns:
- the passed in
StringBuilder.
-
execute
Description copied from interface:TemplateRenders the passed in model to an appendable like output.- Specified by:
executein interfaceRenderer<HelloModel>- Specified by:
executein interfaceTemplate<HelloModel>- Type Parameters:
A- output typeE- error type- Parameters:
model- a model assumed never to benull.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 benull.a- appendable to write to.formatter- formats variables before they are passed to the escaperescaper- 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.EncodedTemplateRenders 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 fromJStacheConfig.charset().- Specified by:
writein interfaceTemplate<HelloModel>- Specified by:
writein interfaceTemplate.EncodedTemplate<HelloModel>- Type Parameters:
A- output typeE- error type- Parameters:
model- a model assumed never to benull.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:ContextTemplateRenders the passed in model to an appendable like output.- Specified by:
executein interfaceContextTemplate<HelloModel>- Type Parameters:
A- output typeE- error type- Parameters:
model- a model assumed never to benull.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:ContextTemplateRenders 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 fromJStacheConfig.charset().- Specified by:
writein interfaceContextTemplate<HelloModel>- Type Parameters:
A- output typeE- error type- Parameters:
model- a model assumed never to benull.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
Description copied from interface:TemplateInfoChecks to see if a template supports the model class.- Specified by:
supportsTypein interfaceTemplateInfo- Parameters:
type- the class of the model.- Returns:
- if this renderer supports the class.
-
templatePath
Description copied from interface:TemplateInfoIf the template is a classpath resource file this will return the location that was originally resolved via config resolution.- Specified by:
templatePathin interfaceTemplateInfo- Returns:
- the location of the template or empty if the template is inlined.
- See Also:
-
templateName
Description copied from interface:TemplateInfoThe logical name of the template which maybe different thanTemplateInfo.templatePath().- Specified by:
templateNamein interfaceTemplateInfo- Returns:
- logical name of template. Never null.
-
templateCharset
Description copied from interface:TemplateInfoThe templateCharsetwhich 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 chosenTemplateInfo.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:
templateCharsetin interfaceTemplateInfo- Returns:
- the template Charset.
- See Also:
-
templateMediaType
Description copied from interface:TemplateInfoThe template media-type from theJStacheContentType.- Specified by:
templateMediaTypein interfaceTemplateInfo- Returns:
- media type maybe an empty string.
-
templateString
Description copied from interface:TemplateInfoThe raw contents of the template. Useful if the template is inline. To determine if the template is actually inline useTemplateInfo.templateSource().- Specified by:
templateStringin interfaceTemplateInfo- Returns:
- the raw contents of the template never null.
- See Also:
-
templateContentType
Description copied from interface:TemplateInfoThe template content type is the class annotated withJStacheContentTypewhich also describes the escaper to be used.- Specified by:
templateContentTypein interfaceTemplateInfo- Returns:
- the template content type.
-
templateEscaper
Description copied from interface:TemplateInfoThe escaper to be used on the template. SeeEscaper.of(Function).- Specified by:
templateEscaperin interfaceTemplateInfo- Returns:
- the escaper.
- See Also:
-
templateFormatter
Description copied from interface:TemplateInfoThe base formatter to be used on the template. SeeFormatter.of(Function).- Specified by:
templateFormatterin interfaceTemplateInfo- Returns:
- the formatter.
- See Also:
-
templateAppender
Appender.- Returns:
- appender for writing unescaped variables.
-
modelClass
Model class.- Specified by:
modelClassin interfaceTemplateInfo- Returns:
- class used as model (annotated with JStache).
-
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- modelunescapedWriter- 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- modelcontext- contextunescapedWriter- 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- modelunescapedWriter- 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- modelcontext- contextunescapedWriter- 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
-