Class ResourceScriptSource
- java.lang.Object
- org.springframework.scripting.support.ResourceScriptSource
- All Implemented Interfaces:
ScriptSource
public class ResourceScriptSource extends Object implements ScriptSource
ScriptSourceimplementation based on Spring'sResourceabstraction. Loads the script text from the underlying Resource'sFileorInputStream, and tracks the last-modified timestamp of the file (if possible).- Since:
- 2.0
- Author:
- Rob Harrop, Juergen Hoeller
- See Also:
InputStreamSource.getInputStream(),Resource.getFile(),ResourceLoader
Constructor Summary
Constructors Constructor Description ResourceScriptSource(Resource resource)Create a new ResourceScriptSource for the given resource.ResourceScriptSource(EncodedResource resource)Create a new ResourceScriptSource for the given resource.
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ResourcegetResource()Return theResourceto load the script from.StringgetScriptAsString()Retrieve the current script source text as String.booleanisModified()Indicate whether the underlying script data has been modified since the last timeScriptSource.getScriptAsString()was called.protected longretrieveLastModifiedTime()Retrieve the current last-modified timestamp of the underlying resource.voidsetEncoding(String encoding)Set the encoding used for reading the script resource.StringsuggestedClassName()Determine a class name for the underlying script.StringtoString()
Constructor Detail
ResourceScriptSource
public ResourceScriptSource(EncodedResource resource)
Create a new ResourceScriptSource for the given resource.- Parameters:
resource- the EncodedResource to load the script from
ResourceScriptSource
public ResourceScriptSource(Resource resource)
Create a new ResourceScriptSource for the given resource.- Parameters:
resource- the Resource to load the script from (using UTF-8 encoding)
Method Detail
getResource
public final Resource getResource()
Return theResourceto load the script from.
setEncoding
public void setEncoding(String encoding)
Set the encoding used for reading the script resource.The default value for regular Resources is "UTF-8". A
nullvalue implies the platform default.
getScriptAsString
public String getScriptAsString() throws IOException
Description copied from interface:ScriptSourceRetrieve the current script source text as String.- Specified by:
getScriptAsStringin interfaceScriptSource- Returns:
- the script text
- Throws:
IOException- if script retrieval failed
isModified
public boolean isModified()
Description copied from interface:ScriptSourceIndicate whether the underlying script data has been modified since the last timeScriptSource.getScriptAsString()was called. Returnstrueif the script has not been read yet.- Specified by:
isModifiedin interfaceScriptSource- Returns:
- whether the script data has been modified
retrieveLastModifiedTime
protected long retrieveLastModifiedTime()
Retrieve the current last-modified timestamp of the underlying resource.- Returns:
- the current timestamp, or 0 if not determinable
suggestedClassName
public String suggestedClassName()
Description copied from interface:ScriptSourceDetermine a class name for the underlying script.- Specified by:
suggestedClassNamein interfaceScriptSource- Returns:
- the suggested class name, or
nullif none available