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 SummaryFields Modifier and Type Field Description protected ObjectdataResource might require ancillary storage of some kindprotected StringencodingCharacter encoding of this resourceprotected longlastModifiedThe file modification time (in milliseconds) for the cached template.protected org.slf4j.Loggerlogprotected static longMILLIS_PER_SECONDThe number of milliseconds in a minute, used to calculate the check interval.protected longmodificationCheckIntervalHow often the file modification time is checked (in seconds).protected StringnameName of the resourceprotected longnextCheckThe next time the file modification time will be checked (in milliseconds).protected ResourceLoaderresourceLoaderThe 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 RuntimeServicesrsvcprotected inttypeResource type (RESOURCE_TEMPLATE or RESOURCE_CONTENT)
 - 
Constructor SummaryConstructors Constructor Description Resource()Default constructor
 - 
Method SummaryAll Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description Objectclone()protected voiddeepCloneData()Deep cloning of resource dataObjectgetData()Get arbitrary data object that might be used by the resource.StringgetEncoding()get the encoding of this resource for example, "ISO-8859-1"longgetLastModified()Return the lastModifed time of this resource.StringgetName()Get the name of this template.ResourceLoadergetResourceLoader()Return the template loader that pulled in the template streamintgetType()booleanisSourceModified()abstract booleanprocess()Perform any subsequent processing that might need to be done by a resource.booleanrequiresChecking()Is it time to check to see if the resource source has been updated?voidsetData(Object data)Set arbitrary data object that might be used by the resource.voidsetEncoding(String encoding)set the encoding of this resource for example, "ISO-8859-1"voidsetLastModified(long lastModified)Set the last modified time for this resource.voidsetModificationCheckInterval(long modificationCheckInterval)Set the modification check interval.voidsetName(String name)Set the name of this resource, for example test.vm.voidsetResourceLoader(ResourceLoader resourceLoader)Set the template loader for this template.voidsetRuntimeServices(RuntimeServices rs)voidsetType(int type)Sets the type of this Resource (RESOURCE_TEMPLATE or RESOURCE_CONTENT)voidtouch()'Touch' this template and thereby resetting the nextCheck field.
 
- 
- 
- 
Field Detail- 
rsvcprotected RuntimeServices rsvc 
 - 
logprotected org.slf4j.Logger log 
 - 
resourceLoaderprotected 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_SECONDprotected static final long MILLIS_PER_SECOND The number of milliseconds in a minute, used to calculate the check interval.- See Also:
- Constant Field Values
 
 - 
modificationCheckIntervalprotected long modificationCheckInterval How often the file modification time is checked (in seconds).
 - 
lastModifiedprotected long lastModified The file modification time (in milliseconds) for the cached template.
 - 
nextCheckprotected long nextCheck The next time the file modification time will be checked (in milliseconds).
 - 
nameprotected String name Name of the resource
 - 
encodingprotected String encoding Character encoding of this resource
 - 
dataprotected Object data Resource might require ancillary storage of some kind
 - 
typeprotected int type Resource type (RESOURCE_TEMPLATE or RESOURCE_CONTENT)
 
- 
 - 
Method Detail- 
setRuntimeServicespublic void setRuntimeServices(RuntimeServices rs) - Parameters:
- rs-
 
 - 
processpublic abstract boolean process() throws ResourceNotFoundException, ParseErrorExceptionPerform 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 TemplateorContentResource, this indicates whether the resource could be read.
- Throws:
- ResourceNotFoundException- Similar in semantics as returning- false.
- ParseErrorException
 
 - 
isSourceModifiedpublic boolean isSourceModified() - Returns:
- True if source has been modified.
 
 - 
setModificationCheckIntervalpublic void setModificationCheckInterval(long modificationCheckInterval) Set the modification check interval.- Parameters:
- modificationCheckInterval- The interval (in seconds).
 
 - 
requiresCheckingpublic boolean requiresChecking() Is it time to check to see if the resource source has been updated?- Returns:
- True if resource must be checked.
 
 - 
touchpublic void touch() 'Touch' this template and thereby resetting the nextCheck field.
 - 
setNamepublic void setName(String name) Set the name of this resource, for example test.vm.- Parameters:
- name-
 
 - 
getNamepublic String getName() Get the name of this template.- Returns:
- The name of this template.
 
 - 
setEncodingpublic void setEncoding(String encoding) set the encoding of this resource for example, "ISO-8859-1"- Parameters:
- encoding-
 
 - 
getEncodingpublic String getEncoding() get the encoding of this resource for example, "ISO-8859-1"- Returns:
- The encoding of this resource.
 
 - 
getLastModifiedpublic long getLastModified() Return the lastModifed time of this resource.- Returns:
- The lastModifed time of this resource.
 
 - 
setLastModifiedpublic void setLastModified(long lastModified) Set the last modified time for this resource.- Parameters:
- lastModified-
 
 - 
getResourceLoaderpublic ResourceLoader getResourceLoader() Return the template loader that pulled in the template stream- Returns:
- The resource loader for this resource.
 
 - 
setResourceLoaderpublic 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-
 
 - 
setDatapublic void setData(Object data) Set arbitrary data object that might be used by the resource.- Parameters:
- data-
 
 - 
getDatapublic Object getData() Get arbitrary data object that might be used by the resource.- Returns:
- The data object for this resource.
 
 - 
setTypepublic 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
 
 - 
getTypepublic int getType() - Returns:
- type code of the Resource
- Since:
- 1.6
 
 - 
deepCloneDataprotected void deepCloneData() throws CloneNotSupportedExceptionDeep cloning of resource data- Throws:
- CloneNotSupportedException
 
 
- 
 
-