Java Doc for VelocityView.java in  » J2EE » spring-framework-2.0.6 » org » springframework » web » servlet » view » velocity » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » spring framework 2.0.6 » org.springframework.web.servlet.view.velocity 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


org.springframework.web.servlet.view.AbstractTemplateView
   org.springframework.web.servlet.view.velocity.VelocityView

All known Subclasses:   org.springframework.web.servlet.view.velocity.VelocityToolboxView,
VelocityView
public class VelocityView extends AbstractTemplateView (Code)
View using the Velocity template engine.

Exposes the following JavaBean properties:

  • url: the location of the Velocity template to be wrapped, relative to the Velocity resource loader path (see VelocityConfigurer).
  • encoding (optional, default is determined by Velocity configuration): the encoding of the Velocity template file
  • velocityFormatterAttribute (optional, default=null): the name of the VelocityFormatter helper object to expose in the Velocity context of this view, or null if not needed. VelocityFormatter is part of standard Velocity.
  • dateToolAttribute (optional, default=null): the name of the DateTool helper object to expose in the Velocity context of this view, or null if not needed. DateTool is part of Velocity Tools 1.0.
  • numberToolAttribute (optional, default=null): the name of the NumberTool helper object to expose in the Velocity context of this view, or null if not needed. NumberTool is part of Velocity Tools 1.1.
  • cacheTemplate (optional, default=false): whether or not the Velocity template should be cached. It should normally be true in production, but setting this to false enables us to modify Velocity templates without restarting the application (similar to JSPs). Note that this is a minor optimization only, as Velocity itself caches templates in a modification-aware fashion.

Depends on a VelocityConfig object such as VelocityConfigurer being accessible in the current web application context, with any bean name. Alternatively, you can set the VelocityEngine object as bean property.

Note: Spring's VelocityView requires Velocity 1.3 or higher, and optionally Velocity Tools 1.0 or higher (depending on the use of DateTool and/or NumberTool).
author:
   Rod Johnson
author:
   Juergen Hoeller
See Also:   VelocityConfig
See Also:   VelocityConfigurer
See Also:   VelocityView.setUrl
See Also:   VelocityView.setExposeSpringMacroHelpers
See Also:   VelocityView.setEncoding
See Also:   VelocityView.setVelocityEngine
See Also:   VelocityConfig
See Also:   VelocityConfigurer





Method Summary
protected  VelocityEngineautodetectVelocityEngine()
     Autodetect a VelocityEngine via the ApplicationContext.
protected  voidcheckTemplate()
     Check that the Velocity template used for this view exists and is valid.
protected  ContextcreateVelocityContext(Map model, HttpServletRequest request, HttpServletResponse response)
     Create a Velocity Context instance for the given model, to be passed to the template for merging.

The default implementation delegates to VelocityView.createVelocityContext(Map) . Can be overridden for a special context class, for example ChainedContext which is part of the view package of Velocity Tools.

protected  ContextcreateVelocityContext(Map model)
     Create a Velocity Context instance for the given model, to be passed to the template for merging.
protected  voiddoRender(Context context, HttpServletResponse response)
     Render the Velocity view to the given response, using the given Velocity context which contains the complete template model to use.

The default implementation renders the template specified by the "url" bean property, retrieved via getTemplate.

protected  voidexposeHelpers(Map model, HttpServletRequest request)
     Expose helpers unique to each rendering operation.
protected  voidexposeHelpers(Context velocityContext, HttpServletRequest request, HttpServletResponse response)
     Expose helpers unique to each rendering operation.
protected  voidexposeHelpers(Context velocityContext, HttpServletRequest request)
     Expose helpers unique to each rendering operation.
protected  voidexposeToolAttributes(Context velocityContext, HttpServletRequest request)
     Expose the tool attributes, according to corresponding bean property settings.
protected  StringgetEncoding()
     Return the encoding for the Velocity template.
protected  TemplategetTemplate()
     Retrieve the Velocity template to be rendered by this view.
protected  TemplategetTemplate(String name)
     Retrieve the Velocity template specified by the given name, using the encoding specified by the "encoding" bean property.
protected  VelocityEnginegetVelocityEngine()
     Return the VelocityEngine used by this view.
protected  voidinitApplicationContext()
     Invoked on startup.
protected  voidinitTool(Object tool, Context velocityContext)
     Initialize the given tool instance.
protected  booleanisCacheTemplate()
     Return whether the Velocity template should be cached.
protected  voidmergeTemplate(Template template, Context context, HttpServletResponse response)
     Merge the template with the context.
protected  voidrenderMergedTemplateModel(Map model, HttpServletRequest request, HttpServletResponse response)
     Process the model map by merging it with the Velocity template.
public  voidsetCacheTemplate(boolean cacheTemplate)
     Set whether the Velocity template should be cached.
public  voidsetDateToolAttribute(String dateToolAttribute)
     Set the name of the DateTool helper object to expose in the Velocity context of this view, or null if not needed.
public  voidsetEncoding(String encoding)
     Set the encoding of the Velocity template file.
public  voidsetNumberToolAttribute(String numberToolAttribute)
     Set the name of the NumberTool helper object to expose in the Velocity context of this view, or null if not needed.
public  voidsetToolAttributes(Properties toolAttributes)
     Set tool attributes to expose to the view, as attribute name / class name pairs. An instance of the given class will be added to the Velocity context for each rendering operation, under the given attribute name.

For example, an instance of MathTool, which is part of the generic package of Velocity Tools, can be bound under the attribute name "math", specifying the fully qualified class name "org.apache.velocity.tools.generic.MathTool" as value.

Note that VelocityView can only create simple generic tools or values, that is, classes with a public default constructor and no further initialization needs. This class does not do any further checks, to not introduce a required dependency on a specific tools package.

For tools that are part of the view package of Velocity Tools, a special Velocity context and a special init callback are needed.

public  voidsetVelocityEngine(VelocityEngine velocityEngine)
     Set the VelocityEngine to be used by this view.
public  voidsetVelocityFormatterAttribute(String velocityFormatterAttribute)
     Set the name of the VelocityFormatter helper object to expose in the Velocity context of this view, or null if not needed.



Method Detail
autodetectVelocityEngine
protected VelocityEngine autodetectVelocityEngine() throws BeansException(Code)
Autodetect a VelocityEngine via the ApplicationContext. Called if no explicit VelocityEngine has been specified. the VelocityEngine to use for VelocityViews
throws:
  BeansException - if no VelocityEngine could be found
See Also:   VelocityView.getApplicationContext
See Also:   VelocityView.setVelocityEngine



checkTemplate
protected void checkTemplate() throws ApplicationContextException(Code)
Check that the Velocity template used for this view exists and is valid.

Can be overridden to customize the behavior, for example in case of multiple templates to be rendered into a single view.
throws:
  ApplicationContextException - if the template cannot be found or is invalid




createVelocityContext
protected Context createVelocityContext(Map model, HttpServletRequest request, HttpServletResponse response) throws Exception(Code)
Create a Velocity Context instance for the given model, to be passed to the template for merging.

The default implementation delegates to VelocityView.createVelocityContext(Map) . Can be overridden for a special context class, for example ChainedContext which is part of the view package of Velocity Tools. ChainedContext is needed for initialization of ViewTool instances.

Have a look at VelocityToolboxView , which pre-implements ChainedContext support. This is not part of the standard VelocityView class in order to avoid a required dependency on the view package of Velocity Tools.
Parameters:
  model - the model Map, containing the model attributes to be exposed to the view
Parameters:
  request - current HTTP request
Parameters:
  response - current HTTP response the Velocity Context
throws:
  Exception - if there's a fatal error while creating the context
See Also:   VelocityView.createVelocityContext(Map)
See Also:   VelocityView.initTool
See Also:   org.apache.velocity.tools.view.context.ChainedContext
See Also:   VelocityToolboxView




createVelocityContext
protected Context createVelocityContext(Map model) throws Exception(Code)
Create a Velocity Context instance for the given model, to be passed to the template for merging.

Default implementation creates an instance of Velocity's VelocityContext implementation class.
Parameters:
  model - the model Map, containing the model attributesto be exposed to the view the Velocity Context
throws:
  Exception - if there's a fatal error while creating the context
See Also:   org.apache.velocity.VelocityContext




doRender
protected void doRender(Context context, HttpServletResponse response) throws Exception(Code)
Render the Velocity view to the given response, using the given Velocity context which contains the complete template model to use.

The default implementation renders the template specified by the "url" bean property, retrieved via getTemplate. It delegates to the mergeTemplate method to merge the template instance with the given Velocity context.

Can be overridden to customize the behavior, for example to render multiple templates into a single view.
Parameters:
  context - the Velocity context to use for rendering
Parameters:
  response - servlet response (use this to get the OutputStream or Writer)
throws:
  Exception - if thrown by Velocity
See Also:   VelocityView.setUrl
See Also:   VelocityView.getTemplate()
See Also:   VelocityView.mergeTemplate




exposeHelpers
protected void exposeHelpers(Map model, HttpServletRequest request) throws Exception(Code)
Expose helpers unique to each rendering operation. This is necessary so that different rendering operations can't overwrite each other's formats etc.

Called by renderMergedTemplateModel. The default implementation is empty. This method can be overridden to add custom helpers to the model.
Parameters:
  model - the model that will be passed to the template for merging
Parameters:
  request - current HTTP request
throws:
  Exception - if there's a fatal error while we're adding model attributes
See Also:   VelocityView.renderMergedTemplateModel




exposeHelpers
protected void exposeHelpers(Context velocityContext, HttpServletRequest request, HttpServletResponse response) throws Exception(Code)
Expose helpers unique to each rendering operation. This is necessary so that different rendering operations can't overwrite each other's formats etc.

Called by renderMergedTemplateModel. Default implementation delegates to exposeHelpers(velocityContext, request). This method can be overridden to add special tools to the context, needing the servlet response to initialize (see Velocity Tools, for example LinkTool and ViewTool/ChainedContext).
Parameters:
  velocityContext - Velocity context that will be passed to the template
Parameters:
  request - current HTTP request
Parameters:
  response - current HTTP response
throws:
  Exception - if there's a fatal error while we're adding model attributes
See Also:   VelocityView.exposeHelpers(org.apache.velocity.context.Context,HttpServletRequest)




exposeHelpers
protected void exposeHelpers(Context velocityContext, HttpServletRequest request) throws Exception(Code)
Expose helpers unique to each rendering operation. This is necessary so that different rendering operations can't overwrite each other's formats etc.

Default implementation is empty. This method can be overridden to add custom helpers to the Velocity context.
Parameters:
  velocityContext - Velocity context that will be passed to the template
Parameters:
  request - current HTTP request
throws:
  Exception - if there's a fatal error while we're adding model attributes
See Also:   VelocityView.exposeHelpers(Map,HttpServletRequest)




exposeToolAttributes
protected void exposeToolAttributes(Context velocityContext, HttpServletRequest request) throws Exception(Code)
Expose the tool attributes, according to corresponding bean property settings.

Do not override this method unless for further tools driven by bean properties. Override one of the exposeHelpers methods to add custom helpers.
Parameters:
  velocityContext - Velocity context that will be passed to the template
Parameters:
  request - current HTTP request
throws:
  Exception - if there's a fatal error while we're adding model attributes
See Also:   VelocityView.setVelocityFormatterAttribute
See Also:   VelocityView.setDateToolAttribute
See Also:   VelocityView.setNumberToolAttribute
See Also:   VelocityView.exposeHelpers(Map,HttpServletRequest)
See Also:   VelocityView.exposeHelpers(org.apache.velocity.context.Context,HttpServletRequest,HttpServletResponse)




getEncoding
protected String getEncoding()(Code)
Return the encoding for the Velocity template.



getTemplate
protected Template getTemplate() throws Exception(Code)
Retrieve the Velocity template to be rendered by this view.

By default, the template specified by the "url" bean property will be retrieved: either returning a cached template instance or loading a fresh instance (according to the "cacheTemplate" bean property) the Velocity template to render
throws:
  Exception - if thrown by Velocity
See Also:   VelocityView.setUrl
See Also:   VelocityView.setCacheTemplate
See Also:   VelocityView.getTemplate(String)




getTemplate
protected Template getTemplate(String name) throws Exception(Code)
Retrieve the Velocity template specified by the given name, using the encoding specified by the "encoding" bean property.

Can be called by subclasses to retrieve a specific template, for example to render multiple templates into a single view.
Parameters:
  name - the file name of the desired template the Velocity template
throws:
  Exception - if thrown by Velocity
See Also:   org.apache.velocity.app.VelocityEngine.getTemplate




getVelocityEngine
protected VelocityEngine getVelocityEngine()(Code)
Return the VelocityEngine used by this view.



initApplicationContext
protected void initApplicationContext() throws BeansException(Code)
Invoked on startup. Looks for a single VelocityConfig bean to find the relevant VelocityEngine for this factory.



initTool
protected void initTool(Object tool, Context velocityContext) throws Exception(Code)
Initialize the given tool instance. The default implementation is empty.

Can be overridden to check for special callback interfaces, for example the ViewContext interface which is part of the view package of Velocity Tools. In the particular case of ViewContext, you'll usually also need a special Velocity context, like ChainedContext which is part of Velocity Tools too.

Have a look at VelocityToolboxView , which pre-implements such a ViewTool check. This is not part of the standard VelocityView class in order to avoid a required dependency on the view package of Velocity Tools.
Parameters:
  tool - the tool instance to initialize
Parameters:
  velocityContext - the Velocity context
throws:
  Exception - if initializion of the tool failed
See Also:   VelocityView.createVelocityContext
See Also:   org.apache.velocity.tools.view.context.ViewContext
See Also:   org.apache.velocity.tools.view.context.ChainedContext
See Also:   VelocityToolboxView




isCacheTemplate
protected boolean isCacheTemplate()(Code)
Return whether the Velocity template should be cached.



mergeTemplate
protected void mergeTemplate(Template template, Context context, HttpServletResponse response) throws Exception(Code)
Merge the template with the context. Can be overridden to customize the behavior.
Parameters:
  template - the template to merge
Parameters:
  context - the Velocity context to use for rendering
Parameters:
  response - servlet response (use this to get the OutputStream or Writer)
throws:
  Exception - if thrown by Velocity
See Also:   org.apache.velocity.Template.merge



renderMergedTemplateModel
protected void renderMergedTemplateModel(Map model, HttpServletRequest request, HttpServletResponse response) throws Exception(Code)
Process the model map by merging it with the Velocity template. Output is directed to the servlet response.

This method can be overridden if custom behavior is needed.




setCacheTemplate
public void setCacheTemplate(boolean cacheTemplate)(Code)
Set whether the Velocity template should be cached. Default is "false". It should normally be true in production, but setting this to false enables us to modify Velocity templates without restarting the application (similar to JSPs).

Note that this is a minor optimization only, as Velocity itself caches templates in a modification-aware fashion.




setDateToolAttribute
public void setDateToolAttribute(String dateToolAttribute)(Code)
Set the name of the DateTool helper object to expose in the Velocity context of this view, or null if not needed. The exposed DateTool will be aware of the current locale, as determined by Spring's LocaleResolver.

DateTool is part of the generic package of Velocity Tools 1.0. Spring uses a special locale-aware subclass of DateTool.
See Also:   org.apache.velocity.tools.generic.DateTool
See Also:   org.springframework.web.servlet.support.RequestContextUtils.getLocale
See Also:   org.springframework.web.servlet.LocaleResolver




setEncoding
public void setEncoding(String encoding)(Code)
Set the encoding of the Velocity template file. Default is determined by the VelocityEngine: "ISO-8859-1" if not specified otherwise.

Specify the encoding in the VelocityEngine rather than per template if all your templates share a common encoding.




setNumberToolAttribute
public void setNumberToolAttribute(String numberToolAttribute)(Code)
Set the name of the NumberTool helper object to expose in the Velocity context of this view, or null if not needed. The exposed NumberTool will be aware of the current locale, as determined by Spring's LocaleResolver.

NumberTool is part of the generic package of Velocity Tools 1.1. Spring uses a special locale-aware subclass of NumberTool.
See Also:   org.apache.velocity.tools.generic.NumberTool
See Also:   org.springframework.web.servlet.support.RequestContextUtils.getLocale
See Also:   org.springframework.web.servlet.LocaleResolver




setToolAttributes
public void setToolAttributes(Properties toolAttributes)(Code)
Set tool attributes to expose to the view, as attribute name / class name pairs. An instance of the given class will be added to the Velocity context for each rendering operation, under the given attribute name.

For example, an instance of MathTool, which is part of the generic package of Velocity Tools, can be bound under the attribute name "math", specifying the fully qualified class name "org.apache.velocity.tools.generic.MathTool" as value.

Note that VelocityView can only create simple generic tools or values, that is, classes with a public default constructor and no further initialization needs. This class does not do any further checks, to not introduce a required dependency on a specific tools package.

For tools that are part of the view package of Velocity Tools, a special Velocity context and a special init callback are needed. Use VelocityToolboxView in such a case, or override createVelocityContext and initTool accordingly.

For a simple VelocityFormatter instance or special locale-aware instances of DateTool/NumberTool, which are part of the generic package of Velocity Tools, specify the "velocityFormatterAttribute", "dateToolAttribute" or "numberToolAttribute" properties, respectively.
Parameters:
  toolAttributes - attribute names as keys, and tool class names as values
See Also:   org.apache.velocity.tools.generic.MathTool
See Also:   VelocityToolboxView
See Also:   VelocityView.createVelocityContext
See Also:   VelocityView.initTool
See Also:   VelocityView.setVelocityFormatterAttribute
See Also:   VelocityView.setDateToolAttribute
See Also:   VelocityView.setNumberToolAttribute




setVelocityEngine
public void setVelocityEngine(VelocityEngine velocityEngine)(Code)
Set the VelocityEngine to be used by this view. If this is not set, the default lookup will occur: A single VelocityConfig is expected in the current web application context, with any bean name.
See Also:   VelocityConfig



setVelocityFormatterAttribute
public void setVelocityFormatterAttribute(String velocityFormatterAttribute)(Code)
Set the name of the VelocityFormatter helper object to expose in the Velocity context of this view, or null if not needed.

VelocityFormatter is part of the standard Velocity distribution.
See Also:   org.apache.velocity.app.tools.VelocityFormatter




Fields inherited from org.springframework.web.servlet.view.AbstractTemplateView
final public static String SPRING_MACRO_REQUEST_CONTEXT_ATTRIBUTE(Code)(Java Doc)

Methods inherited from org.springframework.web.servlet.view.AbstractTemplateView
protected void applyContentType(HttpServletResponse response)(Code)(Java Doc)
final protected void renderMergedOutputModel(Map model, HttpServletRequest request, HttpServletResponse response) throws Exception(Code)(Java Doc)
abstract protected void renderMergedTemplateModel(Map model, HttpServletRequest request, HttpServletResponse response) throws Exception(Code)(Java Doc)
public void setAllowRequestOverride(boolean allowRequestOverride)(Code)(Java Doc)
public void setAllowSessionOverride(boolean allowSessionOverride)(Code)(Java Doc)
public void setExposeRequestAttributes(boolean exposeRequestAttributes)(Code)(Java Doc)
public void setExposeSessionAttributes(boolean exposeSessionAttributes)(Code)(Java Doc)
public void setExposeSpringMacroHelpers(boolean exposeSpringMacroHelpers)(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.