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(EncodedResource resource)
Create a new ResourceScriptSource for the given resource.
|
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)
Set 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(EncodedResource resource)
resource
- the EncodedResource to load the script frompublic ResourceScriptSource(Resource resource)
resource
- the Resource to load the script from (using UTF-8 encoding)public void setEncoding(String encoding)
The default value for regular Resources is "UTF-8".
A null
value implies the platform default.
public 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 available