org.apache.velocity.runtime.resource.loader
Class ClasspathResourceLoader

java.lang.Object
  extended by org.apache.velocity.runtime.resource.loader.ResourceLoader
      extended by org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader

public class ClasspathResourceLoader
extends ResourceLoader

ClasspathResourceLoader is a simple loader that will load templates from the classpath.

Will load templates from from multiple instances of and arbitrary combinations of :

This is a configuration-free loader, in that there are no parameters to be specified in the configuration properties, other than specifying this as the loader to use. For example the following is all that the loader needs to be functional :

resource.loader = class class.resource.loader.class = org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader

To use, put your template directories, jars and zip files into the classpath or other mechanisms that make resources accessable to the classloader.

This makes deployment trivial for web applications running in any Servlet 2.2 compliant servlet runner, such as Tomcat 3.2 and others.

For a Servlet Spec v2.2 servlet runner, just drop the jars of template files into the WEB-INF/lib directory of your webapp, and you won't have to worry about setting template paths or altering them with the root of the webapp before initializing.

I have also tried it with a WAR deployment, and that seemed to work just fine.

Version:
$Id: ClasspathResourceLoader.java 471259 2006-11-04 20:26:57Z henning $
Author:
Aki Nieminen, Geir Magnusson Jr.

Field Summary
 
Fields inherited from class org.apache.velocity.runtime.resource.loader.ResourceLoader
className, isCachingOn, log, modificationCheckInterval, rsvc
 
Constructor Summary
ClasspathResourceLoader()
           
 
Method Summary
 long getLastModified(Resource resource)
          Get the last modified time of the InputStream source that was used to create the template.
 InputStream getResourceStream(String name)
          Get an InputStream so that the Runtime can build a template with it.
 void init(ExtendedProperties configuration)
          This is abstract in the base class, so we need it
 boolean isSourceModified(Resource resource)
          Given a template, check to see if the source of InputStream has been modified.
 
Methods inherited from class org.apache.velocity.runtime.resource.loader.ResourceLoader
commonInit, getClassName, getModificationCheckInterval, isCachingOn, setCachingOn, setModificationCheckInterval
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClasspathResourceLoader

public ClasspathResourceLoader()
Method Detail

init

public void init(ExtendedProperties configuration)
This is abstract in the base class, so we need it

Specified by:
init in class ResourceLoader
Parameters:
configuration -

getResourceStream

public InputStream getResourceStream(String name)
                              throws ResourceNotFoundException
Get an InputStream so that the Runtime can build a template with it.

Specified by:
getResourceStream in class ResourceLoader
Parameters:
name - name of template to get
Returns:
InputStream containing the template
Throws:
ResourceNotFoundException - if template not found in classpath.

isSourceModified

public boolean isSourceModified(Resource resource)
Description copied from class: ResourceLoader
Given a template, check to see if the source of InputStream has been modified.

Specified by:
isSourceModified in class ResourceLoader
Returns:
True if the resource has been modified.
See Also:
ResourceLoader.isSourceModified(org.apache.velocity.runtime.resource.Resource)

getLastModified

public long getLastModified(Resource resource)
Description copied from class: ResourceLoader
Get the last modified time of the InputStream source that was used to create the template. We need the template here because we have to extract the name of the template in order to locate the InputStream source.

Specified by:
getLastModified in class ResourceLoader
Returns:
Time in millis when the resource has been modified.
See Also:
ResourceLoader.getLastModified(org.apache.velocity.runtime.resource.Resource)


Copyright © 2000-2007 The Apache Software Foundation. All Rights Reserved.