Package webwork.view.velocity
Class WebAppLoader
java.lang.Object
org.apache.velocity.runtime.resource.loader.ResourceLoader
webwork.view.velocity.WebAppLoader
public class WebAppLoader
extends org.apache.velocity.runtime.resource.loader.ResourceLoader
Resource loader that uses the ServletContext of a webapp to load Velocity templates. (it's much easier to use with
servlets than the standard FileResourceLoader, in particular the use of war files is transparent).
The default search path is '/' (relative to the webapp root), but you can change this behaviour by specifying one or
more paths by mean of as many webapp.resource.loader.path properties as needed in the velocity.properties file.
All paths must be relative to the root of the webapp.
NOTE: Shamelessly stolen from velocity-tools sources. We include it because it's a lot more civilised that lugging in
all of velo-tools just for a resource loader.
- Version:
- $Id: WebAppLoader.java,v 1.2 2003/11/16 04:54:53 fate Exp $
- Author:
- Geir Magnusson Jr., Nathan Bubna, Claude Brisson
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected String[]The root paths for templates (relative to webapp's root).protected javax.servlet.ServletContextFields inherited from class org.apache.velocity.runtime.resource.loader.ResourceLoader
className, isCachingOn, log, modificationCheckInterval, rsvc -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionlonggetLastModified(org.apache.velocity.runtime.resource.Resource resource) Defaults to return 0getResourceStream(String name) Get an InputStream so that the Runtime can build a template with it.voidinit(org.apache.commons.collections.ExtendedProperties configuration) This is abstract in the base class, so we need it.booleanisSourceModified(org.apache.velocity.runtime.resource.Resource resource) Defaults to return false.Methods inherited from class org.apache.velocity.runtime.resource.loader.ResourceLoader
commonInit, getClassName, getModificationCheckInterval, isCachingOn, resourceExists, setCachingOn, setModificationCheckInterval
-
Field Details
-
paths
The root paths for templates (relative to webapp's root). -
servletContext
protected javax.servlet.ServletContext servletContext
-
-
Constructor Details
-
WebAppLoader
public WebAppLoader()
-
-
Method Details
-
init
public void init(org.apache.commons.collections.ExtendedProperties configuration) This is abstract in the base class, so we need it.
NOTE: this expects that the ServletContext has already been placed in the runtime's application attributes under its full class name (i.e. "javax.servlet.ServletContext").- Specified by:
initin classorg.apache.velocity.runtime.resource.loader.ResourceLoader- Parameters:
configuration- theExtendedPropertiesassociated with this resource loader.
-
getResourceStream
public InputStream getResourceStream(String name) throws org.apache.velocity.exception.ResourceNotFoundException Get an InputStream so that the Runtime can build a template with it.- Specified by:
getResourceStreamin classorg.apache.velocity.runtime.resource.loader.ResourceLoader- Parameters:
name- name of template to get- Returns:
- InputStream containing the template
- Throws:
org.apache.velocity.exception.ResourceNotFoundException- if template not found in classpath.
-
isSourceModified
public boolean isSourceModified(org.apache.velocity.runtime.resource.Resource resource) Defaults to return false.- Specified by:
isSourceModifiedin classorg.apache.velocity.runtime.resource.loader.ResourceLoader
-
getLastModified
public long getLastModified(org.apache.velocity.runtime.resource.Resource resource) Defaults to return 0- Specified by:
getLastModifiedin classorg.apache.velocity.runtime.resource.loader.ResourceLoader
-