Package org.apache.velocity.runtime.resource.loader

# Class JarResourceLoader

java.lang.Object
org.apache.velocity.runtime.resource.loader.ResourceLoader
org.apache.velocity.runtime.resource.loader.JarResourceLoader

public class JarResourceLoader extends ResourceLoader

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.loaders = jar
        resource.loader.jar.class = org.apache.velocity.runtime.resource.loader.JarResourceLoader
        resource.loader.jar.path = list of JAR <URL>s

So for example, if you had a jar file on your local filesystem, you could simply do

        resource.loader.jar.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$
Author:
  Aki Nieminen, Dave Bryson

## Field Summary

### Fields inherited from class org.apache.velocity.runtime.resource.loader.ResourceLoader

`className, isCachingOn, log, modificationCheckInterval, rsvc`

## Constructor Summary

Constructors
Constructor
Description
`JarResourceLoader()`

## Method Summary

Modifier and Type
Method
Description
`long`
`getLastModified(Resource resource)`
Get the last modified time of the InputStream source that was used to create the template.
`Reader`
`getResourceReader(String source, String encoding)`
Get a Reader so that the Runtime can build a template with it.
`void`
`init(ExtProperties configuration)`
Called by Velocity to initialize the loader
`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

`buildReader, commonInit, getClassName, getModificationCheckInterval, isCachingOn, resourceExists, setCachingOn, setModificationCheckInterval`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### JarResourceLoader

public JarResourceLoader()

## Method Details

### init

public void init(ExtProperties configuration)
Called by Velocity to initialize the loader

Specified by:
  `init` in class `ResourceLoader`
Parameters:
  `configuration` -

### getResourceReader

public Reader getResourceReader(String source, String encoding) throws ResourceNotFoundException
Get a Reader so that the Runtime can build a template with it.

Specified by:
  `getResourceReader` in class `ResourceLoader`
Parameters:
  `source` - name of template to get
  `encoding` - asked encoding
Returns:
  InputStream containing the template
Throws:
  `ResourceNotFoundException` - if template not found in the file template path.
Since:
  2.0

### 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`
Parameters:
  `resource` -
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`
Parameters:
  `resource` -
Returns:
  Time in millis when the resource has been modified.
See Also:
  - `ResourceLoader.getLastModified(org.apache.velocity.runtime.resource.Resource)`