org.restlet.ext.velocity
Class TemplateRepresentation

java.lang.Object
  extended by org.restlet.representation.Variant
      extended by org.restlet.representation.RepresentationInfo
          extended by org.restlet.representation.Representation
              extended by org.restlet.representation.CharacterRepresentation
                  extended by org.restlet.representation.WriterRepresentation
                      extended by org.restlet.ext.velocity.TemplateRepresentation

public class TemplateRepresentation
extends WriterRepresentation

Velocity template representation. Useful for dynamic string-based representations.

Author:
Jerome Louvel
See Also:
Velocity home page

Field Summary
 
Fields inherited from class org.restlet.representation.Representation
UNKNOWN_SIZE
 
Constructor Summary
TemplateRepresentation(Representation templateRepresentation, Map<String,Object> dataModel, MediaType mediaType)
          Constructor based on a Velocity 'encoded' representation.
TemplateRepresentation(Representation templateRepresentation, MediaType mediaType)
          Constructor based on a Velocity 'encoded' representation.
TemplateRepresentation(String templateName, Map<String,Object> dataModel, MediaType mediaType)
          Constructor.
TemplateRepresentation(String templateName, MediaType mediaType)
          Constructor.
TemplateRepresentation(Template template, Map<String,Object> dataModel, MediaType mediaType)
          Constructor.
TemplateRepresentation(Template template, MediaType mediaType)
          Constructor.
 
Method Summary
 VelocityEngine getEngine()
          Returns the Velocity engine.
 Template getTemplate()
          Returns the Velocity template.
 void setDataModel(Map<String,Object> dataModel)
          Sets the template's data model.
 void setDataModel(Request request, Response response)
          Sets the template's data model from a request/response pair.
 void setDataModel(Resolver<Object> resolver)
          Sets the template's data model from a resolver.
 void write(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, includes, isCompatible, setCharacterSet, setEncodings, setLanguages, setLocationRef, setLocationRef, setMediaType, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TemplateRepresentation

public TemplateRepresentation(Representation templateRepresentation,
                              Map<String,Object> dataModel,
                              MediaType mediaType)
                       throws ResourceNotFoundException,
                              ParseErrorException,
                              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:
IOException
ParseErrorException
ResourceNotFoundException

TemplateRepresentation

public TemplateRepresentation(Representation templateRepresentation,
                              MediaType mediaType)
                       throws ResourceNotFoundException,
                              ParseErrorException,
                              IOException
Constructor based on a Velocity 'encoded' representation.

Parameters:
templateRepresentation - The representation to 'decode'.
mediaType - The representation's media type.
Throws:
IOException
ParseErrorException
ResourceNotFoundException

TemplateRepresentation

public TemplateRepresentation(String templateName,
                              Map<String,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(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(Template template,
                              Map<String,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(Template template,
                              MediaType mediaType)
Constructor.

Parameters:
template - The Velocity template.
mediaType - The representation's media type.
Method Detail

getEngine

public VelocityEngine getEngine()
Returns the Velocity engine.

Returns:
The Velocity engine.

getTemplate

public Template getTemplate()
Returns the Velocity template.

Returns:
The Velocity template.

setDataModel

public void setDataModel(Map<String,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<Object> resolver)
Sets the template's data model from a resolver.

Parameters:
resolver - The resolver.

write

public void write(Writer writer)
           throws IOException
Writes the datum as a stream of characters.

Specified by:
write in class Representation
Parameters:
writer - The writer to use when writing.
Throws:
IOException


Copyright © 2005-2013 Restlet.