NVelocity.App
Class VelocityEngine

This class provides a separate new-able instance of the Velocity template engine. The alternative model for use is using the Velocity class which employs the singleton model. Please ensure that you call one of the init() variants. This is critical for proper behavior. Coming soon : Velocity will call the parameter-less init() at the first use of this class if the init() wasn't explicitly called. While this will ensure that Velocity functions, it almost certainly won't function in the way you intend, so please make sure to call init().

Constructor Summary
VelocityEngine()
        Initializes a new instance of the VelocityEngine class.

Property Summary
Commons.Collections.ExtendedProperties ExtendedProperties
         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.

Method Summary
void AddProperty(string key, object value_Renamed)
         Add a Velocity Runtime property.
void ClearProperty(string key)
         Clear a Velocity Runtime property.
void Debug(object message)
         Log a debug message.
void Error(object message)
         Log an error message.
bool Evaluate(NVelocity.Context.IContext context, System.IO.TextWriter writer, string logTag, System.IO.TextReader 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.
bool Evaluate(NVelocity.Context.IContext context, System.IO.TextWriter writer, string logTag, System.IO.Stream 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.
bool Evaluate(NVelocity.Context.IContext context, System.IO.TextWriter out_Renamed, 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.
object GetProperty(string key)
         Get a Velocity Runtime property.
NVelocity.Template GetTemplate(string name, string encoding)
         Returns a
Template
from the Velocity resource management system.
NVelocity.Template GetTemplate(string name)
         Returns a
Template
from the Velocity resource management system.
void Info(object message)
         Log an info message.
void Init(Commons.Collections.ExtendedProperties p)
         initialize the Velocity runtime engine, using default properties plus the properties in the passed in java.util.Properties object
void Init(string propsFilename)
         initialize the Velocity runtime engine, using default properties plus the properties in the properties file passed in as the arg
void Init()
         initialize the Velocity runtime engine, using the default properties of the Velocity distribution
bool InvokeVelocimacro(string vmName, string logTag, string[] params_Renamed, NVelocity.Context.IContext context, System.IO.TextWriter 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.
bool MergeTemplate(string templateName, string encoding, NVelocity.Context.IContext context, System.IO.TextWriter writer)
         merges a template and puts the rendered stream into the writer
bool MergeTemplate(string templateName, NVelocity.Context.IContext context, System.IO.TextWriter writer)
         merges a template and puts the rendered stream into the writer
void SetApplicationAttribute(object key, object value_Renamed)
         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.
void SetProperty(string key, object value_Renamed)
         Set a Velocity Runtime property.
bool TemplateExists(string templateName)
void Warn(object message)
         Log a warning message.

Methods inherited from class System.Object
Equals, Finalize, GetHashCode, GetType, MemberwiseClone, ToString


Constructor Detail

VelocityEngine

public VelocityEngine()

Initializes a new instance of the VelocityEngine class.

Property Detail

ExtendedProperties

public Commons.Collections.ExtendedProperties ExtendedProperties

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:
ExtendedProperties - configuration
Method Detail

AddProperty

public void AddProperty(string key,
                        object value_Renamed)

Add a Velocity Runtime property.

Parameters:
String - key
Object - value

ClearProperty

public void ClearProperty(string key)

Clear a Velocity Runtime property.

Parameters:
key - of property to clear

Debug

public void Debug(object message)

Log a debug message.

Parameters:
Object - message to log

Error

public void Error(object message)

Log an error message.

Parameters:
Object - message to log

Evaluate

public bool Evaluate(NVelocity.Context.IContext context,
                     System.IO.TextWriter writer,
                     string logTag,
                     System.IO.TextReader 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
out - Writer in which to render the output
logTag - string to be used as the template name for log messages in case of error
reader - Reader containing the VTL to be rendered
Returns:
true if successful, false otherwise. If false, see Velocity runtime log @since Velocity v1.1

Evaluate

public bool Evaluate(NVelocity.Context.IContext context,
                     System.IO.TextWriter writer,
                     string logTag,
                     System.IO.Stream 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
out - Writer in which to render the output
logTag - string to be used as the template name for log messages in case of error
instream - input stream containing the VTL to be rendered
Returns:
true if successful, false otherwise. If false, see Velocity runtime log

Evaluate

public bool Evaluate(NVelocity.Context.IContext context,
                     System.IO.TextWriter out_Renamed,
                     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
out - Writer in which to render the output
logTag - string to be used as the template name for log messages in case of error
instring - input string containing the VTL to be rendered
Returns:
true if successful, false otherwise. If false, see Velocity runtime log

GetProperty

public object GetProperty(string key)

Get a Velocity Runtime property.

Parameters:
key - property to retrieve
Returns:
property value or null if the property not currently set

GetTemplate

public NVelocity.Template GetTemplate(string name,
                                      string encoding)

Returns a

Template
from the Velocity resource management system.

Parameters:
name - The file name of the desired template.
encoding - The character encoding to use for the template.
Returns:
The template. @throws ResourceNotFoundException if template not found from any available source. @throws ParseErrorException if template cannot be parsed due to syntax (or other) error. @throws Exception if an error occurs in template initialization @since Velocity v1.1

GetTemplate

public NVelocity.Template GetTemplate(string name)

Returns a

Template
from the Velocity resource management system.

Parameters:
name - The file name of the desired template.
Returns:
The template. @throws ResourceNotFoundException if template not found from any available source. @throws ParseErrorException if template cannot be parsed due to syntax (or other) error. @throws Exception if an error occurs in template initialization

Info

public void Info(object message)

Log an info message.

Parameters:
Object - message to log

Init

public void Init(Commons.Collections.ExtendedProperties p)

initialize the Velocity runtime engine, using default properties plus the properties in the passed in java.util.Properties object

Parameters:
p - Proprties object containing initialization properties

Init

public void Init(string propsFilename)

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 initialize the Velocity runtime

Init

public void Init()

initialize the Velocity runtime engine, using the default properties of the Velocity distribution


InvokeVelocimacro

public bool InvokeVelocimacro(string vmName,
                              string logTag,
                              string[] params_Renamed,
                              NVelocity.Context.IContext context,
                              System.IO.TextWriter 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
logTag - string to be used for template name in case of error
params[] - args used to invoke Velocimacro. In context key format : eg "foo","bar" (rather than "$foo","$bar")
context - Context object containing data/objects used for rendering.
writer - Writer for output stream
Returns:
true if Velocimacro exists and successfully invoked, false otherwise.

MergeTemplate

public bool MergeTemplate(string templateName,
                          string encoding,
                          NVelocity.Context.IContext context,
                          System.IO.TextWriter writer)

merges a template and puts the rendered stream into the writer

Parameters:
templateName - name of template to be used in merge
encoding - encoding used in template
context - filled context to be used in merge
writer - writer to write template into
Returns:
true if successful, false otherwise. Errors logged to velocity log @since Velocity v1.1

MergeTemplate

public bool MergeTemplate(string templateName,
                          NVelocity.Context.IContext context,
                          System.IO.TextWriter writer)

merges a template and puts the rendered stream into the writer

Parameters:
templateName - name of template to be used in merge
context - filled context to be used in merge
writer - writer to write template into
Returns:
true if successful, false otherwise. Errors logged to velocity log.

SetApplicationAttribute

public void SetApplicationAttribute(object key,
                                    object value_Renamed)

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
value - object to store under this key

SetProperty

public void SetProperty(string key,
                        object value_Renamed)

Set a Velocity Runtime property.

Parameters:
String - key
Object - value

TemplateExists

public bool TemplateExists(string templateName)


Warn

public void Warn(object message)

Log a warning message.

Parameters:
Object - message to log