org.apache.sling.api.scripting
Class SlingBindings

java.lang.Object
  extended by java.util.AbstractMap<K,V>
      extended by java.util.HashMap<java.lang.String,java.lang.Object>
          extended by org.apache.sling.api.scripting.SlingBindings
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.util.Map<java.lang.String,java.lang.Object>

public class SlingBindings
extends java.util.HashMap<java.lang.String,java.lang.Object>

The 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:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.util.AbstractMap
java.util.AbstractMap.SimpleEntry<K,V>, java.util.AbstractMap.SimpleImmutableEntry<K,V>
 
Field Summary
static java.lang.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 java.lang.String LOG
          The name of the global scripting variable providing a logger which may be used for logging purposes (value is "log").
static java.lang.String OUT
          The name of the global scripting variable providing the java.io.PrintWriter object to return the response content (value is "out").
static java.lang.String READER
          The name of the global scripting variable providing the Reader object (value is "reader").
static java.lang.String REQUEST
          The name of the global scripting variable providing the SlingHttpServletRequest object (value is "request").
static java.lang.String RESOURCE
          The name of the global scripting variable providing the Resource object (value is "resource").
static java.lang.String RESPONSE
          The name of the global scripting variable providing the SlingHttpServletResponse object (value is "response").
static java.lang.String SLING
          The name of the global scripting variable providing the SlingScriptHelper for the request (value is "sling").
 
Constructor Summary
SlingBindings()
           
 
Method Summary
protected
<ObjectType>
ObjectType
get(java.lang.String key, java.lang.Class<ObjectType> type)
          Helper method to get an object with a given type from this map.
 boolean getFlush()
          Returns the FLUSH property if not null and a boolean.
 org.slf4j.Logger getLog()
          Returns the LOG property if not null and a org.slf4j.Logger instance.
 java.io.PrintWriter getOut()
          Returns the OUT property if not null and a PrintWriter instance.
 java.io.Reader getReader()
          Returns the READER property if not null and a Reader instance.
 SlingHttpServletRequest getRequest()
          Returns the REQUEST property if not null and a SlingHttpServletRequest instance.
 Resource getResource()
          Returns the RESOURCE property if not null and a Resource instance.
 SlingHttpServletResponse getResponse()
          Returns the RESPONSE property if not null and a SlingHttpServletResponse instance.
 SlingScriptHelper getSling()
          Returns the SLING property if not null and a SlingScriptHelper instance.
protected  void safePut(java.lang.String key, java.lang.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)
          Sets the LOG property to log if not null.
 void setOut(java.io.PrintWriter out)
          Sets the OUT property to out if not null.
 void setReader(java.io.Reader reader)
          Sets the READER property to reader if not null.
 void setRequest(SlingHttpServletRequest request)
          Sets the REQUEST property to request if not null.
 void setResource(Resource resource)
          Sets the RESOURCE property to resource if not null.
 void setResponse(SlingHttpServletResponse response)
          Sets the RESPONSE property to response if not null.
 void setSling(SlingScriptHelper sling)
          Sets the SLING property to sling if not null.
 
Methods inherited from class java.util.HashMap
clear, clone, containsKey, containsValue, entrySet, get, isEmpty, keySet, put, putAll, remove, size, values
 
Methods inherited from class java.util.AbstractMap
equals, hashCode, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Field Detail

REQUEST

public static final java.lang.String REQUEST
The name of the global scripting variable providing the 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.

See Also:
Constant Field Values

RESPONSE

public static final java.lang.String RESPONSE
The name of the global scripting variable providing the 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.

See Also:
Constant Field Values

READER

public static final java.lang.String READER
The name of the global scripting variable providing the Reader object (value is "reader").

This bound variable is required in the bindings given the script.

See Also:
Constant Field Values

SLING

public static final java.lang.String SLING
The name of the global scripting variable providing the 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.

See Also:
Constant Field Values

RESOURCE

public static final java.lang.String RESOURCE
The name of the global scripting variable providing the 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.

See Also:
Constant Field Values

OUT

public static final java.lang.String OUT
The name of the global scripting variable providing the 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.

See Also:
Constant Field Values

FLUSH

public static final java.lang.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").

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.

See Also:
Constant Field Values

LOG

public static final java.lang.String 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 SLF4J 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.

See Also:
Constant Field Values
Constructor Detail

SlingBindings

public SlingBindings()
Method Detail

get

protected <ObjectType> ObjectType get(java.lang.String key,
                                      java.lang.Class<ObjectType> type)
Helper method to get an object with a given type from this map.

Returns:
The searched object if it has the specified type, otherwise null is returned.

safePut

protected void safePut(java.lang.String key,
                       java.lang.Object value)
Helper method which invokes HashMap.put(Object, Object) only if the value is not null.


setFlush

public void setFlush(boolean flush)
Sets the FLUSH property to flush.


getFlush

public boolean getFlush()
Returns the FLUSH property if not null and a boolean. Otherwise false is returned.


setLog

public void setLog(org.slf4j.Logger log)
Sets the LOG property to log if not null.


getLog

public org.slf4j.Logger getLog()
Returns the LOG property if not null and a org.slf4j.Logger instance. Otherwise null is returned.


setOut

public void setOut(java.io.PrintWriter out)
Sets the OUT property to out if not null.


getOut

public java.io.PrintWriter getOut()
Returns the OUT property if not null and a PrintWriter instance. Otherwise null is returned.


setRequest

public void setRequest(SlingHttpServletRequest request)
Sets the REQUEST property to request if not null.


getRequest

public SlingHttpServletRequest getRequest()
Returns the REQUEST property if not null and a SlingHttpServletRequest instance. Otherwise null is returned.


setReader

public void setReader(java.io.Reader reader)
Sets the READER property to reader if not null.


getReader

public java.io.Reader getReader()
Returns the READER property if not null and a Reader instance. Otherwise null is returned.


setResource

public void setResource(Resource resource)
Sets the RESOURCE property to resource if not null.


getResource

public Resource getResource()
Returns the RESOURCE property if not null and a Resource instance. Otherwise null is returned.


setResponse

public void setResponse(SlingHttpServletResponse response)
Sets the RESPONSE property to response if not null.


getResponse

public SlingHttpServletResponse getResponse()
Returns the RESPONSE property if not null and a SlingHttpServletResponse instance. Otherwise null is returned.


setSling

public void setSling(SlingScriptHelper sling)
Sets the SLING property to sling if not null.


getSling

public SlingScriptHelper getSling()
Returns the SLING property if not null and a SlingScriptHelper instance. Otherwise null is returned.



Copyright © 2007-2009. All Rights Reserved.