public class ResourceScriptSource extends java.lang.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. |
java.lang.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(java.lang.String encoding)
Set the encoding used for reading the script resource.
|
java.lang.String |
suggestedClassName()
Determine a class name for the underlying script.
|
java.lang.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(@Nullable java.lang.String encoding)
The default value for regular Resources is "UTF-8".
A null
value implies the platform default.
public java.lang.String getScriptAsString() throws java.io.IOException
ScriptSource
getScriptAsString
in interface ScriptSource
java.io.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()
@Nullable public java.lang.String suggestedClassName()
ScriptSource
suggestedClassName
in interface ScriptSource
null
if none availablepublic java.lang.String toString()
toString
in class java.lang.Object