public abstract class Template extends Object
path
and can used to produce markup.
Templates perform rendering using a parameter map and a locale as inputs and produces a markup response.
Template can be rendered with many methods that will affect the current execution. Those methods will implicitly set
the produced markup response on the MimeContext
using the MimeContext.setResponse(juzu.Response.Content)
method: render()
, render(java.util.Locale)
, render(java.util.Map)
, render(java.util.Map, java.util.Locale)
,
notFound()
, notFound(java.util.Locale)
, notFound(java.util.Map)
, notFound(java.util.Map, java.util.Locale)
,
ok()
, ok(java.util.Locale)
, ok(java.util.Map)
, ok(java.util.Map, java.util.Locale)
.
Template can be parameterized using a fluent API with the Template.Builder
object provided by the with()
method:
template.with().set("date", new java.util.Date()).render()
The template compiler produces also a subclass of the template that can be used instead of this base template class.
This sub class overrides the with()
method to return a builder that provides typed methods when the
template declares parameters:
template.with().date(new java.util.Date()).render()
Modifier and Type | Class and Description |
---|---|
class |
Template.Builder
A builder providing a fluent syntax for rendering a template.
|
Constructor and Description |
---|
Template(juzu.impl.plugin.template.TemplatePlugin plugin,
juzu.impl.common.Path path,
Class<? extends juzu.impl.template.spi.TemplateStub> stubType) |
Template(juzu.impl.plugin.template.TemplatePlugin plugin,
String path,
Class<? extends juzu.impl.template.spi.TemplateStub> stubType) |
Modifier and Type | Method and Description |
---|---|
juzu.impl.common.Path |
getPath()
Returns the template path.
|
Response.Content |
notFound()
Renders the template.
|
Response.Content |
notFound(Locale locale)
Renders the template.
|
Response.Content |
notFound(Map<String,?> parameters)
Renders the template.
|
Response.Content |
notFound(Map<String,?> parameters,
Locale locale)
Renders the template.
|
Response.Content |
ok()
Renders the template.
|
Response.Content |
ok(Locale locale)
Renders the template.
|
Response.Content |
ok(Map<String,?> parameters)
Renders the template and set the response on the current
MimeContext . |
Response.Content |
ok(Map<String,?> parameters,
Locale locale)
Renders the template.
|
void |
render()
Renders the template and set the response on the current
MimeContext |
void |
render(Locale locale)
Renders the template and set a the response on the current
MimeContext . |
void |
render(Map<String,?> parameters)
Renders the template and set a the response on the current
MimeContext . |
void |
render(Map<String,?> parameters,
Locale locale)
Renders the template and set a the response on the current
MimeContext . |
<A extends Appendable> |
renderTo(A appendable)
Renders the template to the specified appendable.
|
<A extends Appendable> |
renderTo(A appendable,
Locale locale)
Renders the template to the specified appendable.
|
<A extends Appendable> |
renderTo(A appendable,
Map<String,?> parameters)
Renders the template to the specified appendable.
|
void |
renderTo(Stream printer)
Renders the template to the specified printer.
|
void |
renderTo(Stream printer,
Locale locale)
Renders the template to the specified printer.
|
void |
renderTo(Stream printer,
Map<String,?> parameters)
Renders the template to the specified printer.
|
String |
toString() |
Template.Builder |
with()
Returns a builder to further customize the template rendering.
|
Template.Builder |
with(Locale locale)
Returns a builder to further customize the template rendering.
|
Template.Builder |
with(Map<String,?> parameters)
Returns a builder to further customize the template rendering.
|
public Template(juzu.impl.plugin.template.TemplatePlugin plugin, String path, Class<? extends juzu.impl.template.spi.TemplateStub> stubType)
public Template(juzu.impl.plugin.template.TemplatePlugin plugin, juzu.impl.common.Path path, Class<? extends juzu.impl.template.spi.TemplateStub> stubType)
public final juzu.impl.common.Path getPath()
public void render() throws TemplateExecutionException, UndeclaredIOException
MimeContext
public void render(Locale locale) throws TemplateExecutionException, UndeclaredIOException
MimeContext
.locale
- the localeTemplateExecutionException
UndeclaredIOException
public void render(Map<String,?> parameters) throws TemplateExecutionException, UndeclaredIOException
MimeContext
.parameters
- the parametersTemplateExecutionException
UndeclaredIOException
public void render(Map<String,?> parameters, Locale locale) throws TemplateExecutionException, UndeclaredIOException
MimeContext
.parameters
- the parameterslocale
- the localeTemplateExecutionException
UndeclaredIOException
public final Response.Content ok()
public final Response.Content ok(Locale locale)
locale
- the localepublic final Response.Content ok(Map<String,?> parameters)
MimeContext
.parameters
- the parameterspublic final Response.Content ok(Map<String,?> parameters, Locale locale)
parameters
- the parameterslocale
- the localepublic final Response.Content notFound()
public final Response.Content notFound(Locale locale)
locale
- the localepublic final Response.Content notFound(Map<String,?> parameters)
parameters
- the parameterspublic final Response.Content notFound(Map<String,?> parameters, Locale locale)
parameters
- the parameterslocale
- the localepublic <A extends Appendable> A renderTo(A appendable) throws TemplateExecutionException, UndeclaredIOException
appendable
- the appendableTemplateExecutionException
- any execution exceptionUndeclaredIOException
- any io exceptionpublic <A extends Appendable> A renderTo(A appendable, Locale locale) throws TemplateExecutionException, UndeclaredIOException
appendable
- the appendablelocale
- the localeTemplateExecutionException
- any execution exceptionUndeclaredIOException
- any io exceptionpublic <A extends Appendable> A renderTo(A appendable, Map<String,?> parameters) throws TemplateExecutionException, UndeclaredIOException
appendable
- the appendableparameters
- the attributesTemplateExecutionException
- any execution exceptionUndeclaredIOException
- any io exceptionpublic void renderTo(Stream printer) throws TemplateExecutionException, UndeclaredIOException
printer
- the printerTemplateExecutionException
- any execution exceptionUndeclaredIOException
- any io exceptionpublic void renderTo(Stream printer, Locale locale) throws TemplateExecutionException, UndeclaredIOException
printer
- the printerlocale
- the localeTemplateExecutionException
- any execution exceptionUndeclaredIOException
- any io exceptionpublic void renderTo(Stream printer, Map<String,?> parameters) throws TemplateExecutionException, UndeclaredIOException
printer
- the printerparameters
- the attributesTemplateExecutionException
- any execution exceptionUndeclaredIOException
- any io exceptionpublic Template.Builder with()
public Template.Builder with(Map<String,?> parameters)
public Template.Builder with(Locale locale)
Copyright © 2013 eXo Platform SAS. All Rights Reserved.