Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

The procedure to create a personalized resource loader for Apache Velocity 2.0 is as follows:

  1. Create a new class that implements the org.apache.velocity.runtime.resource.loader.ResourceLoader interface.

  2. Override the getReader(String name, String encoding) method to return a java.io.Reader object that reads the contents of the specified resource.

  3. Override the init(ExtendedProperties configuration) method to initialize the resource loader with any configuration properties that may be needed.

  4. Override the getLastModified(String name) method to return a timestamp that represents the last time the resource was modified.

  5. Register the new resource loader with Velocity by calling the Velocity.addProperty(name, value) method with the name of the resource loader class and any configuration properties that may be needed.

  6. Use the personalized resource loader in your Velocity templates by specifying the name of the loader in the #set($resource.loader = "name") directive.

  7. Load the templates using the VelocityContext class and evaluate them by calling the evaluate(Writer writer, VelocityContext context, String logTag, String templateName) method.