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>sSo 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.jarNote that jar specification for the
.pathconfiguration 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$
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map<java.lang.String,java.lang.String>entryDirectoryMaps entries to the parent JAR File Key = the entry *excluding* plain directories Value = the JAR URLprivate java.util.Map<java.lang.String,JarHolder>jarfilesMaps JAR URLs to the actual JAR Key = the JAR URL Value = the JAR-
Fields inherited from class org.apache.velocity.runtime.resource.loader.ResourceLoader
className, isCachingOn, log, modificationCheckInterval, rsvc
-
-
Constructor Summary
Constructors Constructor Description JarResourceLoader()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidaddEntries(java.util.Map<java.lang.String,java.lang.String> entries)Copy all the entries into the entryDirectory It will overwrite any duplicate keys.private voidcloseJar(java.lang.String path)Closes a Jar file and set its URLConnection to null.longgetLastModified(Resource resource)Get the last modified time of the InputStream source that was used to create the template.java.io.ReadergetResourceReader(java.lang.String source, java.lang.String encoding)Get a Reader so that the Runtime can build a template with it.voidinit(ExtProperties configuration)Called by Velocity to initialize the loaderbooleanisSourceModified(Resource resource)Given a template, check to see if the source of InputStream has been modified.private voidloadJar(java.lang.String path)-
Methods inherited from class org.apache.velocity.runtime.resource.loader.ResourceLoader
buildReader, commonInit, getClassName, getModificationCheckInterval, isCachingOn, resourceExists, setCachingOn, setModificationCheckInterval
-
-
-
-
Field Detail
-
entryDirectory
private java.util.Map<java.lang.String,java.lang.String> entryDirectory
Maps entries to the parent JAR File Key = the entry *excluding* plain directories Value = the JAR URL
-
jarfiles
private java.util.Map<java.lang.String,JarHolder> jarfiles
Maps JAR URLs to the actual JAR Key = the JAR URL Value = the JAR
-
-
Method Detail
-
init
public void init(ExtProperties configuration)
Called by Velocity to initialize the loader- Specified by:
initin classResourceLoader- Parameters:
configuration-
-
loadJar
private void loadJar(java.lang.String path)
-
closeJar
private void closeJar(java.lang.String path)
Closes a Jar file and set its URLConnection to null.
-
addEntries
private void addEntries(java.util.Map<java.lang.String,java.lang.String> entries)
Copy all the entries into the entryDirectory It will overwrite any duplicate keys.
-
getResourceReader
public java.io.Reader getResourceReader(java.lang.String source, java.lang.String encoding) throws ResourceNotFoundExceptionGet a Reader so that the Runtime can build a template with it.- Specified by:
getResourceReaderin classResourceLoader- Parameters:
source- name of template to getencoding- 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:ResourceLoaderGiven a template, check to see if the source of InputStream has been modified.- Specified by:
isSourceModifiedin classResourceLoader- 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: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- Returns:
- Time in millis when the resource has been modified.
- See Also:
ResourceLoader.getLastModified(org.apache.velocity.runtime.resource.Resource)
-
-