Package com.composum.platform.htl.impl
Class AttributesUseProvider
- java.lang.Object
-
- com.composum.platform.htl.impl.AttributesUseProvider
-
- All Implemented Interfaces:
org.apache.sling.scripting.sightly.use.UseProvider
public class AttributesUseProvider extends Object implements org.apache.sling.scripting.sightly.use.UseProvider
Allows reading request- or session-attributes or theEmulatedPageContext
with a data-sly-use statement such that the IDE knows the specific class and can provide code completion etc. Since the retrieved value can be a model, the priority of this needs to be higher than the models use providers. This use provider is activated whenever the "fromScope" parameter is present. Possible scopes are defined inAttributesUseProvider.Scope
. Usage example:<sly data-sly-use.searchresult="${'com.composum.pages.commons.service.search.SearchService.Result' @ fromScope='request', key='searchresult'}"/>
If the parameter "key" is not present, the identifier is used as key. This might make sense if you don't want to specify the Java class of the value, which is more concise but gives your IDE less power to check:<sly data-sly-use.searchresult="${'searchresult' @ fromScope='request'}"/>
This can also be used to give the IDE a clue on the type of some binding. If there is a bindingsearchresult
and you want your IDE to know about it's type to easily access it's attributes:<sly data-sly-use.searchresult="${'com.composum.pages.commons.service.search.SearchService.Result' @ fromScope='bindings', * key='searchresult'}"/>
- Since:
- 09/2017
- Author:
- Hans-Peter Stoerr
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
AttributesUseProvider.Scope
-
Field Summary
Fields Modifier and Type Field Description static String
PARAM_KEY
If the identifier is a class name, this is the name of the attribute name to read from - otherwise the identifier is taken.static String
PARAM_SCOPE
Mandatory parameter that determines the scope to read from: lower case string representation ofAttributesUseProvider.Scope
.static String
PARAM_VALUE
Explicitly given value; mandatory for scope ScopeAttributesUseProvider.Scope.VALUE
.
-
Constructor Summary
Constructors Constructor Description AttributesUseProvider()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
checkType(Object value, String identifier, String scriptName)
protected Object
getAttribute(org.apache.sling.scripting.sightly.render.RenderContext renderContext, AttributesUseProvider.Scope scope, String key, Object rawValue)
protected org.apache.sling.api.SlingHttpServletRequest
getRequest(org.apache.sling.scripting.sightly.render.RenderContext renderContext)
org.apache.sling.scripting.sightly.use.ProviderOutcome
provide(String identifier, org.apache.sling.scripting.sightly.render.RenderContext renderContext, Bindings arguments)
-
-
-
Field Detail
-
PARAM_SCOPE
public static final String PARAM_SCOPE
Mandatory parameter that determines the scope to read from: lower case string representation ofAttributesUseProvider.Scope
. If this parameter isn't present, theAttributesUseProvider
is not used.- See Also:
- Constant Field Values
-
PARAM_KEY
public static final String PARAM_KEY
If the identifier is a class name, this is the name of the attribute name to read from - otherwise the identifier is taken.- See Also:
- Constant Field Values
-
PARAM_VALUE
public static final String PARAM_VALUE
Explicitly given value; mandatory for scope ScopeAttributesUseProvider.Scope.VALUE
.- See Also:
- Constant Field Values
-
-
Method Detail
-
provide
public org.apache.sling.scripting.sightly.use.ProviderOutcome provide(String identifier, org.apache.sling.scripting.sightly.render.RenderContext renderContext, Bindings arguments)
- Specified by:
provide
in interfaceorg.apache.sling.scripting.sightly.use.UseProvider
-
getRequest
protected org.apache.sling.api.SlingHttpServletRequest getRequest(org.apache.sling.scripting.sightly.render.RenderContext renderContext)
-
getAttribute
protected Object getAttribute(org.apache.sling.scripting.sightly.render.RenderContext renderContext, AttributesUseProvider.Scope scope, String key, Object rawValue)
-
-