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


java.lang.Object
   org.apache.velocity.app.Velocity

Velocity
public class Velocity implements RuntimeConstants(Code)
This class provides services to the application developer, such as :
  • Simple Velocity Runtime engine initialization methods.
  • Functions to apply the template engine to streams and strings to allow embedding and dynamic template generation.
  • Methods to access Velocimacros directly.


While the most common way to use Velocity is via templates, as Velocity is a general-purpose template engine, there are other uses that Velocity is well suited for, such as processing dynamically created templates, or processing content streams.

The methods herein were developed to allow easy access to the Velocity facilities without direct spelunking of the internals. If there is something you feel is necessary to add here, please, send a patch.
author:
   Geir Magnusson Jr.
author:
   Christoph Reck
author:
   Jason van Zyl
version:
   $Id: Velocity.java 471381 2006-11-05 08:56:58Z wglass $




Method Summary
public static  voidaddProperty(String key, Object value)
     Add a Velocity Runtime property.
public static  voidclearProperty(String key)
     Clear a Velocity Runtime property.
public static  voiddebug(Object message)
    
public static  voiderror(Object message)
    
public static  booleanevaluate(Context context, Writer out, String logTag, String instring)
     renders the input string using the context into the output writer. To be used when a template is dynamically constructed, or want to use Velocity as a token replacer.
Parameters:
  context - context to use in rendering input string
Parameters:
  out - Writer in which to render the output
Parameters:
  logTag - string to be used as the template name for logmessages in case of error
Parameters:
  instring - input string containing the VTL to be rendered true if successful, false otherwise.
public static  booleanevaluate(Context context, Writer writer, String logTag, InputStream instream)
     Renders the input stream using the context into the output writer. To be used when a template is dynamically constructed, or want to use Velocity as a token replacer.
Parameters:
  context - context to use in rendering input string
Parameters:
  writer - Writer in which to render the output
Parameters:
  logTag - string to be used as the template name for log messagesin case of error
Parameters:
  instream - input stream containing the VTL to be rendered true if successful, false otherwise.
public static  booleanevaluate(Context context, Writer writer, String logTag, Reader reader)
     Renders the input reader using the context into the output writer. To be used when a template is dynamically constructed, or want to use Velocity as a token replacer.
Parameters:
  context - context to use in rendering input string
Parameters:
  writer - Writer in which to render the output
Parameters:
  logTag - string to be used as the template name for log messagesin case of error
Parameters:
  reader - Reader containing the VTL to be rendered true if successful, false otherwise.
public static  LoggetLog()
     Returns a convenient Log instance that wraps the current LogChute. Use this to log error messages.
public static  ObjectgetProperty(String key)
     Get a Velocity Runtime property.
public static  TemplategetTemplate(String name)
     Returns a Template from the Velocity resource management system.
Parameters:
  name - The file name of the desired template.
public static  TemplategetTemplate(String name, String encoding)
     Returns a Template from the Velocity resource management system.
Parameters:
  name - The file name of the desired template.
Parameters:
  encoding - The character encoding to use for the template.
public static  voidinfo(Object message)
    
public static  voidinit()
    
public static  voidinit(String propsFilename)
    
public static  voidinit(Properties p)
    
public static  booleaninvokeVelocimacro(String vmName, String logTag, String params, Context context, Writer writer)
     Invokes a currently registered Velocimacro with the parms provided and places the rendered stream into the writer. Note : currently only accepts args to the VM if they are in the context.
Parameters:
  vmName - name of Velocimacro to call
Parameters:
  logTag - string to be used for template name in case of error
Parameters:
  params - args used to invoke Velocimacro.
public static  booleanmergeTemplate(String templateName, Context context, Writer writer)
     Merges a template and puts the rendered stream into the writer. The default encoding that Velocity uses to read template files is defined in the property input.encoding and defaults to ISO-8859-1.
Parameters:
  templateName - name of template to be used in merge
Parameters:
  context - filled context to be used in merge
Parameters:
  writer - writer to write template into true if successful, false otherwise.
public static  booleanmergeTemplate(String templateName, String encoding, Context context, Writer writer)
     merges a template and puts the rendered stream into the writer
Parameters:
  templateName - name of template to be used in merge
Parameters:
  encoding - encoding used in template
Parameters:
  context - filled context to be used in merge
Parameters:
  writer - writer to write template into true if successful, false otherwise.
public static  booleanresourceExists(String resourceName)
    

Determines whether a resource is accessable via the currently configured resource loaders.

public static  voidsetApplicationAttribute(Object key, Object value)
    

Set the an ApplicationAttribue, which is an Object set by the application which is accessable from any component of the system that gets a RuntimeServices. This allows communication between the application environment and custom pluggable components of the Velocity engine, such as loaders and loggers.

Note that there is no enfocement or rules for the key used - it is up to the application developer.

public static  voidsetExtendedProperties(ExtendedProperties configuration)
     Set an entire configuration at once.
public static  voidsetProperty(String key, Object value)
     Set a Velocity Runtime property.
public static  booleantemplateExists(String resourceName)
    
Parameters:
  resourceName - Name of the Template to check.
public static  voidwarn(Object message)
    



Method Detail
addProperty
public static void addProperty(String key, Object value)(Code)
Add a Velocity Runtime property.
Parameters:
  key - The property key.
Parameters:
  value - The property value.



clearProperty
public static void clearProperty(String key)(Code)
Clear a Velocity Runtime property.
Parameters:
  key - of property to clear



debug
public static void debug(Object message)(Code)

See Also:   Log.debug(Object)
Parameters:
  message - The message to log.



error
public static void error(Object message)(Code)

See Also:   Log.error(Object)
Parameters:
  message - The message to log.



evaluate
public static boolean evaluate(Context context, Writer out, String logTag, String instring) throws ParseErrorException, MethodInvocationException, ResourceNotFoundException, IOException(Code)
renders the input string using the context into the output writer. To be used when a template is dynamically constructed, or want to use Velocity as a token replacer.
Parameters:
  context - context to use in rendering input string
Parameters:
  out - Writer in which to render the output
Parameters:
  logTag - string to be used as the template name for logmessages in case of error
Parameters:
  instring - input string containing the VTL to be rendered true if successful, false otherwise. If false, seeVelocity runtime log
throws:
  ParseErrorException - The template could not be parsed.
throws:
  MethodInvocationException - A method on a context object could not be invoked.
throws:
  ResourceNotFoundException - A referenced resource could not be loaded.
throws:
  IOException - While loading a reference, an I/O problem occured.



evaluate
public static boolean evaluate(Context context, Writer writer, String logTag, InputStream instream) throws ParseErrorException, MethodInvocationException, ResourceNotFoundException, IOException(Code)
Renders the input stream using the context into the output writer. To be used when a template is dynamically constructed, or want to use Velocity as a token replacer.
Parameters:
  context - context to use in rendering input string
Parameters:
  writer - Writer in which to render the output
Parameters:
  logTag - string to be used as the template name for log messagesin case of error
Parameters:
  instream - input stream containing the VTL to be rendered true if successful, false otherwise. If false, seeVelocity runtime logVelocity.evaluate(Context context,Writer writer,String logTag,Reader reader)
throws:
  ParseErrorException - The template could not be parsed.
throws:
  MethodInvocationException - A method on a context object could not be invoked.
throws:
  ResourceNotFoundException - A referenced resource could not be loaded.
throws:
  IOException - While loading a reference, an I/O problem occured.



evaluate
public static boolean evaluate(Context context, Writer writer, String logTag, Reader reader) throws ParseErrorException, MethodInvocationException, ResourceNotFoundException, IOException(Code)
Renders the input reader using the context into the output writer. To be used when a template is dynamically constructed, or want to use Velocity as a token replacer.
Parameters:
  context - context to use in rendering input string
Parameters:
  writer - Writer in which to render the output
Parameters:
  logTag - string to be used as the template name for log messagesin case of error
Parameters:
  reader - Reader containing the VTL to be rendered true if successful, false otherwise. If false, seeVelocity runtime log
throws:
  ParseErrorException - The template could not be parsed.
throws:
  MethodInvocationException - A method on a context object could not be invoked.
throws:
  ResourceNotFoundException - A referenced resource could not be loaded.
throws:
  IOException - While loading a reference, an I/O problem occured.
since:
   Velocity v1.1



getLog
public static Log getLog()(Code)
Returns a convenient Log instance that wraps the current LogChute. Use this to log error messages. It has the usual methods. A convenience Log instance that wraps the current LogChute.



getProperty
public static Object getProperty(String key)(Code)
Get a Velocity Runtime property.
Parameters:
  key - property to retrieve property value or null if the propertynot currently set



getTemplate
public static Template getTemplate(String name) throws ResourceNotFoundException, ParseErrorException, Exception(Code)
Returns a Template from the Velocity resource management system.
Parameters:
  name - The file name of the desired template. The 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 static Template getTemplate(String name, String encoding) throws ResourceNotFoundException, ParseErrorException, Exception(Code)
Returns a Template from the Velocity resource management system.
Parameters:
  name - The file name of the desired template.
Parameters:
  encoding - The character encoding to use for the template. The 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
since:
   Velocity v1.1



info
public static void info(Object message)(Code)

See Also:   Log.info(Object)
Parameters:
  message - The message to log.



init
public static void init() throws Exception(Code)
initialize the Velocity runtime engine, using the default properties of the Velocity distribution
throws:
  Exception - When an error during initialization occurs.



init
public static void init(String propsFilename) throws Exception(Code)
initialize the Velocity runtime engine, using default properties plus the properties in the properties file passed in as the arg
Parameters:
  propsFilename - file containing properties to use to initializethe Velocity runtime
throws:
  Exception - When an error during initialization occurs.



init
public static void init(Properties p) throws Exception(Code)
initialize the Velocity runtime engine, using default properties plus the properties in the passed in java.util.Properties object
Parameters:
  p - Properties object containing initialization properties
throws:
  Exception - When an error during initialization occurs.



invokeVelocimacro
public static boolean invokeVelocimacro(String vmName, String logTag, String params, Context context, Writer writer)(Code)
Invokes a currently registered Velocimacro with the parms provided and places the rendered stream into the writer. Note : currently only accepts args to the VM if they are in the context.
Parameters:
  vmName - name of Velocimacro to call
Parameters:
  logTag - string to be used for template name in case of error
Parameters:
  params - args used to invoke Velocimacro. In context key format :eg "foo","bar" (rather than "$foo","$bar")
Parameters:
  context - Context object containing data/objects used for rendering.
Parameters:
  writer - Writer for output stream true if Velocimacro exists and successfully invoked, false otherwise.



mergeTemplate
public static boolean mergeTemplate(String templateName, Context context, Writer writer) throws ResourceNotFoundException, ParseErrorException, MethodInvocationException, Exception(Code)
Merges a template and puts the rendered stream into the writer. The default encoding that Velocity uses to read template files is defined in the property input.encoding and defaults to ISO-8859-1.
Parameters:
  templateName - name of template to be used in merge
Parameters:
  context - filled context to be used in merge
Parameters:
  writer - writer to write template into true if successful, false otherwise. Errorslogged to velocity log.Velocity.mergeTemplate(String templateName,String encoding,Context context,Writer writer)
throws:
  ParseErrorException - The template could not be parsed.
throws:
  MethodInvocationException - A method on a context object could not be invoked.
throws:
  ResourceNotFoundException - A referenced resource could not be loaded.
throws:
  Exception - Any other exception.



mergeTemplate
public static boolean mergeTemplate(String templateName, String encoding, Context context, Writer writer) throws ResourceNotFoundException, ParseErrorException, MethodInvocationException, Exception(Code)
merges a template and puts the rendered stream into the writer
Parameters:
  templateName - name of template to be used in merge
Parameters:
  encoding - encoding used in template
Parameters:
  context - filled context to be used in merge
Parameters:
  writer - writer to write template into true if successful, false otherwise. Errorslogged to velocity log
throws:
  ParseErrorException - The template could not be parsed.
throws:
  MethodInvocationException - A method on a context object could not be invoked.
throws:
  ResourceNotFoundException - A referenced resource could not be loaded.
throws:
  Exception - Any other exception.
since:
   Velocity v1.1



resourceExists
public static boolean resourceExists(String resourceName)(Code)

Determines whether a resource is accessable via the currently configured resource loaders. org.apache.velocity.runtime.resource.Resource is the generic description of templates, static content, etc.

Note that the current implementation will not change the state of the system in any real way - so this cannot be used to pre-load the resource cache, as the previous implementation did as a side-effect.


Parameters:
  resourceName - The name of the resource to search for. Whether the resource was located.



setApplicationAttribute
public static void setApplicationAttribute(Object key, Object value)(Code)

Set the an ApplicationAttribue, which is an Object set by the application which is accessable from any component of the system that gets a RuntimeServices. This allows communication between the application environment and custom pluggable components of the Velocity engine, such as loaders and loggers.

Note that there is no enfocement or rules for the key used - it is up to the application developer. However, to help make the intermixing of components possible, using the target Class name (e.g. com.foo.bar ) as the key might help avoid collision.


Parameters:
  key - object 'name' under which the object is stored
Parameters:
  value - object to store under this key



setExtendedProperties
public static void setExtendedProperties(ExtendedProperties configuration)(Code)
Set an entire configuration at once. This is useful in cases where the parent application uses the ExtendedProperties class and the velocity configuration is a subset of the parent application's configuration.
Parameters:
  configuration - A configuration object.



setProperty
public static void setProperty(String key, Object value)(Code)
Set a Velocity Runtime property.
Parameters:
  key - The property key.
Parameters:
  value - The property value.



templateExists
public static boolean templateExists(String resourceName)(Code)

Parameters:
  resourceName - Name of the Template to check. True if the template exists.
See Also:   Velocity.resourceExists(String)



warn
public static void warn(Object message)(Code)

See Also:   Log.warn(Object)
Parameters:
  message - The message to log.



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(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.