public class SlingBindings extends HashMap<String,Object>
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.AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
Modifier and Type | Field and Description |
---|---|
static String |
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").
|
static String |
LOG
The name of the global scripting variable providing a logger which may be
used for logging purposes (value is "log").
|
static String |
OUT
The name of the global scripting variable providing the
java.io.PrintWriter object to return the response content
(value is "out"). |
static String |
READER
The name of the global scripting variable providing the
Reader object (value is "reader"). |
static String |
REQUEST
The name of the global scripting variable providing the
SlingHttpServletRequest object (value is
"request"). |
static String |
RESOLVER
The name of the global scripting variable providing the
ResourceResolver object (value is
"resolver"). |
static String |
RESOURCE
The name of the global scripting variable providing the
Resource object (value is
"resource"). |
static String |
RESPONSE
The name of the global scripting variable providing the
SlingHttpServletResponse object (value is
"response"). |
static String |
SLING
The name of the global scripting variable providing the
SlingScriptHelper for the request
(value is "sling"). |
Constructor and Description |
---|
SlingBindings() |
Modifier and Type | Method and Description |
---|---|
protected <ObjectType> |
get(String key,
Class<ObjectType> type)
Helper method to get an object with a given type from this map.
|
boolean |
getFlush()
|
org.slf4j.Logger |
getLog()
|
PrintWriter |
getOut()
|
Reader |
getReader()
|
SlingHttpServletRequest |
getRequest()
|
Resource |
getResource()
|
ResourceResolver |
getResourceResolver()
|
SlingHttpServletResponse |
getResponse()
|
SlingScriptHelper |
getSling()
|
protected void |
safePut(String key,
Object value)
Helper method which invokes
HashMap.put(Object, Object) only if the value is not null. |
void |
setFlush(boolean flush)
Sets the
FLUSH property to flush . |
void |
setLog(org.slf4j.Logger log)
|
void |
setOut(PrintWriter out)
|
void |
setReader(Reader reader)
|
void |
setRequest(SlingHttpServletRequest request)
|
void |
setResource(Resource resource)
|
void |
setResourceResolver(ResourceResolver resourceResolver)
|
void |
setResponse(SlingHttpServletResponse response)
|
void |
setSling(SlingScriptHelper sling)
|
clear, clone, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, forEach, get, getOrDefault, isEmpty, keySet, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, values
equals, hashCode, toString
public static final String REQUEST
SlingHttpServletRequest
object (value is
"request"). The value of the scripting variable is the same as that
returned by the
SlingScriptHelper.getRequest()
method.
This bound variable is required in the bindings given the script.
public static final String RESPONSE
SlingHttpServletResponse
object (value is
"response"). The value of the scripting variable is the same as that
returned by the
SlingScriptHelper.getResponse()
method.
This bound variable is required in the bindings given the script.
public static final String READER
Reader
object (value is "reader").
This bound variable is required in the bindings given the script.
public static final String SLING
SlingScriptHelper
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
and RESPONSE
variables. If this variable is not
bound, the script implementation will create it before actually
evaluating the script.
public static final String RESOURCE
Resource
object (value is
"resource"). The value of the scripting variable is the same as that
returned by the SlingScriptHelper.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.
public static final String 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 the SlingScriptHelper.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.
public static final String OUT
java.io.PrintWriter
object to return the response content
(value is "out"). The value of the scripting variable is the same as that
returned by the SlingScriptHelper.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 the RESPONSE
variable. If this variable
is not bound, the script implementation will bind it before actually
evaluating the script.
public static final String FLUSH
The type of this variable is java.lang.Boolean
indicating
whether to flush the output (value is TRUE
) or not (value
is FALSE
). If the variable has a non-null
value of another type, the output is not flush as if the value would be
FALSE
.
public static final String LOG
org.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.
protected <ObjectType> ObjectType get(String key, Class<ObjectType> type)
ObjectType
- The object typekey
- The key for the objecttype
- The object typenull
is returned.protected void safePut(String key, Object value)
HashMap.put(Object, Object)
only if the value is not null.key
- The key of the objectvalue
- The valuepublic void setFlush(boolean flush)
FLUSH
property to flush
.flush
- Whether to flush or notpublic boolean getFlush()
true
if flushpublic void setLog(org.slf4j.Logger log)
log
- The logger@CheckForNull public org.slf4j.Logger getLog()
null
public void setOut(PrintWriter out)
out
- The print writer@CheckForNull public PrintWriter getOut()
null
public void setRequest(SlingHttpServletRequest request)
request
- The request object.@CheckForNull public SlingHttpServletRequest getRequest()
REQUEST
property if not null
and a
SlingHttpServletRequest
instance. Otherwise
null
is returned.null
public void setReader(Reader reader)
reader
- The reader@CheckForNull public Reader getReader()
null
.public void setResource(Resource resource)
resource
- The resource@CheckForNull public Resource getResource()
null
.public void setResourceResolver(ResourceResolver resourceResolver)
resourceResolver
- the Resource Resolver@CheckForNull public ResourceResolver getResourceResolver()
RESOLVER
property if not null
and a
ResourceResolver
instance. Otherwise null
is
returned.ResourceResolver
if one exists, null
otherwisepublic void setResponse(SlingHttpServletResponse response)
response
- The response@CheckForNull public SlingHttpServletResponse getResponse()
RESPONSE
property if not null
and a
SlingHttpServletResponse
instance. Otherwise
null
is returned.null
.public void setSling(SlingScriptHelper sling)
sling
- The script helper@CheckForNull public SlingScriptHelper getSling()
SLING
property if not null
and a
SlingScriptHelper
instance. Otherwise null
is returned.null
.Copyright © 2017 The Apache Software Foundation. All rights reserved.