Package org.restlet.ext.thymeleaf
Class TemplateRepresentation
- java.lang.Object
-
- org.restlet.representation.Variant
-
- org.restlet.representation.RepresentationInfo
-
- org.restlet.representation.Representation
-
- org.restlet.representation.CharacterRepresentation
-
- org.restlet.representation.WriterRepresentation
-
- org.restlet.ext.thymeleaf.TemplateRepresentation
-
public class TemplateRepresentation extends org.restlet.representation.WriterRepresentation
Thymeleaf template representation. Useful for dynamic string-based representations.- Author:
- Grzegorz Godlewski
- See Also:
- Thymeleaf home page
-
-
Field Summary
Fields Modifier and Type Field Description protected org.thymeleaf.context.IContext
context
The template's data model.
-
Constructor Summary
Constructors Constructor Description TemplateRepresentation(java.lang.String templateName, java.util.Locale locale, java.util.Map<java.lang.String,java.lang.Object> dataModel, org.restlet.data.MediaType mediaType)
Constructor.TemplateRepresentation(java.lang.String templateName, java.util.Locale locale, org.restlet.data.MediaType mediaType)
Constructor.TemplateRepresentation(java.lang.String templateName, org.thymeleaf.TemplateEngine engine, java.util.Locale locale, java.util.Map<java.lang.String,java.lang.Object> dataModel, org.restlet.data.MediaType mediaType)
Constructor.TemplateRepresentation(java.lang.String templateName, org.thymeleaf.TemplateEngine engine, java.util.Locale locale, org.restlet.data.MediaType mediaType)
Constructor.TemplateRepresentation(TemplateRepresentation templateRepresentation, java.util.Locale locale, org.restlet.data.MediaType mediaType)
Constructor based on a Thymeleaf 'encoded' representation.TemplateRepresentation(TemplateRepresentation templateRepresentation, org.thymeleaf.TemplateEngine engine, java.util.Locale locale, org.restlet.data.MediaType mediaType)
Constructor based on a Thymeleaf 'encoded' representation.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static org.thymeleaf.TemplateEngine
createTemplateEngine()
Returns a new instance ofTemplateEngine
based by default on aITemplateResolver
returned by callingcreateTemplateResolver()
.static org.thymeleaf.TemplateEngine
createTemplateEngine(org.thymeleaf.templateresolver.ITemplateResolver resolver)
Returns a new instance ofTemplateEngine
based by default on aITemplateResolver
returned by callingcreateTemplateResolver()
.static org.thymeleaf.templateresolver.ITemplateResolver
createTemplateResolver()
Returns a new instance ofITemplateResolver
with default configuration (XHTML template model, templates located inside "/WEB-INF/templates/", suffixed by ".html".java.util.Locale
getLocale()
Returns the representation's locale.java.lang.String
getTemplateName()
Returns the template's name.protected void
setContext(org.thymeleaf.context.IContext context)
Sets the Thymeleaf context.void
setDataModel(java.util.Map<java.lang.String,java.lang.Object> dataModel)
Sets the template's data model.void
setDataModel(org.restlet.Request request, org.restlet.Response response)
Sets the template's data model from a request/response pair.void
setDataModel(org.restlet.util.Resolver<java.lang.Object> resolver)
Sets the template's data model from a resolver.void
setTemplateName(java.lang.String templateName)
Sets the template's name.void
write(java.io.Writer writer)
Writes the datum as a stream of characters.-
Methods inherited from class org.restlet.representation.CharacterRepresentation
getChannel, getStream, write, write
-
Methods inherited from class org.restlet.representation.Representation
append, exhaust, getAvailableSize, getDigest, getDisposition, getExpirationDate, getRange, getRegistration, getSize, getText, hasKnownSize, isAvailable, isEmpty, isSelectable, isTransient, release, setAvailable, setDigest, setDisposition, setExpirationDate, setListener, setRange, setSize, setTransient
-
Methods inherited from class org.restlet.representation.RepresentationInfo
getModificationDate, getTag, setModificationDate, setTag
-
-
-
-
Constructor Detail
-
TemplateRepresentation
public TemplateRepresentation(java.lang.String templateName, java.util.Locale locale, java.util.Map<java.lang.String,java.lang.Object> dataModel, org.restlet.data.MediaType mediaType)
Constructor.- Parameters:
templateName
- The Thymeleaf template's name. The actual template is retrieved using the Thymeleaf configuration.locale
- The locale of the template.dataModel
- The Thymeleaf template's data model.mediaType
- The representation's media type.
-
TemplateRepresentation
public TemplateRepresentation(java.lang.String templateName, java.util.Locale locale, org.restlet.data.MediaType mediaType)
Constructor.- Parameters:
templateName
- The Thymeleaf template's name. The full path is resolved by the configuration.locale
- The locale of the template.mediaType
- The representation's media type.
-
TemplateRepresentation
public TemplateRepresentation(java.lang.String templateName, org.thymeleaf.TemplateEngine engine, java.util.Locale locale, java.util.Map<java.lang.String,java.lang.Object> dataModel, org.restlet.data.MediaType mediaType)
Constructor.- Parameters:
templateName
- The Thymeleaf template's name. The actual template is retrieved using the Thymeleaf configuration.engine
- The template engine.locale
- The locale of the template.dataModel
- The Thymeleaf template's data model.mediaType
- The representation's media type.
-
TemplateRepresentation
public TemplateRepresentation(java.lang.String templateName, org.thymeleaf.TemplateEngine engine, java.util.Locale locale, org.restlet.data.MediaType mediaType)
Constructor.- Parameters:
templateName
- The Thymeleaf template's name. The full path is resolved by the configuration.locale
- The locale of the templatemediaType
- The representation's media type.
-
TemplateRepresentation
public TemplateRepresentation(TemplateRepresentation templateRepresentation, java.util.Locale locale, org.restlet.data.MediaType mediaType)
Constructor based on a Thymeleaf 'encoded' representation.- Parameters:
templateRepresentation
- The representation to 'decode'.locale
- The locale of the template.mediaType
- The representation's media type.
-
TemplateRepresentation
public TemplateRepresentation(TemplateRepresentation templateRepresentation, org.thymeleaf.TemplateEngine engine, java.util.Locale locale, org.restlet.data.MediaType mediaType)
Constructor based on a Thymeleaf 'encoded' representation.- Parameters:
templateRepresentation
- The representation to 'decode'.engine
- The template engine.locale
- The locale of the template.mediaType
- The representation's media type.
-
-
Method Detail
-
createTemplateEngine
public static org.thymeleaf.TemplateEngine createTemplateEngine()
Returns a new instance ofTemplateEngine
based by default on aITemplateResolver
returned by callingcreateTemplateResolver()
.- Returns:
- A new instance of
TemplateEngine
-
createTemplateEngine
public static org.thymeleaf.TemplateEngine createTemplateEngine(org.thymeleaf.templateresolver.ITemplateResolver resolver)
Returns a new instance ofTemplateEngine
based by default on aITemplateResolver
returned by callingcreateTemplateResolver()
.- Returns:
- A new instance of
TemplateEngine
-
createTemplateResolver
public static org.thymeleaf.templateresolver.ITemplateResolver createTemplateResolver()
Returns a new instance ofITemplateResolver
with default configuration (XHTML template model, templates located inside "/WEB-INF/templates/", suffixed by ".html".- Returns:
- A new instance of
ITemplateResolver
.
-
getLocale
public java.util.Locale getLocale()
Returns the representation's locale.- Returns:
- The representation's locale.
-
getTemplateName
public java.lang.String getTemplateName()
Returns the template's name.- Returns:
- The template's name.
-
setContext
protected void setContext(org.thymeleaf.context.IContext context)
Sets the Thymeleaf context.- Parameters:
context
- The Thymeleaf context
-
setDataModel
public void setDataModel(java.util.Map<java.lang.String,java.lang.Object> dataModel)
Sets the template's data model.- Parameters:
dataModel
- The template's data model.
-
setDataModel
public void setDataModel(org.restlet.Request request, org.restlet.Response response)
Sets the template's data model from a request/response pair. This default implementation uses a Resolver.- Parameters:
request
- The request where data are located.response
- The response where data are located.- See Also:
Resolver
,Resolver.createResolver(Request, Response)
-
setDataModel
public void setDataModel(org.restlet.util.Resolver<java.lang.Object> resolver)
Sets the template's data model from a resolver.- Parameters:
resolver
- The resolver.
-
setTemplateName
public void setTemplateName(java.lang.String templateName)
Sets the template's name.- Parameters:
templateName
- The template's name.
-
write
public void write(java.io.Writer writer) throws java.io.IOException
Writes the datum as a stream of characters.- Specified by:
write
in classorg.restlet.representation.Representation
- Parameters:
writer
- The writer to use when writing.- Throws:
java.io.IOException
-
-