Class Resource

java.lang.Object
org.apache.velocity.runtime.resource.Resource
All Implemented Interfaces:
Cloneable
Direct Known Subclasses:
ContentResource, Template

public abstract class Resource extends Object implements Cloneable
This class represent a general text resource that may have been retrieved from any number of possible sources.
Version:
$Id$
Author:
Jason van Zyl, Geir Magnusson Jr.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected Object
    Resource might require ancillary storage of some kind
    protected String
    Character encoding of this resource
    protected long
    The file modification time (in milliseconds) for the cached template.
    protected org.slf4j.Logger
     
    protected static final long
    The number of milliseconds in a minute, used to calculate the check interval.
    protected long
    How often the file modification time is checked (in seconds).
    protected String
    Name of the resource
    protected long
    The next time the file modification time will be checked (in milliseconds).
    protected ResourceLoader
    The template loader that initially loaded the input stream for this template, and knows how to check the source of the input stream for modification.
    protected RuntimeServices
     
    protected int
    Resource type (RESOURCE_TEMPLATE or RESOURCE_CONTENT)
  • Constructor Summary

    Constructors
    Constructor
    Description
    Default constructor
  • Method Summary

    Modifier and Type
    Method
    Description
     
    protected void
    Deep cloning of resource data
    Get arbitrary data object that might be used by the resource.
    get the encoding of this resource for example, "ISO-8859-1"
    long
    Return the lastModifed time of this resource.
    Get the name of this template.
    Return the template loader that pulled in the template stream
    int
     
    boolean
     
    abstract boolean
    Perform any subsequent processing that might need to be done by a resource.
    boolean
    Is it time to check to see if the resource source has been updated?
    void
    Set arbitrary data object that might be used by the resource.
    void
    setEncoding(String encoding)
    set the encoding of this resource for example, "ISO-8859-1"
    void
    setLastModified(long lastModified)
    Set the last modified time for this resource.
    void
    setModificationCheckInterval(long modificationCheckInterval)
    Set the modification check interval.
    void
    Set the name of this resource, for example test.vm.
    void
    Set the template loader for this template.
    void
     
    void
    setType(int type)
    Sets the type of this Resource (RESOURCE_TEMPLATE or RESOURCE_CONTENT)
    void
    'Touch' this template and thereby resetting the nextCheck field.

    Methods inherited from class java.lang.Object

    equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • rsvc

      protected RuntimeServices rsvc
    • log

      protected org.slf4j.Logger log
    • resourceLoader

      protected ResourceLoader resourceLoader
      The template loader that initially loaded the input stream for this template, and knows how to check the source of the input stream for modification.
    • MILLIS_PER_SECOND

      protected static final long MILLIS_PER_SECOND
      The number of milliseconds in a minute, used to calculate the check interval.
      See Also:
    • modificationCheckInterval

      protected long modificationCheckInterval
      How often the file modification time is checked (in seconds).
    • lastModified

      protected long lastModified
      The file modification time (in milliseconds) for the cached template.
    • nextCheck

      protected long nextCheck
      The next time the file modification time will be checked (in milliseconds).
    • name

      protected String name
      Name of the resource
    • encoding

      protected String encoding
      Character encoding of this resource
    • data

      protected Object data
      Resource might require ancillary storage of some kind
    • type

      protected int type
      Resource type (RESOURCE_TEMPLATE or RESOURCE_CONTENT)
  • Constructor Details

    • Resource

      public Resource()
      Default constructor
  • Method Details

    • setRuntimeServices

      public void setRuntimeServices(RuntimeServices rs)
      Parameters:
      rs -
    • process

      public abstract boolean process() throws ResourceNotFoundException, ParseErrorException
      Perform any subsequent processing that might need to be done by a resource. In the case of a template the actual parsing of the input stream needs to be performed.
      Returns:
      Whether the resource could be processed successfully. For a Template or ContentResource, this indicates whether the resource could be read.
      Throws:
      ResourceNotFoundException - Similar in semantics as returning false.
      ParseErrorException
    • isSourceModified

      public boolean isSourceModified()
      Returns:
      True if source has been modified.
    • setModificationCheckInterval

      public void setModificationCheckInterval(long modificationCheckInterval)
      Set the modification check interval.
      Parameters:
      modificationCheckInterval - The interval (in seconds).
    • requiresChecking

      public boolean requiresChecking()
      Is it time to check to see if the resource source has been updated?
      Returns:
      True if resource must be checked.
    • touch

      public void touch()
      'Touch' this template and thereby resetting the nextCheck field.
    • setName

      public void setName(String name)
      Set the name of this resource, for example test.vm.
      Parameters:
      name -
    • getName

      public String getName()
      Get the name of this template.
      Returns:
      The name of this template.
    • setEncoding

      public void setEncoding(String encoding)
      set the encoding of this resource for example, "ISO-8859-1"
      Parameters:
      encoding -
    • getEncoding

      public String getEncoding()
      get the encoding of this resource for example, "ISO-8859-1"
      Returns:
      The encoding of this resource.
    • getLastModified

      public long getLastModified()
      Return the lastModifed time of this resource.
      Returns:
      The lastModifed time of this resource.
    • setLastModified

      public void setLastModified(long lastModified)
      Set the last modified time for this resource.
      Parameters:
      lastModified -
    • getResourceLoader

      public ResourceLoader getResourceLoader()
      Return the template loader that pulled in the template stream
      Returns:
      The resource loader for this resource.
    • setResourceLoader

      public void setResourceLoader(ResourceLoader resourceLoader)
      Set the template loader for this template. Set when the Runtime determines where this template came from the list of possible sources.
      Parameters:
      resourceLoader -
    • setData

      public void setData(Object data)
      Set arbitrary data object that might be used by the resource.
      Parameters:
      data -
    • getData

      public Object getData()
      Get arbitrary data object that might be used by the resource.
      Returns:
      The data object for this resource.
    • setType

      public void setType(int type)
      Sets the type of this Resource (RESOURCE_TEMPLATE or RESOURCE_CONTENT)
      Parameters:
      type - RESOURCE_TEMPLATE or RESOURCE_CONTENT
      Since:
      1.6
    • getType

      public int getType()
      Returns:
      type code of the Resource
      Since:
      1.6
    • clone

      public Object clone()
      Overrides:
      clone in class Object
      Returns:
      cloned resource
      Since:
      2.4
    • deepCloneData

      protected void deepCloneData() throws CloneNotSupportedException
      Deep cloning of resource data
      Throws:
      CloneNotSupportedException