类 WebappResourceLoader

java.lang.Object
org.apache.velocity.runtime.resource.loader.ResourceLoader
org.apache.velocity.tools.view.WebappResourceLoader

public class WebappResourceLoader extends org.apache.velocity.runtime.resource.loader.ResourceLoader
Resource loader that uses the ServletContext of a webapp to load Velocity templates. (it's much easier to use with servlets than the standard FileResourceLoader, in particular the use of war files is transparent). The default search path is '/' (relative to the webapp root), but you can change this behaviour by specifying one or more paths by mean of as many webapp.resource.loader.path properties as needed in the velocity.properties file. All paths must be relative to the root of the webapp. To enable caching and cache refreshing the webapp.resource.loader.cache and webapp.resource.loader.modificationCheckInterval properties need to be set in the velocity.properties file ... auto-reloading of global macros requires the webapp.resource.loader.cache property to be set to 'false'.
版本:
$Id$
作者:
Geir Magnusson Jr., Nathan Bubna, Claude Brisson
  • 字段概要

    字段
    修饰符和类型
    字段
    说明
    protected String[]
    The root paths for templates (relative to webapp's root).
    protected jakarta.servlet.ServletContext
     
    protected HashMap
     

    从类继承的字段 org.apache.velocity.runtime.resource.loader.ResourceLoader

    className, isCachingOn, log, modificationCheckInterval, rsvc
  • 构造器概要

    构造器
    构造器
    说明
     
  • 方法概要

    修饰符和类型
    方法
    说明
    long
    getLastModified(org.apache.velocity.runtime.resource.Resource resource)
    Checks to see when a resource was last modified
    getResourceReader(String name, String encoding)
    Get Reader so that the Runtime can build a template with it.
    void
    init(org.apache.velocity.util.ExtProperties configuration)
    This is abstract in the base class, so we need it.
    boolean
    isSourceModified(org.apache.velocity.runtime.resource.Resource resource)
    Checks to see if a resource has been deleted, moved or modified.

    从类继承的方法 org.apache.velocity.runtime.resource.loader.ResourceLoader

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

    从类继承的方法 java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 字段详细资料

    • paths

      protected String[] paths
      The root paths for templates (relative to webapp's root).
    • templatePaths

      protected HashMap templatePaths
    • servletContext

      protected jakarta.servlet.ServletContext servletContext
  • 构造器详细资料

    • WebappResourceLoader

      public WebappResourceLoader()
  • 方法详细资料

    • init

      public void init(org.apache.velocity.util.ExtProperties configuration)
      This is abstract in the base class, so we need it.
      NOTE: this expects that the ServletContext has already been placed in the runtime's application attributes under its full class name (i.e. "javax.servlet.ServletContext").
      指定者:
      init 在类中 org.apache.velocity.runtime.resource.loader.ResourceLoader
      参数:
      configuration - the ExtProperties associated with this resource loader.
    • getResourceReader

      public Reader getResourceReader(String name, String encoding) throws org.apache.velocity.exception.ResourceNotFoundException
      Get Reader so that the Runtime can build a template with it.
      指定者:
      getResourceReader 在类中 org.apache.velocity.runtime.resource.loader.ResourceLoader
      参数:
      name - name of template to get
      encoding - asked encoding
      返回:
      InputStream containing the template
      抛出:
      org.apache.velocity.exception.ResourceNotFoundException - if template not found in classpath.
      从以下版本开始:
      2.0
    • isSourceModified

      public boolean isSourceModified(org.apache.velocity.runtime.resource.Resource resource)
      Checks to see if a resource has been deleted, moved or modified.
      指定者:
      isSourceModified 在类中 org.apache.velocity.runtime.resource.loader.ResourceLoader
      参数:
      resource - Resource The resource to check for modification
      返回:
      boolean True if the resource has been modified
    • getLastModified

      public long getLastModified(org.apache.velocity.runtime.resource.Resource resource)
      Checks to see when a resource was last modified
      指定者:
      getLastModified 在类中 org.apache.velocity.runtime.resource.loader.ResourceLoader
      参数:
      resource - Resource the resource to check
      返回:
      long The time when the resource was last modified or 0 if the file can't be read