Class EmulatedPageContext

  • All Implemented Interfaces:
    org.apache.sling.scripting.sightly.pojo.Use, org.apache.sling.scripting.sightly.Record<Object>

    public class EmulatedPageContext
    extends Object
    implements org.apache.sling.scripting.sightly.pojo.Use, org.apache.sling.scripting.sightly.Record<Object>
    Implements a kind of pagecontext for HTL by putting a map into a request attribute, to enable communication between templates. There are separate maps for each script name - that is, the resource of the script.
    Since:
    09/2017
    Author:
    Hans-Peter Stoerr
    • Field Detail

      • simulatedPageContext

        protected Map<String,​Object> simulatedPageContext
      • REQUESTATTR_PAGECONTEXTMAP

        public static final String REQUESTATTR_PAGECONTEXTMAP
        Map<String,Map<String,Object>> from scriptname to simulated pagecontext map, since the scriptname is the script resource and the bindings are generated freshly each call.
    • Constructor Detail

      • EmulatedPageContext

        public EmulatedPageContext()
    • Method Detail

      • init

        public void init​(Bindings bindings)
        Initializes the maps.
        Specified by:
        init in interface org.apache.sling.scripting.sightly.pojo.Use
      • getScriptName

        protected static String getScriptName​(Bindings bindings)
      • map

        public static Map<String,​Object> map​(Bindings bindings)
        Allows easy access to the map when used in Java Code: returns the actual map used.
      • getProperty

        public Object getProperty​(String name)
        Specified by:
        getProperty in interface org.apache.sling.scripting.sightly.Record<Object>
      • getPropertyNames

        public Set<String> getPropertyNames()
        Specified by:
        getPropertyNames in interface org.apache.sling.scripting.sightly.Record<Object>
      • asMap

        public Map<String,​Object> asMap()
        Returns the emulated page context as a map.