Java Doc for VelocityViewServlet.java in  » Template-Engine » Velocity » org » apache » velocity » tools » view » servlet » 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 » Template Engine » Velocity » org.apache.velocity.tools.view.servlet 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


javax.servlet.http.HttpServlet
   org.apache.velocity.tools.view.servlet.VelocityViewServlet

All known Subclasses:   org.apache.velocity.tools.view.servlet.VelocityLayoutServlet,
VelocityViewServlet
public class VelocityViewServlet extends HttpServlet (Code)

A servlet to process Velocity templates. This is comparable to the the JspServlet for JSP-based applications.

The servlet provides the following features:

  • renders Velocity templates
  • provides support for an auto-loaded, configurable toolbox
  • provides transparent access to the servlet request attributes, servlet session attributes and servlet context attributes by auto-searching them
  • logs to the logging facility of the servlet API

VelocityViewServlet supports the following configuration parameters in web.xml:

org.apache.velocity.toolbox
Path and name of the toolbox configuration file. The path must be relative to the web application root directory. If this parameter is not found, the servlet will check for a toolbox file at '/WEB-INF/toolbox.xml'.
org.apache.velocity.properties
Path and name of the Velocity configuration file. The path must be relative to the web application root directory. If this parameter is not present, Velocity will check for a properties file at '/WEB-INF/velocity.properties'. If no file is found there, then Velocity is initialized with the settings in the classpath at 'org.apache.velocity.tools.view.servlet.velocity.properties'.

There are methods you may wish to override to access, alter or control any part of the request processing chain. Please see the javadocs for more information on :


author:
   Dave Bryson
author:
   Jon S. Stevens
author:
   Gabe Sidler
author:
   Geir Magnusson Jr.
author:
   Kent Johnson
author:
   Daniel Rall
author:
   Nathan Bubna
version:
   $Id: VelocityViewServlet.java 488468 2006-12-19 00:19:30Z nbubna $


Field Summary
final public static  StringCONTENT_TYPE
     The HTTP content type context key.
final public static  StringDEFAULT_CONTENT_TYPE
    
final public static  StringDEFAULT_OUTPUT_ENCODING
    
final protected static  StringDEFAULT_PROPERTIES_PATH
     Default velocity properties file path.
final protected static  StringDEFAULT_TOOLBOX_PATH
     Default toolbox configuration file path.
final public static  StringDEFAULT_TOOLS_PROPERTIES
     Default Runtime properties.
final protected static  StringINIT_PROPS_KEY
     This is the string that is looked for when getInitParameter is called ("org.apache.velocity.properties").
final public static  StringSERVLET_CONTEXT_KEY
     Key used to access the ServletContext in the Velocity application attributes.
final protected static  StringTOOLBOX_KEY
     Key used to access the toolbox configuration file path from the Servlet or webapp init parameters ("org.apache.velocity.toolbox").
protected  ToolboxManagertoolboxManager
     A reference to the toolbox manager.


Method Summary
protected  ContextcreateContext(HttpServletRequest request, HttpServletResponse response)
    

Creates and returns an initialized Velocity context.

A new context of class ChainedContext is created and initialized.
public  voiddoGet(HttpServletRequest request, HttpServletResponse response)
    
public  voiddoPost(HttpServletRequest request, HttpServletResponse response)
    
protected  voiddoRequest(HttpServletRequest request, HttpServletResponse response)
    
protected  voiderror(HttpServletRequest request, HttpServletResponse response, Exception e)
     Invoked when there is an error thrown in any part of doRequest() processing.
protected  StringfindInitParameter(ServletConfig config, String key)
     Looks up an init parameter with the specified key in either the ServletConfig or, failing that, in the ServletContext.
protected  WritergetResponseWriter(HttpServletResponse response)
    

Procure a Writer with correct encoding which can be used even if HttpServletResponse's getOutputStream() method has already been called.

This is a transitional method which will be removed in a future version of Velocity.

public  TemplategetTemplate(String name)
     Retrieves the requested template.
Parameters:
  name - The file name of the template to retrieve relative to thetemplate root.
public  TemplategetTemplate(String name, String encoding)
     Retrieves the requested template with the specified character encoding.
protected  VelocityEnginegetVelocityEngine()
     Returns the underlying VelocityEngine being used.
protected  StringgetVelocityProperty(String key, String alternate)
     Simplifies process of getting a property from VelocityEngine, because the VelocityEngine interface sucks compared to the singleton's.
protected  TemplatehandleRequest(HttpServletRequest request, HttpServletResponse response, Context ctx)
    
public  voidinit(ServletConfig config)
    

Initializes servlet, toolbox and Velocity template engine.

protected  voidinitToolbox(ServletConfig config)
     Initializes the ServletToolboxManager for this servlet's toolbox (if any).
protected  voidinitVelocity(ServletConfig config)
     Initializes the Velocity runtime, first calling loadConfiguration(ServletConfig) to get a org.apache.commons.collections.ExtendedProperties of configuration information and then calling velocityEngine.init().
protected  ExtendedPropertiesloadConfiguration(ServletConfig config)
     Loads the configuration information and returns that information as an ExtendedProperties, which will be used to initialize the Velocity runtime.
protected  voidmergeTemplate(Template template, Context context, HttpServletResponse response)
     Merges the template with the context.
protected  voidperformMerge(Template template, Context context, Writer writer)
     This is here so developers may override it and gain access to the Writer which the template will be merged into.
protected  voidrequestCleanup(HttpServletRequest request, HttpServletResponse response, Context context)
     Cleanup routine called at the end of the request processing sequence allows a derived class to do resource cleanup or other end of process cycle tasks.
protected  voidsetContentType(HttpServletRequest request, HttpServletResponse response)
     Sets the content type of the response.
protected  voidsetVelocityEngine(VelocityEngine ve)
    

Field Detail
CONTENT_TYPE
final public static String CONTENT_TYPE(Code)
The HTTP content type context key.



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



DEFAULT_OUTPUT_ENCODING
final public static String DEFAULT_OUTPUT_ENCODING(Code)
Default encoding for the output stream



DEFAULT_PROPERTIES_PATH
final protected static String DEFAULT_PROPERTIES_PATH(Code)
Default velocity properties file path. If no alternate value for this is specified, the servlet will look here.



DEFAULT_TOOLBOX_PATH
final protected static String DEFAULT_TOOLBOX_PATH(Code)
Default toolbox configuration file path. If no alternate value for this is specified, the servlet will look here.



DEFAULT_TOOLS_PROPERTIES
final public static String DEFAULT_TOOLS_PROPERTIES(Code)
Default Runtime properties.



INIT_PROPS_KEY
final protected static String INIT_PROPS_KEY(Code)
This is the string that is looked for when getInitParameter is called ("org.apache.velocity.properties").



SERVLET_CONTEXT_KEY
final public static String SERVLET_CONTEXT_KEY(Code)
Key used to access the ServletContext in the Velocity application attributes.



TOOLBOX_KEY
final protected static String TOOLBOX_KEY(Code)
Key used to access the toolbox configuration file path from the Servlet or webapp init parameters ("org.apache.velocity.toolbox").



toolboxManager
protected ToolboxManager toolboxManager(Code)
A reference to the toolbox manager.





Method Detail
createContext
protected Context createContext(HttpServletRequest request, HttpServletResponse response)(Code)

Creates and returns an initialized Velocity context.

A new context of class ChainedContext is created and initialized.
Parameters:
  request - servlet request from client
Parameters:
  response - servlet reponse to client



doGet
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException(Code)
Handles GET - calls doRequest()



doPost
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException(Code)
Handle a POST request - calls doRequest()



doRequest
protected void doRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException(Code)
Handles with both GET and POST requests
Parameters:
  request - HttpServletRequest object containing client request
Parameters:
  response - HttpServletResponse object for the response



error
protected void error(HttpServletRequest request, HttpServletResponse response, Exception e) throws ServletException(Code)
Invoked when there is an error thrown in any part of doRequest() processing.

Default will send a simple HTML response indicating there was a problem.
Parameters:
  request - original HttpServletRequest from servlet container.
Parameters:
  response - HttpServletResponse object from servlet container.
Parameters:
  e - Exception that was thrown by some other part of process.



findInitParameter
protected String findInitParameter(ServletConfig config, String key)(Code)
Looks up an init parameter with the specified key in either the ServletConfig or, failing that, in the ServletContext.



getResponseWriter
protected Writer getResponseWriter(HttpServletResponse response) throws UnsupportedEncodingException, IOException(Code)

Procure a Writer with correct encoding which can be used even if HttpServletResponse's getOutputStream() method has already been called.

This is a transitional method which will be removed in a future version of Velocity. It is not recommended that you override this method.


Parameters:
  response - The response. A Writer, possibly created using thegetOutputStream().



getTemplate
public Template getTemplate(String name) throws ResourceNotFoundException, ParseErrorException, Exception(Code)
Retrieves the requested template.
Parameters:
  name - The file name of the template to retrieve relative to thetemplate root. The requested template.
throws:
  ResourceNotFoundException - if template not foundfrom any available source.
throws:
  ParseErrorException - if template cannot be parsed dueto syntax (or other) error.
throws:
  Exception - if an error occurs in template initialization



getTemplate
public Template getTemplate(String name, String encoding) throws ResourceNotFoundException, ParseErrorException, Exception(Code)
Retrieves the requested template with the specified character encoding.
Parameters:
  name - The file name of the template to retrieve relative to thetemplate root.
Parameters:
  encoding - the character encoding of the template The requested template.
throws:
  ResourceNotFoundException - if template not foundfrom any available source.
throws:
  ParseErrorException - if template cannot be parsed dueto syntax (or other) error.
throws:
  Exception - if an error occurs in template initialization



getVelocityEngine
protected VelocityEngine getVelocityEngine()(Code)
Returns the underlying VelocityEngine being used.



getVelocityProperty
protected String getVelocityProperty(String key, String alternate)(Code)
Simplifies process of getting a property from VelocityEngine, because the VelocityEngine interface sucks compared to the singleton's. Use of this method assumes that VelocityViewServlet.initVelocity(ServletConfig) has already been called.



handleRequest
protected Template handleRequest(HttpServletRequest request, HttpServletResponse response, Context ctx) throws Exception(Code)

Handle the template processing request.


Parameters:
  request - client request
Parameters:
  response - client response
Parameters:
  ctx - VelocityContext to fill Velocity Template object or null



init
public void init(ServletConfig config) throws ServletException(Code)

Initializes servlet, toolbox and Velocity template engine. Called by the servlet container on loading.

NOTE: If no charset is specified in the default.contentType property (in your velocity.properties) and you have specified an output.encoding property, then that will be used as the charset for the default content-type of pages served by this servlet.


Parameters:
  config - servlet configuation



initToolbox
protected void initToolbox(ServletConfig config) throws ServletException(Code)
Initializes the ServletToolboxManager for this servlet's toolbox (if any).
Parameters:
  config - servlet configuation



initVelocity
protected void initVelocity(ServletConfig config) throws ServletException(Code)
Initializes the Velocity runtime, first calling loadConfiguration(ServletConfig) to get a org.apache.commons.collections.ExtendedProperties of configuration information and then calling velocityEngine.init(). Override this to do anything to the environment before the initialization of the singleton takes place, or to initialize the singleton in other ways.
Parameters:
  config - servlet configuration parameters



loadConfiguration
protected ExtendedProperties loadConfiguration(ServletConfig config) throws IOException(Code)
Loads the configuration information and returns that information as an ExtendedProperties, which will be used to initialize the Velocity runtime.

Currently, this method gets the initialization parameter VelocityServlet.INIT_PROPS_KEY, which should be a file containing the configuration information.

To configure your Servlet Spec 2.2 compliant servlet runner to pass this to you, put the following in your WEB-INF/web.xml file
 <servlet>
 <servlet-name> YourServlet </servlet-name>
 <servlet-class> your.package.YourServlet </servlet-class>
 <init-param>
 <param-name> org.apache.velocity.properties </param-name>
 <param-value> velocity.properties </param-value>
 </init-param>
 </servlet>
 
Alternately, if you wish to configure an entire context in this fashion, you may use the following:
 <context-param>
 <param-name> org.apache.velocity.properties </param-name>
 <param-value> velocity.properties </param-value>
 <description> Path to Velocity configuration </description>
 </context-param>
 
Derived classes may do the same, or take advantage of this code to do the loading for them via :
 ExtendedProperties p = super.loadConfiguration(config);
 
and then add or modify the configuration values from the file.

Parameters:
  config - ServletConfig passed to the servlets init() functionCan be used to access the real path via ServletContext (hint) ExtendedProperties loaded with configuration values to be usedto initialize the Velocity runtime.
throws:
  IOException - I/O problem accessing the specified file, if specified.



mergeTemplate
protected void mergeTemplate(Template template, Context context, HttpServletResponse response) throws ResourceNotFoundException, ParseErrorException, MethodInvocationException, IOException, UnsupportedEncodingException, Exception(Code)
Merges the template with the context. Only override this if you really, really really need to. (And don't call us with questions if it breaks :)
Parameters:
  template - template object returned by the handleRequest() method
Parameters:
  context - Context created by the VelocityViewServlet.createContext
Parameters:
  response - servlet reponse (used to get a Writer)



performMerge
protected void performMerge(Template template, Context context, Writer writer) throws ResourceNotFoundException, ParseErrorException, MethodInvocationException, Exception(Code)
This is here so developers may override it and gain access to the Writer which the template will be merged into. See VELTOOLS-7 for discussion of this.
Parameters:
  template - template object returned by the handleRequest() method
Parameters:
  context - Context created by the VelocityViewServlet.createContext
Parameters:
  writer - a VelocityWriter that the template is merged into



requestCleanup
protected void requestCleanup(HttpServletRequest request, HttpServletResponse response, Context context)(Code)
Cleanup routine called at the end of the request processing sequence allows a derived class to do resource cleanup or other end of process cycle tasks. This default implementation does nothing.
Parameters:
  request - servlet request from client
Parameters:
  response - servlet reponse
Parameters:
  context - Context created by the VelocityViewServlet.createContext



setContentType
protected void setContentType(HttpServletRequest request, HttpServletResponse response)(Code)
Sets the content type of the response. This is available to be overriden by a derived class.

The default implementation is :

 response.setContentType(defaultContentType);
 
where defaultContentType is set to the value of the default.contentType property, or "text/html" if that is not set.


Parameters:
  request - servlet request from client
Parameters:
  response - servlet reponse to client



setVelocityEngine
protected void setVelocityEngine(VelocityEngine ve)(Code)
Sets the underlying VelocityEngine



Methods inherited from javax.servlet.http.HttpServlet
protected void doDelete(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException(Code)(Java Doc)
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException(Code)(Java Doc)
protected void doHead(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException(Code)(Java Doc)
protected void doOptions(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException(Code)(Java Doc)
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException(Code)(Java Doc)
protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException(Code)(Java Doc)
protected void doTrace(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException(Code)(Java Doc)
protected long getLastModified(HttpServletRequest req)(Code)(Java Doc)
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException(Code)(Java Doc)
public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException(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.