Class SlingBindings
SlingBindings
class is used to prepare global variables
for script execution. The constants in this class define names of variables
which MUST or MAY be provided for the script execution.
Other variables may be define as callers see fit.- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.sling.api.scripting.LazyBindings
LazyBindings.Supplier
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K extends Object,
V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object, V extends Object> -
Field Summary
Modifier and TypeFieldDescriptionstatic final String
The name of the global scripting variable indicating whether the output used by the script should be flushed after the script evaluation ended normally (value is "flush").static final String
The name of the global scripting variable providing a logger which may be used for logging purposes (value is "log").static final String
The name of the global scripting variable providing thejava.io.PrintWriter
object to return the response content (value is "out").static final String
The name of the global scripting variable providing theReader
object (value is "reader").static final String
The name of the global scripting variable providing theSlingHttpServletRequest
object (value is "request").static final String
The name of the global scripting variable providing theResourceResolver
object (value is "resolver").static final String
The name of the global scripting variable providing theResource
object (value is "resource").static final String
The name of the global scripting variable providing theSlingHttpServletResponse
object (value is "response").static final String
The name of the global scripting variable providing theSlingScriptHelper
for the request (value is "sling"). -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected <ObjectType>
ObjectTypeHelper method to get an object with a given type from this map.boolean
getFlush()
@Nullable org.slf4j.Logger
getLog()
@Nullable PrintWriter
getOut()
@Nullable Reader
@Nullable SlingHttpServletRequest
@Nullable Resource
@Nullable ResourceResolver
@Nullable SlingHttpServletResponse
@Nullable SlingScriptHelper
getSling()
protected void
Helper method which invokesHashMap.put(Object, Object)
only if the value is not null.void
setFlush
(boolean flush) Sets theFLUSH
property toflush
.void
setLog
(org.slf4j.Logger log) void
setOut
(PrintWriter out) void
void
setRequest
(SlingHttpServletRequest request) void
setResource
(Resource resource) void
setResourceResolver
(ResourceResolver resourceResolver) void
setResponse
(SlingHttpServletResponse response) void
setSling
(SlingScriptHelper sling) Methods inherited from class org.apache.sling.api.scripting.LazyBindings
clear, containsKey, entrySet, equals, get, getOrDefault, hashCode, isEmpty, keySet, put, putAll, remove, size, values
Methods inherited from class java.util.HashMap
clone, compute, computeIfAbsent, computeIfPresent, containsValue, forEach, merge, putIfAbsent, remove, replace, replace, replaceAll
Methods inherited from class java.util.AbstractMap
toString
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, containsValue, forEach, merge, putIfAbsent, remove, replace, replace, replaceAll
-
Field Details
-
REQUEST
The name of the global scripting variable providing theSlingHttpServletRequest
object (value is "request"). The value of the scripting variable is the same as that returned by theSlingScriptHelper.getRequest()
method.This bound variable is required in the bindings given the script.
- See Also:
-
RESPONSE
The name of the global scripting variable providing theSlingHttpServletResponse
object (value is "response"). The value of the scripting variable is the same as that returned by theSlingScriptHelper.getResponse()
method.This bound variable is required in the bindings given the script.
- See Also:
-
READER
The name of the global scripting variable providing theReader
object (value is "reader").This bound variable is required in the bindings given the script.
- See Also:
-
SLING
The name of the global scripting variable providing theSlingScriptHelper
for the request (value is "sling").This bound variable is optional. If existing, the script helper instance must be bound to the same request and response objects as bound with the
REQUEST
andRESPONSE
variables. If this variable is not bound, the script implementation will create it before actually evaluating the script.- See Also:
-
RESOURCE
The name of the global scripting variable providing theResource
object (value is "resource"). The value of the scripting variable is the same as that returned by theSlingScriptHelper.getRequest().getResource()
method.This bound variable is optional. If existing, the resource must be bound to the same resource as returned by the
SlingHttpServletRequest.getResource()
method. If this variable is not bound, the script implementation will bind it before actually evaluating the script.- See Also:
-
RESOLVER
The name of the global scripting variable providing the
ResourceResolver
object (value is "resolver"). The value of the scripting variable is the same as that returned by theSlingScriptHelper.getRequest().getResourceResolver()
method.This bound variable is optional. If existing, the resource resolver must be bound to the same resolver as returned by the
SlingHttpServletRequest.getResource().getResourceResolver
method. If this variable is not bound, the script implementation will bind it before actually evaluating the script.- See Also:
-
OUT
The name of the global scripting variable providing thejava.io.PrintWriter
object to return the response content (value is "out"). The value of the scripting variable is the same as that returned by theSlingScriptHelper.getResponse().getWriter()
method.Note, that it may be advisable to implement a lazy acquiring writer for the out variable to enable the script to write binary data to the response output stream instead of the writer.
This bound variable is optional. If existing, the resource must be bound to the same writer as returned by the
SlingHttpServletResponse.getWriter()
method of the response object bound to theRESPONSE
variable. If this variable is not bound, the script implementation will bind it before actually evaluating the script.- See Also:
-
FLUSH
The name of the global scripting variable indicating whether the output used by the script should be flushed after the script evaluation ended normally (value is "flush").The type of this variable is
java.lang.Boolean
indicating whether to flush the output (value isTRUE
) or not (value isFALSE
). If the variable has a non-null
value of another type, the output is not flush as if the value would beFALSE
.- See Also:
-
LOG
The name of the global scripting variable providing a logger which may be used for logging purposes (value is "log"). The logger provides the API defined by the SLF4Jorg.slf4j.Logger
interface.This bound variable is optional. If this variable is not bound, the script implementation will bind it before actually evaluating the script.
- See Also:
-
-
Constructor Details
-
SlingBindings
public SlingBindings()
-
-
Method Details
-
get
Helper method to get an object with a given type from this map.- Type Parameters:
ObjectType
- The object type- Parameters:
key
- The key for the objecttype
- The object type- Returns:
- The searched object if it has the specified type, otherwise
null
is returned.
-
safePut
Helper method which invokesHashMap.put(Object, Object)
only if the value is not null.- Parameters:
key
- The key of the objectvalue
- The value
-
setFlush
public void setFlush(boolean flush) Sets theFLUSH
property toflush
.- Parameters:
flush
- Whether to flush or not
-
getFlush
public boolean getFlush()- Returns:
true
if flush
-
setLog
public void setLog(org.slf4j.Logger log) - Parameters:
log
- The logger
-
getLog
@Nullable public @Nullable org.slf4j.Logger getLog()- Returns:
- The logger or
null
-
setOut
- Parameters:
out
- The print writer
-
getOut
- Returns:
- The print writer or
null
-
setRequest
- Parameters:
request
- The request object.
-
getRequest
Returns theREQUEST
property if notnull
and aSlingHttpServletRequest
instance. Otherwisenull
is returned.- Returns:
- The request object or
null
-
setReader
- Parameters:
reader
- The reader
-
getReader
- Returns:
- The reader or
null
.
-
setResource
- Parameters:
resource
- The resource
-
getResource
- Returns:
- The resource or
null
.
-
setResourceResolver
- Parameters:
resourceResolver
- the Resource Resolver
-
getResourceResolver
Returns theRESOLVER
property if notnull
and aResourceResolver
instance. Otherwisenull
is returned.- Returns:
- the bound
ResourceResolver
if one exists,null
otherwise
-
setResponse
- Parameters:
response
- The response
-
getResponse
Returns theRESPONSE
property if notnull
and aSlingHttpServletResponse
instance. Otherwisenull
is returned.- Returns:
- The response or
null
.
-
setSling
- Parameters:
sling
- The script helper
-
getSling
Returns theSLING
property if notnull
and aSlingScriptHelper
instance. Otherwisenull
is returned.- Returns:
- The script helper or
null
.
-