Package com.composum.platform.htl
Class AttributeHelper
- java.lang.Object
-
- com.composum.platform.htl.AttributeHelper
-
- All Implemented Interfaces:
UseWithRenderContext
public class AttributeHelper extends Object implements UseWithRenderContext
Allows setting and reading request-/session-attributes, script bindings or a simulated pageContext (EmulatedPageContext
). If there should be something written, the parameterscope
should be one of bindings, page, request, session (page being theEmulatedPageContext
), and there can be akey
andvalue
parameter to set one value, or an arbitrary number key1, key2, key3 ... and corresponding value1, value2, value3, ... parameters to set the values in that scope.- Since:
- 09/2017
- Author:
- Hans-Peter Stoerr
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
AttributeHelper.Scope
-
Field Summary
Fields Modifier and Type Field Description protected Bindings
bindings
protected static Pattern
KEYPATTERN
static String
PARAM_SCOPE
Parameter that determines the scope: lower case string representation ofAttributeHelper.Scope
.
-
Constructor Summary
Constructors Constructor Description AttributeHelper()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Bindings
getBindings()
Provides a HTL readable view of the Bindings.Map<String,Object>
getPageContext()
TheEmulatedPageContext
for the script.protected org.apache.sling.api.SlingHttpServletRequest
getRequest()
org.apache.sling.scripting.sightly.Record<Object>
getRequestAttributes()
Provides a HTL readable view of the request attributes.Map<String,String[]>
getRequestParameters()
The map of request parameters.org.apache.sling.scripting.sightly.Record<Object>
getSessionAttributes()
Provides a HTL readable view of the session Attributes.void
init(org.apache.sling.scripting.sightly.render.RenderContext renderContext, Bindings arguments)
Called to initialize the Java object with the current Java Scripting API arguments.protected void
setAttribute(AttributeHelper.Scope scope, Object rawKey, Object value)
-
-
-
Field Detail
-
PARAM_SCOPE
public static final String PARAM_SCOPE
Parameter that determines the scope: lower case string representation ofAttributeHelper.Scope
.- See Also:
- Constant Field Values
-
bindings
protected Bindings bindings
-
KEYPATTERN
protected static final Pattern KEYPATTERN
-
-
Method Detail
-
init
public void init(org.apache.sling.scripting.sightly.render.RenderContext renderContext, Bindings arguments)
Description copied from interface:UseWithRenderContext
Called to initialize the Java object with the current Java Scripting API arguments.
This method is called only if the object has been instantiated by HTL as part of processing the
data-sly-use
attribute. The Java Scripting API arguments provide all the global variables known to a script being executed.- Specified by:
init
in interfaceUseWithRenderContext
- Parameters:
renderContext
- the context where this is called. Caution: modifyingRenderContext.getBindings()
will change the global bindings.arguments
- The Java Scripting API arguments. Caution: modifying this could interfere with other providers.
-
setAttribute
protected void setAttribute(AttributeHelper.Scope scope, Object rawKey, Object value)
-
getRequest
protected org.apache.sling.api.SlingHttpServletRequest getRequest()
-
getPageContext
public Map<String,Object> getPageContext()
TheEmulatedPageContext
for the script.
-
getRequestParameters
public Map<String,String[]> getRequestParameters()
The map of request parameters. Caution: the values are arrays.
-
getRequestAttributes
public org.apache.sling.scripting.sightly.Record<Object> getRequestAttributes()
Provides a HTL readable view of the request attributes.
-
getSessionAttributes
public org.apache.sling.scripting.sightly.Record<Object> getSessionAttributes()
Provides a HTL readable view of the session Attributes.
-
getBindings
public Bindings getBindings()
Provides a HTL readable view of the Bindings.
-
-