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 parameterscopeshould be one of bindings, page, request, session (page being theEmulatedPageContext), and there can be akeyandvalueparameter 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 classAttributeHelper.Scope
-
Field Summary
Fields Modifier and Type Field Description protected Bindingsbindingsprotected static PatternKEYPATTERNstatic StringPARAM_SCOPEParameter 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 BindingsgetBindings()Provides a HTL readable view of the Bindings.Map<String,Object>getPageContext()TheEmulatedPageContextfor the script.protected org.apache.sling.api.SlingHttpServletRequestgetRequest()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.voidinit(org.apache.sling.scripting.sightly.render.RenderContext renderContext, Bindings arguments)Called to initialize the Java object with the current Java Scripting API arguments.protected voidsetAttribute(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:UseWithRenderContextCalled 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-useattribute. The Java Scripting API arguments provide all the global variables known to a script being executed.- Specified by:
initin 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()
TheEmulatedPageContextfor 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.
-
-