Class JarResourceLoader
java.lang.Object
org.apache.velocity.runtime.resource.loader.ResourceLoader
org.apache.velocity.runtime.resource.loader.JarResourceLoader
ResourceLoader to load templates from multiple Jar files.
The configuration of the JarResourceLoader is straightforward - You simply add the JarResourceLoader to the configuration via
resource.loader = jar jar.resource.loader.class = org.apache.velocity.runtime.resource.loader.JarResourceLoader jar.resource.loader.path = list of JAR <URL>s
So for example, if you had a jar file on your local filesystem, you could simply do
jar.resource.loader.path = jar:file:/opt/myfiles/jar1.jar
Note that jar specification for the .path
configuration property
conforms to the same rules for the java.net.JarUrlConnection class.
For a working example, see the unit test case, org.apache.velocity.test.MultiLoaderTestCase class
- Version:
- $Id: JarResourceLoader.java 691884 2008-09-04 06:46:51Z nbubna $
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Map
Maps entries to the parent JAR File Key = the entry *excluding* plain directories Value = the JAR URLprivate Map
Maps JAR URLs to the actual JAR Key = the JAR URL Value = the JARFields inherited from class org.apache.velocity.runtime.resource.loader.ResourceLoader
className, isCachingOn, log, modificationCheckInterval, rsvc
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate void
addEntries
(Hashtable entries) Copy all the entries into the entryDirectory It will overwrite any duplicate keys.private void
Closes a Jar file and set its URLConnection to null.long
getLastModified
(Resource resource) Get the last modified time of the InputStream source that was used to create the template.getResourceStream
(String source) Get an InputStream so that the Runtime can build a template with it.void
init
(org.apache.commons.collections.ExtendedProperties configuration) Called by Velocity to initialize the loaderboolean
isSourceModified
(Resource resource) Given a template, check to see if the source of InputStream has been modified.private void
Methods inherited from class org.apache.velocity.runtime.resource.loader.ResourceLoader
commonInit, getClassName, getModificationCheckInterval, isCachingOn, resourceExists, setCachingOn, setModificationCheckInterval
-
Field Details
-
entryDirectory
Maps entries to the parent JAR File Key = the entry *excluding* plain directories Value = the JAR URL -
jarfiles
Maps JAR URLs to the actual JAR Key = the JAR URL Value = the JAR
-
-
Constructor Details
-
JarResourceLoader
public JarResourceLoader()
-
-
Method Details
-
init
public void init(org.apache.commons.collections.ExtendedProperties configuration) Called by Velocity to initialize the loader- Specified by:
init
in classResourceLoader
- Parameters:
configuration
-
-
loadJar
-
closeJar
Closes a Jar file and set its URLConnection to null. -
addEntries
Copy all the entries into the entryDirectory It will overwrite any duplicate keys. -
getResourceStream
Get an InputStream so that the Runtime can build a template with it.- Specified by:
getResourceStream
in classResourceLoader
- Parameters:
source
- name of template to get- Returns:
- InputStream containing the template
- Throws:
ResourceNotFoundException
- if template not found in the file template path.
-
isSourceModified
Description copied from class:ResourceLoader
Given a template, check to see if the source of InputStream has been modified.- Specified by:
isSourceModified
in classResourceLoader
- Returns:
- True if the resource has been modified.
- See Also:
-
getLastModified
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 classResourceLoader
- Returns:
- Time in millis when the resource has been modified.
- See Also:
-