java.lang.Object
io.jstach.jstachio.spi.AbstractJStachio
- All Implemented Interfaces:
ContextJStachio,JStachio,Renderer<Object>,JStachioExtensions.Provider
- Direct Known Subclasses:
SpringJStachio
public abstract class AbstractJStachio
extends Object
implements JStachio, JStachioExtensions.Provider, ContextJStachio
An abstract jstachio that just needs a
JStachioExtensions container.
To extend just override JStachioExtensions.Provider.extensions().
- Author:
- agentgt
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionRenders the passed in model.execute(Object model, ContextNode context, A appendable) Renders the passed in model with a context.findTemplate(Object model) Finds a template by model.protected final JStachioFilter.FilterChainloadFilter(Object model, TemplateInfo template) Loads the filter and checks if it can process the model and template.final booleansupportsType(Class<?> modelType) Determines if this jstachio can render the model type (the class annotated by JStache).protected TemplateInfoFinds the template by model class wrapping any exceptions.<A extends Output.EncodedOutput<E>,E extends Exception>
ARenders the passed in model directly to a binary stream possibly leveraging pre-encoded parts of the template.final <A extends Output.EncodedOutput<E>,E extends Exception>
Awrite(Object model, ContextNode context, A output) Renders the passed in model with a context 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.spi.JStachioExtensions.Provider
extensions
-
Constructor Details
-
AbstractJStachio
public AbstractJStachio()Do nothing constructor
-
-
Method Details
-
execute
Description copied from interface:RendererRenders the passed in model.- Specified by:
executein interfaceRenderer<Object>- Type Parameters:
A- output typeE- error type- Parameters:
model- a model assumed never to benull.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:JStachioRenders 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 fromJStacheConfig.charset(). -
write
public final <A extends Output.EncodedOutput<E>,E extends Exception> A write(Object model, ContextNode context, A output) throws E Description copied from interface:ContextJStachioRenders the passed in model with a context 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 interfaceContextJStachio- Type Parameters:
A- output typeE- error type- Parameters:
model- a model assumed never to benull.context- context node bound to "@context".output- to write to.- Returns:
- the passed in output for convenience
- Throws:
E- if an error occurs while writing to output
-
execute
public final <A extends Output<E>,E extends Exception> A execute(Object model, ContextNode context, A appendable) throws E Description copied from interface:ContextJStachioRenders the passed in model with a context.- Specified by:
executein interfaceContextJStachio- Type Parameters:
A- output typeE- error type- Parameters:
model- a model assumed never to benull.context- context node bound to "@context".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
-
findTemplate
Description copied from interface:JStachioFinds 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
TemplateModelshould work as well and the returned template will be able to execute the TemplateModel as though it were a regular model.- Specified by:
findTemplatein interfaceJStachio- Parameters:
model- the actual model or aTemplateModelcontaining the model- Returns:
- a filtered template
-
loadFilter
Loads the filter and checks if it can process the model and template.- Parameters:
model- to rendertemplate- loaded bytemplate(Class)- Returns:
- filter chain that can process model
-
supportsType
Description copied from interface:JStachioDetermines if this jstachio can render the model type (the class annotated by JStache).- Specified by:
supportsTypein interfaceJStachio- Parameters:
modelType- the models class (the one annotated withJStacheand not the Templates class)- Returns:
- true if this jstachio can render instances of modelType
-
template
Finds the template by model class wrapping any exceptions.- Parameters:
modelType- the class of the model.- Returns:
- found template never
null.
-