Class ClasspathResourceLoader
java.lang.Object
org.apache.velocity.runtime.resource.loader.ResourceLoader
org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
ClasspathResourceLoader is a simple loader that will load
templates from the classpath.
Will load templates from from multiple instances of and arbitrary combinations of:
To use, put your template directories, jars and zip files into the classpath or other mechanisms that make resources accessible 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.
Will load templates from from multiple instances of and arbitrary combinations of:
- jar files
- zip files
- template directories (any directory containing templates)
resource.loaders = class
resource.loader.class.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 accessible 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$
- 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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionlonggetLastModified(Resource resource) Get the last modified time of the InputStream source that was used to create the template.getResourceReader(String name, String encoding) Get a Reader so that the Runtime can build a template with it.voidinit(ExtProperties configuration) This is abstract in the base class, so we need itbooleanisSourceModified(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
buildReader, commonInit, getClassName, getModificationCheckInterval, isCachingOn, resourceExists, setCachingOn, setModificationCheckInterval
-
Constructor Details
-
ClasspathResourceLoader
public ClasspathResourceLoader()
-
-
Method Details
-
init
This is abstract in the base class, so we need it- Specified by:
initin classResourceLoader- Parameters:
configuration-
-
getResourceReader
Get a Reader so that the Runtime can build a template with it.- Specified by:
getResourceReaderin classResourceLoader- Parameters:
name- name of template to getencoding- asked encoding- Returns:
- InputStream containing the template
- Throws:
ResourceNotFoundException- if template not found in classpath.- Since:
- 2.0
-
isSourceModified
Description copied from class:ResourceLoaderGiven a template, check to see if the source of InputStream has been modified.- Specified by:
isSourceModifiedin classResourceLoader- Parameters:
resource-- Returns:
- True if the resource has been modified.
- See Also:
-
getLastModified
Description copied from class:ResourceLoaderGet 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:
getLastModifiedin classResourceLoader- Parameters:
resource-- Returns:
- Time in millis when the resource has been modified.
- See Also:
-