org.abstracthorizon.danube.velocity
Class VelocityViewAdapter

java.lang.Object
  extended by org.abstracthorizon.danube.velocity.VelocityViewAdapter
All Implemented Interfaces:
View

public class VelocityViewAdapter
extends Object
implements View

This is implementation of View that uses Velocity template engine. Model map is used as map of parameters for Velocity.

This implementation is based on VelocityServlet

Author:
Daniel Sendula

Field Summary
static String CONTENT_TYPE
          The HTTP content type context key.
protected  String contentType
          The default content type.
static String DEFAULT_CONTENT_TYPE
          The default content type for the response
static String DEFAULT_OUTPUT_ENCODING
          Default encoding for the output stream
protected  String suffix
          Template suffix
protected  File templatesPath
          Path where templates are stored
protected  URL templatesURL
          Path where templates are stored
 
Constructor Summary
VelocityViewAdapter()
          Constructor.
 
Method Summary
protected  org.apache.velocity.context.Context createContext(Map attributes)
          Creates context based on provided model's map
protected  org.apache.velocity.Template findTemplate(org.apache.velocity.context.Context ctx, String view)
          This method finds template based on view name and ".vm" file extension.
 String getContentType()
          Returns default content type
 String getSuffix()
          Returns template suffix.
 File getTemplatesPath()
          Returns path where templates are stored
 URL getTemplatesURL()
          Returns URL where templates are stored
 void init()
          This metod initialises Velocity engine.
protected  void mergeTemplate(org.apache.velocity.Template template, org.apache.velocity.context.Context context, HTTPConnection connection)
          Generates output from given template
 void render(Connection connection, ModelAndView modelAndView)
          This method renders output
 void setContentType(String contentType)
          Sets default content type
 void setSuffix(String suffix)
          Sets suffix of templates
 void setTemplatesPath(File templatesPath)
          Sets path where templates are stored
 void setTemplatesURL(URL templatesURL)
          Sets URL where templates are stored
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CONTENT_TYPE

public static final String CONTENT_TYPE
The HTTP content type context key.

See Also:
Constant Field Values

DEFAULT_CONTENT_TYPE

public static final String DEFAULT_CONTENT_TYPE
The default content type for the response

See Also:
Constant Field Values

DEFAULT_OUTPUT_ENCODING

public static final String DEFAULT_OUTPUT_ENCODING
Default encoding for the output stream

See Also:
Constant Field Values

templatesURL

protected URL templatesURL
Path where templates are stored


templatesPath

protected File templatesPath
Path where templates are stored


suffix

protected String suffix
Template suffix


contentType

protected String contentType
The default content type. When necessary, includes the character set to use when encoding textual output.

Constructor Detail

VelocityViewAdapter

public VelocityViewAdapter()
                    throws Exception
Constructor.

Throws:
Exception
Method Detail

init

public void init()
          throws InitializationException
This metod initialises Velocity engine.

Throws:
Exception
InitializationException

render

public void render(Connection connection,
                   ModelAndView modelAndView)
            throws ConnectionException
This method renders output

Specified by:
render in interface View
Parameters:
connection - http connection
modelAndView - view name to be used as template's name and model map to be used as attributes throws ConnectionException
Throws:
ConnectionException

findTemplate

protected org.apache.velocity.Template findTemplate(org.apache.velocity.context.Context ctx,
                                                    String view)
                                             throws Exception
This method finds template based on view name and ".vm" file extension. Template is located in provided #templatesLocation

Parameters:
ctx - velocity context
templateFile -
Returns:
template
Throws:
Exception

createContext

protected org.apache.velocity.context.Context createContext(Map attributes)
Creates context based on provided model's map

Parameters:
attributes - model's map
Returns:
velocity context

mergeTemplate

protected void mergeTemplate(org.apache.velocity.Template template,
                             org.apache.velocity.context.Context context,
                             HTTPConnection connection)
                      throws Exception
Generates output from given template

Parameters:
template - template
context - velocity context
connection - http connection result to be rendered to
Throws:
Exception

getTemplatesPath

public File getTemplatesPath()
Returns path where templates are stored

Returns:
Returns the templatePath.

setTemplatesPath

public void setTemplatesPath(File templatesPath)
Sets path where templates are stored

Parameters:
templatesPath - path where templates are stored.

getTemplatesURL

public URL getTemplatesURL()
Returns URL where templates are stored

Returns:
returns the templates URL

setTemplatesURL

public void setTemplatesURL(URL templatesURL)
Sets URL where templates are stored

Parameters:
templatesURL - URL where templates are stored.

getContentType

public String getContentType()
Returns default content type

Returns:
default content type

setContentType

public void setContentType(String contentType)
Sets default content type

Parameters:
contentType - default content type

getSuffix

public String getSuffix()
Returns template suffix. If not set it is then initialised to ".vm"

Returns:
template suffix

setSuffix

public void setSuffix(String suffix)
Sets suffix of templates

Parameters:
suffix - suffix of templates


Copyright © 2005-2009 Abstract Horizon. All Rights Reserved.