Class FileResourceLoader
java.lang.Object
org.apache.velocity.runtime.resource.loader.ResourceLoader
org.apache.velocity.runtime.resource.loader.FileResourceLoader
A loader for templates stored on the file system. Treats the template
as relative to the configured root path. If the root path is empty
treats the template name as an absolute path.
- Version:
- $Id: FileResourceLoader.java 743616 2009-02-12 04:38:53Z nbubna $
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate ListThe paths to search for templates.private MapUsed to map the path that a template was found on so that we can properly check the modification times of the files.private booleanShall we inspect unicode files to see what encoding they contain?.Fields inherited from class org.apache.velocity.runtime.resource.loader.ResourceLoader
className, isCachingOn, log, modificationCheckInterval, rsvc -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate voidprivate InputStreamfindTemplate(String path, String template) Try to find a template given a normalized path.private FileCreate a File based on either a relative path if given, or absolute path otherwiselonggetLastModified(Resource resource) Get the last modified time of the InputStream source that was used to create the template.getResourceStream(String templateName) Get an InputStream so that the Runtime can build a template with it.voidinit(org.apache.commons.collections.ExtendedProperties configuration) Initialize the template loader with a a resources class.booleanisSourceModified(Resource resource) How to keep track of all the modified times across the paths.booleanresourceExists(String name) Overrides superclass for better performance.Methods inherited from class org.apache.velocity.runtime.resource.loader.ResourceLoader
commonInit, getClassName, getModificationCheckInterval, isCachingOn, setCachingOn, setModificationCheckInterval
-
Field Details
-
paths
The paths to search for templates. -
templatePaths
Used to map the path that a template was found on so that we can properly check the modification times of the files. This is synchronizedMap instance. -
unicode
private boolean unicodeShall we inspect unicode files to see what encoding they contain?.
-
-
Constructor Details
-
FileResourceLoader
public FileResourceLoader()
-
-
Method Details
-
init
public void init(org.apache.commons.collections.ExtendedProperties configuration) Description copied from class:ResourceLoaderInitialize the template loader with a a resources class.- Specified by:
initin classResourceLoader- See Also:
-
getResourceStream
Get an InputStream so that the Runtime can build a template with it.- Specified by:
getResourceStreamin classResourceLoader- Parameters:
templateName- name of template to get- Returns:
- InputStream containing the template
- Throws:
ResourceNotFoundException- if template not found in the file template path.
-
resourceExists
Overrides superclass for better performance.- Overrides:
resourceExistsin classResourceLoader- Parameters:
name- The name of a resource.- Returns:
- true if a resource exists and can be accessed.
- Since:
- 1.6
-
findTemplate
Try to find a template given a normalized path.- Parameters:
path- a normalized pathtemplate- name of template to find- Returns:
- InputStream input stream that will be parsed
- Throws:
IOException
-
closeQuiet
-
isSourceModified
How to keep track of all the modified times across the paths. Note that a file might have appeared in a directory which is earlier in the path; so we should search the path and see if the file we find that way is the same as the one that we have cached.- Specified by:
isSourceModifiedin classResourceLoader- Parameters:
resource-- Returns:
- True if the source has been modified.
-
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- Returns:
- Time in millis when the resource has been modified.
- See Also:
-
getFile
Create a File based on either a relative path if given, or absolute path otherwise
-