org.restlet.ext.freemarker
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.freemarker.TemplateRepresentation

public class TemplateRepresentation
extends WriterRepresentation

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

Author:
Jerome Louvel
See Also:
FreeMarker home page

Field Summary
 
Fields inherited from class org.restlet.representation.Representation
UNKNOWN_SIZE
 
Constructor Summary
TemplateRepresentation(Representation templateRepresentation, Configuration config, MediaType mediaType)
          Constructor.
TemplateRepresentation(Representation templateRepresentation, Configuration config, Object dataModel, MediaType mediaType)
          Constructor.
TemplateRepresentation(Representation templateRepresentation, MediaType mediaType)
          Constructor.
TemplateRepresentation(Representation templateRepresentation, Object dataModel, MediaType mediaType)
          Constructor.
TemplateRepresentation(String templateName, Configuration config, MediaType mediaType)
          Constructor.
TemplateRepresentation(String templateName, Configuration config, Object dataModel, MediaType mediaType)
          Constructor.
TemplateRepresentation(Template template, MediaType mediaType)
          Constructor.
TemplateRepresentation(Template template, Object dataModel, MediaType mediaType)
          Constructor.
 
Method Summary
 Object getDataModel()
          Returns the template's data model.
 Template getTemplate()
          Returns the FreeMarker template.
static Template getTemplate(Configuration config, Representation templateRepresentation)
          Returns a FreeMarker template from a representation and a configuration.
static Template getTemplate(Configuration config, String templateName)
          Returns a FreeMarker template from its name and a configuration.
 Object setDataModel(Object dataModel)
          Sets the template's data model.
 Object setDataModel(Request request, Response response)
          Sets the template's data model from a request/response pair.
 Object setDataModel(Resolver<Object> resolver)
          Sets the template's data model from a resolver.
 void setTemplate(Template template)
          Sets the FreeMarker template.
 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,
                              Configuration config,
                              MediaType mediaType)
Constructor.

Parameters:
templateRepresentation - The FreeMarker template provided via a representation.
config - The FreeMarker configuration.
mediaType - The representation's media type.

TemplateRepresentation

public TemplateRepresentation(Representation templateRepresentation,
                              Configuration config,
                              Object dataModel,
                              MediaType mediaType)
Constructor.

Parameters:
templateRepresentation - The FreeMarker template provided via a representation.
config - The FreeMarker configuration.
dataModel - The template's data model.
mediaType - The representation's media type.

TemplateRepresentation

public TemplateRepresentation(Representation templateRepresentation,
                              MediaType mediaType)
Constructor.

Parameters:
templateRepresentation - The FreeMarker template provided via a representation.
mediaType - The representation's media type.

TemplateRepresentation

public TemplateRepresentation(Representation templateRepresentation,
                              Object dataModel,
                              MediaType mediaType)
Constructor. Uses a default FreeMarker configuration.

Parameters:
templateRepresentation - The FreeMarker template provided via a representation.
dataModel - The template's data model.
mediaType - The representation's media type.

TemplateRepresentation

public TemplateRepresentation(String templateName,
                              Configuration config,
                              MediaType mediaType)
Constructor.

Parameters:
templateName - The FreeMarker template's name. The full path is resolved by the configuration.
config - The FreeMarker configuration.
mediaType - The representation's media type.

TemplateRepresentation

public TemplateRepresentation(String templateName,
                              Configuration config,
                              Object dataModel,
                              MediaType mediaType)
Constructor.

Parameters:
templateName - The FreeMarker template's name. The full path is resolved by the configuration.
config - The FreeMarker configuration.
dataModel - The template's data model.
mediaType - The representation's media type.

TemplateRepresentation

public TemplateRepresentation(Template template,
                              MediaType mediaType)
Constructor.

Parameters:
template - The FreeMarker template.
mediaType - The representation's media type.

TemplateRepresentation

public TemplateRepresentation(Template template,
                              Object dataModel,
                              MediaType mediaType)
Constructor.

Parameters:
template - The FreeMarker template.
dataModel - The template's data model.
mediaType - The representation's media type.
Method Detail

getTemplate

public static Template getTemplate(Configuration config,
                                   Representation templateRepresentation)
Returns a FreeMarker template from a representation and a configuration.

Parameters:
config - The FreeMarker configuration.
templateRepresentation - The template representation.
Returns:
The template or null if not found.

getTemplate

public static Template getTemplate(Configuration config,
                                   String templateName)
Returns a FreeMarker template from its name and a configuration.

Parameters:
config - The FreeMarker configuration.
templateName - The template name.
Returns:
The template or null if not found.

getDataModel

public Object getDataModel()
Returns the template's data model.

Returns:
The template's data model.

getTemplate

public Template getTemplate()
Returns the FreeMarker template.

Returns:
The FreeMarker template.

setDataModel

public Object setDataModel(Object dataModel)
Sets the template's data model.

Parameters:
dataModel - The template's data model.
Returns:
The template's data model.

setDataModel

public Object 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.
Returns:
The template's data model.
See Also:
Resolver, Resolver.createResolver(Request, Response)

setDataModel

public Object setDataModel(Resolver<Object> resolver)
Sets the template's data model from a resolver.

Parameters:
resolver - The resolver.
Returns:
The template's data model.

setTemplate

public void setTemplate(Template template)
Sets the FreeMarker template.

Parameters:
template - The FreeMarker template.

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.