Class 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 the EmulatedPageContext 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 in AttributesUseProvider.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 binding searchresult 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
    • Constructor Detail

      • AttributesUseProvider

        public AttributesUseProvider()
    • 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 interface org.apache.sling.scripting.sightly.use.UseProvider
      • checkType

        protected void checkType​(Object value,
                                 String identifier,
                                 String scriptName)
      • getRequest

        protected org.apache.sling.api.SlingHttpServletRequest getRequest​(org.apache.sling.scripting.sightly.render.RenderContext renderContext)