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 a java.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:
  • Field Details

  • Constructor Details

    • SpringResourceLoader

      public SpringResourceLoader()
  • Method Details

    • init

      public void init(ExtProperties configuration)
      Description copied from class: ResourceLoader
      Initialize the template loader with a a resources class.
      Specified by:
      init in class ResourceLoader
      Parameters:
      configuration -
    • 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 class ResourceLoader
      Parameters:
      source - resource name
      encoding - 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 class ResourceLoader
      Parameters:
      resource -
      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 class ResourceLoader
      Parameters:
      resource -
      Returns:
      Time in millis when the resource has been modified.