Package org.restlet.ext.velocity
Class TemplateRepresentation
- java.lang.Object
-
public class TemplateRepresentation extends WriterRepresentation
Velocity template representation. Useful for dynamic string-based representations.- See Also:
- Velocity home page
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private classTemplateRepresentation.ResolverContextVelocity context based on a Resolver.
-
Field Summary
Fields Modifier and Type Field Description private org.apache.velocity.context.ContextcontextThe template's data model.private org.apache.velocity.app.VelocityEngineengineThe Velocity engine.private org.apache.velocity.TemplatetemplateThe template.private java.lang.StringtemplateNameThe template name.-
Fields inherited from class org.restlet.representation.Representation
UNKNOWN_SIZE
-
-
Constructor Summary
Constructors Constructor Description TemplateRepresentation(java.lang.String templateName, java.util.Map<java.lang.String,java.lang.Object> dataModel, MediaType mediaType)Constructor.TemplateRepresentation(java.lang.String templateName, MediaType mediaType)Constructor.TemplateRepresentation(org.apache.velocity.Template template, java.util.Map<java.lang.String,java.lang.Object> dataModel, MediaType mediaType)Constructor.TemplateRepresentation(org.apache.velocity.Template template, MediaType mediaType)Constructor.TemplateRepresentation(Representation templateRepresentation, java.util.Map<java.lang.String,java.lang.Object> dataModel, MediaType mediaType)Constructor based on a Velocity 'encoded' representation.TemplateRepresentation(Representation templateRepresentation, MediaType mediaType)Constructor based on a Velocity 'encoded' representation.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private org.apache.velocity.context.ContextgetContext()Returns the Velocity context.org.apache.velocity.app.VelocityEnginegetEngine()Returns the Velocity engine.org.apache.velocity.TemplategetTemplate()Returns the Velocity template.private voidsetContext(org.apache.velocity.context.Context context)Sets the Velocity context.voidsetDataModel(java.util.Map<java.lang.String,java.lang.Object> dataModel)Sets the template's data model.voidsetDataModel(Request request, Response response)Sets the template's data model from a request/response pair.voidsetDataModel(Resolver<java.lang.Object> resolver)Sets the template's data model from a resolver.voidwrite(java.io.Writer writer)Writes the datum as a stream of characters.-
Methods inherited from class org.restlet.representation.WriterRepresentation
getReader
-
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
-
Methods inherited from class org.restlet.representation.Variant
createClientInfo, equals, getCharacterSet, getEncodings, getLanguages, getLocationRef, getMediaType, hashCode, includes, isCompatible, setCharacterSet, setEncodings, setLanguages, setLocationRef, setLocationRef, setMediaType, toString
-
-
-
-
Field Detail
-
context
private volatile org.apache.velocity.context.Context context
The template's data model.
-
engine
private volatile org.apache.velocity.app.VelocityEngine engine
The Velocity engine.
-
template
private volatile org.apache.velocity.Template template
The template.
-
templateName
private volatile java.lang.String templateName
The template name.
-
-
Constructor Detail
-
TemplateRepresentation
public TemplateRepresentation(Representation templateRepresentation, java.util.Map<java.lang.String,java.lang.Object> dataModel, MediaType mediaType) throws org.apache.velocity.exception.ResourceNotFoundException, org.apache.velocity.exception.ParseErrorException, java.io.IOException
Constructor based on a Velocity 'encoded' representation.- Parameters:
templateRepresentation- The representation to 'decode'.dataModel- The Velocity template's data model.mediaType- The representation's media type.- Throws:
java.io.IOExceptionorg.apache.velocity.exception.ParseErrorExceptionorg.apache.velocity.exception.ResourceNotFoundException
-
TemplateRepresentation
public TemplateRepresentation(Representation templateRepresentation, MediaType mediaType) throws org.apache.velocity.exception.ResourceNotFoundException, org.apache.velocity.exception.ParseErrorException, java.io.IOException
Constructor based on a Velocity 'encoded' representation.- Parameters:
templateRepresentation- The representation to 'decode'.mediaType- The representation's media type.- Throws:
java.io.IOExceptionorg.apache.velocity.exception.ParseErrorExceptionorg.apache.velocity.exception.ResourceNotFoundException
-
TemplateRepresentation
public TemplateRepresentation(java.lang.String templateName, java.util.Map<java.lang.String,java.lang.Object> dataModel, MediaType mediaType)Constructor.- Parameters:
templateName- The Velocity template's name. The actual template is retrieved using the Velocity configuration.dataModel- The Velocity template's data model.mediaType- The representation's media type.
-
TemplateRepresentation
public TemplateRepresentation(java.lang.String templateName, MediaType mediaType)Constructor.- Parameters:
templateName- The Velocity template's name. The full path is resolved by the configuration.mediaType- The representation's media type.
-
TemplateRepresentation
public TemplateRepresentation(org.apache.velocity.Template template, java.util.Map<java.lang.String,java.lang.Object> dataModel, MediaType mediaType)Constructor.- Parameters:
template- The Velocity template.dataModel- The Velocity template's data model.mediaType- The representation's media type.
-
TemplateRepresentation
public TemplateRepresentation(org.apache.velocity.Template template, MediaType mediaType)Constructor.- Parameters:
template- The Velocity template.mediaType- The representation's media type.
-
-
Method Detail
-
getContext
private org.apache.velocity.context.Context getContext()
Returns the Velocity context.- Returns:
- The Velocity context.
-
getEngine
public org.apache.velocity.app.VelocityEngine getEngine()
Returns the Velocity engine.- Returns:
- The Velocity engine.
-
getTemplate
public org.apache.velocity.Template getTemplate()
Returns the Velocity template.- Returns:
- The Velocity template.
-
setContext
private void setContext(org.apache.velocity.context.Context context)
Sets the Velocity context.- Parameters:
context- The Velocity 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(Request request, 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(Resolver<java.lang.Object> resolver)
Sets the template's data model from a resolver.- Parameters:
resolver- The resolver.
-
write
public void write(java.io.Writer writer) throws java.io.IOExceptionWrites the datum as a stream of characters.- Specified by:
writein classRepresentation- Parameters:
writer- The writer to use when writing.- Throws:
java.io.IOException
-
-