public class ResourceScriptSource extends Object implements ScriptSource
ScriptSource
implementation
based on Spring's Resource
abstraction. Loads the script text from the underlying Resource's
File
or
InputStream
,
and tracks the last-modified timestamp of the file (if possible).InputStreamSource.getInputStream()
,
Resource.getFile()
,
ResourceLoader
Modifier and Type | Field and Description |
---|---|
protected Log |
logger
Logger available to subclasses
|
Constructor and Description |
---|
ResourceScriptSource(Resource resource)
Create a new ResourceScriptSource for the given resource.
|
Modifier and Type | Method and Description |
---|---|
Resource |
getResource()
Return the
Resource to load the
script from. |
String |
getScriptAsString()
Retrieve the current script source text as String.
|
boolean |
isModified()
Indicate whether the underlying script data has been modified since
the last time
ScriptSource.getScriptAsString() was called. |
protected long |
retrieveLastModifiedTime()
Retrieve the current last-modified timestamp of the underlying resource.
|
void |
setEncoding(String encoding)
Sets the encoding used for reading the script resource.
|
String |
suggestedClassName()
Determine a class name for the underlying script.
|
String |
toString() |
protected final Log logger
public ResourceScriptSource(Resource resource)
resource
- the Resource to load the script frompublic String getScriptAsString() throws IOException
ScriptSource
getScriptAsString
in interface ScriptSource
IOException
- if script retrieval failedpublic boolean isModified()
ScriptSource
ScriptSource.getScriptAsString()
was called.
Returns true
if the script has not been read yet.isModified
in interface ScriptSource
protected long retrieveLastModifiedTime()
public String suggestedClassName()
ScriptSource
suggestedClassName
in interface ScriptSource
null
if none availablepublic void setEncoding(String encoding)
encoding
- charset encoding used for reading the script.