Class HelloModelView
java.lang.Object
io.jstach.opt.spring.webflux.example.hello.HelloModelView
- All Implemented Interfaces:
Renderer<HelloModel>
,JStachioFilter.FilterChain
,TemplateProvider
,Template<HelloModel>
,Template.EncodedTemplate<HelloModel>
,TemplateInfo
@Component
public class HelloModelView
extends Object
implements Template.EncodedTemplate<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.TemplateSource
Nested classes/interfaces inherited from interface io.jstach.jstachio.spi.TemplateProvider
TemplateProvider.GeneratedTemplateProvider
-
Constructor Summary
ConstructorDescriptionRenderer 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.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, StringBuilder sb) A convenience method that does not throwIOException
when using StringBuilder.Class<?>
Model class.static HelloModelView
of()
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.boolean
supportsType
(Class<?> type) Checks to see if a template supports the model class.Appender.The templateCharset
which 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 withJStacheContentType
which 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.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.jstach.jstachio.Template.EncodedTemplate
model, write
Methods inherited from interface io.jstach.jstachio.TemplateInfo
description, lastLoaded, normalizePath, templateSource
Methods 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:Renderer
A convenience method that does not throwIOException
when using StringBuilder.- Specified by:
execute
in 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:Template
Renders the passed in model to an appendable like output.- Specified by:
execute
in interfaceRenderer<HelloModel>
- Specified by:
execute
in 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.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 fromJStacheConfig.charset()
.- Specified by:
write
in interfaceTemplate<HelloModel>
- Specified by:
write
in 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
-
supportsType
Description copied from interface:TemplateInfo
Checks to see if a template supports the model class.- Specified by:
supportsType
in interfaceTemplateInfo
- Parameters:
type
- the class of the model.- Returns:
- if this renderer supports the class.
-
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 interfaceTemplateInfo
- Returns:
- the location of the template or empty if the template is inlined.
- See Also:
-
templateName
Description copied from interface:TemplateInfo
The logical name of the template which maybe different thanTemplateInfo.templatePath()
.- Specified by:
templateName
in interfaceTemplateInfo
- Returns:
- logical name of template. Never null.
-
templateCharset
Description copied from interface:TemplateInfo
The templateCharset
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 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:
templateCharset
in interfaceTemplateInfo
- Returns:
- the template Charset.
- See Also:
-
templateMediaType
Description copied from interface:TemplateInfo
The template media-type from theJStacheContentType
.- Specified by:
templateMediaType
in interfaceTemplateInfo
- 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 useTemplateInfo.templateSource()
.- Specified by:
templateString
in interfaceTemplateInfo
- 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 withJStacheContentType
which also describes the escaper to be used.- Specified by:
templateContentType
in interfaceTemplateInfo
- Returns:
- the template content type.
-
templateEscaper
Description copied from interface:TemplateInfo
The escaper to be used on the template. SeeEscaper.of(Function)
.- Specified by:
templateEscaper
in interfaceTemplateInfo
- Returns:
- the escaper.
- See Also:
-
templateFormatter
Description copied from interface:TemplateInfo
The base formatter to be used on the template. SeeFormatter.of(Function)
.- Specified by:
templateFormatter
in interfaceTemplateInfo
- Returns:
- the formatter.
- See Also:
-
templateAppender
Appender.- Returns:
- appender for writing unescaped variables.
-
modelClass
Model class.- Specified by:
modelClass
in 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
-
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
-