Top Description Fields Constructors Methods
org.springframework.scripting.support

public Class ResourceScriptSource

extends Object
implements ScriptSource
Class Inheritance
All Implemented Interfaces
org.springframework.scripting.ScriptSource
Imports
java.io.IOException, .Reader, java.nio.charset.StandardCharsets, org.apache.commons.logging.Log, .LogFactory, org.springframework.core.io.Resource, org.springframework.core.io.support.EncodedResource, org.springframework.lang.Nullable, org.springframework.scripting.ScriptSource, org.springframework.util.Assert, .FileCopyUtils, .StringUtils

org.springframework.scripting.ScriptSource implementation based on Spring's org.springframework.core.io.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).
Authors
Rob Harrop, Juergen Hoeller
Since
2.0
See Also
org.springframework.core.io.Resource#getInputStream(), org.springframework.core.io.Resource#getFile(), org.springframework.core.io.ResourceLoader

Field Summary

Modifier and TypeField and Description
private long
private final Object
protected final Log
logger

Logger available to subclasses.

private EncodedResource

Constructor Summary

AccessConstructor and Description
public
ResourceScriptSource(EncodedResource
the EncodedResource to load the script from
resource
)

Create a new ResourceScriptSource for the given resource.

public
ResourceScriptSource(Resource
the Resource to load the script from (using UTF-8 encoding)
resource
)

Create a new ResourceScriptSource for the given resource.

Method Summary

Modifier and TypeMethod and Description
public final Resource
getResource()

Return the org.springframework.core.io.Resource to load the script from.

public String
getScriptAsString()

Implements org.springframework.scripting.ScriptSource.getScriptAsString.

Retrieve the current script source text as String.

public boolean
isModified()

Implements org.springframework.scripting.ScriptSource.isModified.

Indicate whether the underlying script data has been modified since the last time getScriptAsString() was called.

protected long

Returns:

the current timestamp, or 0 if not determinable
retrieveLastModifiedTime
()

Retrieve the current last-modified timestamp of the underlying resource.

public void
setEncoding(String encoding)

Set the encoding used for reading the script resource.

public String
suggestedClassName()

Implements org.springframework.scripting.ScriptSource.suggestedClassName.

Determine a class name for the underlying script.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

lastModifiedback to summary
private long lastModified
lastModifiedMonitorback to summary
private final Object lastModifiedMonitor
loggerback to summary
protected final Log logger

Logger available to subclasses.

resourceback to summary
private EncodedResource resource

Constructor Detail

ResourceScriptSourceback to summary
public ResourceScriptSource(EncodedResource resource)

Create a new ResourceScriptSource for the given resource.

Parameters
resource:EncodedResource

the EncodedResource to load the script from

ResourceScriptSourceback to summary
public ResourceScriptSource(Resource resource)

Create a new ResourceScriptSource for the given resource.

Parameters
resource:Resource

the Resource to load the script from (using UTF-8 encoding)

Method Detail

getResourceback to summary
public final Resource getResource()

Return the org.springframework.core.io.Resource to load the script from.

getScriptAsStringback to summary
public String getScriptAsString() throws IOException

Implements org.springframework.scripting.ScriptSource.getScriptAsString.

Doc from org.springframework.scripting.ScriptSource.getScriptAsString.

Retrieve the current script source text as String.

Returns:String

the script text

Annotations
@Override
Exceptions
IOException:
if script retrieval failed
isModifiedback to summary
public boolean isModified()

Implements org.springframework.scripting.ScriptSource.isModified.

Doc from org.springframework.scripting.ScriptSource.isModified.

Indicate whether the underlying script data has been modified since the last time getScriptAsString() was called. Returns true if the script has not been read yet.

Returns:boolean

whether the script data has been modified

Annotations
@Override
retrieveLastModifiedTimeback to summary
protected long retrieveLastModifiedTime()

Retrieve the current last-modified timestamp of the underlying resource.

Returns:long

the current timestamp, or 0 if not determinable

setEncodingback to summary
public void setEncoding(String encoding)

Set the encoding used for reading the script resource.

The default value for regular Resources is "UTF-8". A null value implies the platform default.

suggestedClassNameback to summary
public String suggestedClassName()

Implements org.springframework.scripting.ScriptSource.suggestedClassName.

Doc from org.springframework.scripting.ScriptSource.suggestedClassName.

Determine a class name for the underlying script.

Returns:String

the suggested class name, or null if none available

Annotations
@Override
@Nullable
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override