Package org.apache.velocity.spring
Class SpringResourceLoader
- java.lang.Object
-
- org.apache.velocity.runtime.resource.loader.ResourceLoader
-
- org.apache.velocity.spring.SpringResourceLoader
-
public class SpringResourceLoader extends ResourceLoader
Velocity ResourceLoader adapter that loads via a Spring ResourceLoader. Used by VelocityEngineFactory for any resource loader path that cannot be resolved to ajava.io.File
.Note that this loader does not allow for modification detection: Use Velocity's default FileResourceLoader for
java.io.File
resources.Expects "spring.resource.loader" and "spring.resource.loader.path" application attributes in the Velocity runtime: the former of type
org.springframework.core.io.ResourceLoader
, the latter a String.- Since:
- 2020-05-29
- Author:
- Juergen Hoeller, Claude Brisson
- See Also:
VelocityEngineFactory.setResourceLoaderPath(java.lang.String)
,ResourceLoader
,FileResourceLoader
-
-
Field Summary
Fields Modifier and Type Field Description protected org.slf4j.Logger
logger
static String
NAME
static String
SPRING_RESOURCE_LOADER
static String
SPRING_RESOURCE_LOADER_CACHE
static String
SPRING_RESOURCE_LOADER_CLASS
static String
SPRING_RESOURCE_LOADER_PATH
-
Fields inherited from class org.apache.velocity.runtime.resource.loader.ResourceLoader
className, isCachingOn, log, modificationCheckInterval, rsvc
-
-
Constructor Summary
Constructors Constructor Description SpringResourceLoader()
-
Method Summary
All Methods Instance Methods Concrete Methods 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 the Reader that the Runtime will parse to create a template.void
init(ExtProperties configuration)
Initialize the template loader with a a resources class.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
-
-
-
-
Field Detail
-
NAME
public static final String NAME
- See Also:
- Constant Field Values
-
SPRING_RESOURCE_LOADER_CLASS
public static final String SPRING_RESOURCE_LOADER_CLASS
- See Also:
- Constant Field Values
-
SPRING_RESOURCE_LOADER_CACHE
public static final String SPRING_RESOURCE_LOADER_CACHE
- See Also:
- Constant Field Values
-
SPRING_RESOURCE_LOADER
public static final String SPRING_RESOURCE_LOADER
- See Also:
- Constant Field Values
-
SPRING_RESOURCE_LOADER_PATH
public static final String SPRING_RESOURCE_LOADER_PATH
- See Also:
- Constant Field Values
-
logger
protected final org.slf4j.Logger logger
-
-
Method Detail
-
init
public void init(ExtProperties configuration)
Description copied from class:ResourceLoader
Initialize the template loader with a a resources class.- Specified by:
init
in classResourceLoader
-
getResourceReader
public Reader getResourceReader(String source, String encoding) throws ResourceNotFoundException
Get the Reader that the Runtime will parse to create a template.- Specified by:
getResourceReader
in classResourceLoader
- Parameters:
source
- resource nameencoding
- resource encoding- Returns:
- The reader for the requested resource.
- Throws:
ResourceNotFoundException
- 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 classResourceLoader
- Returns:
- True if the resource has been modified.
-
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 classResourceLoader
- Returns:
- Time in millis when the resource has been modified.
-
-