Class PipeBindings


  • public class PipeBindings
    extends Object
    Execution bindings of a pipe, and all expression related
    • Constructor Detail

      • PipeBindings

        public PipeBindings​(@NotNull
                            @NotNull Plumber plumber,
                            @NotNull
                            @NotNull org.apache.sling.api.resource.Resource resource)
      • PipeBindings

        public PipeBindings​(@NotNull
                            @NotNull org.apache.sling.api.resource.Resource resource)
        public constructor, built from pipe's resource
        Parameters:
        resource - pipe's configuration resource
      • PipeBindings

        public PipeBindings​(@NotNull
                            @NotNull org.apache.sling.api.resource.Resource resource,
                            boolean allowAdditionalScripts)
        public constructor, built from pipe's resource
        Parameters:
        resource - pipe's configuration resource
        allowAdditionalScripts - flag allowing additional scripts
    • Method Detail

      • embedAsScript

        public static String embedAsScript​(String value)
        Parameters:
        value -
        Returns:
        script equivalent
      • addBinding

        public void addBinding​(String name,
                               Object value)
        add a binding
        Parameters:
        name - binding's name
        value - binding's value
      • addBindings

        public void addBindings​(Map<String,​Object> bindings)
        adds additional bindings (global variables to use in child pipes expressions)
        Parameters:
        bindings - key/values bindings to add to the existing bindings
      • addScript

        public void addScript​(org.apache.sling.api.resource.ResourceResolver resolver,
                              String path)
        add a script file to the engine
        Parameters:
        resolver - resolver with which the file should be read
        path - path of the script file
      • evaluate

        protected Object evaluate​(String expr)
        evaluate a given expression
        Parameters:
        expr - ecma like expression
        Returns:
        object that is the result of the expression
      • instantiateObject

        public Object instantiateObject​(String expr)
        Instantiate object from expression
        Parameters:
        expr - ecma expression
        Returns:
        instantiated object
      • getBindings

        public Bindings getBindings()
        return registered bindings
        Returns:
        bindings
      • getExecutedResource

        public org.apache.sling.api.resource.Resource getExecutedResource​(String name)
        return Pipe name's F binding
        Parameters:
        name - name of the pipe
        Returns:
        resource corresponding to that pipe output
      • initializeScriptEngine

        public void initializeScriptEngine​(String engineName)
        Initialize the ScriptEngine. In some contexts the nashorn engine cannot be obtained from thread's class loader. Do fallback to system classloader.
        Parameters:
        engineName - name of the engine as registered in the JVM
      • conditionalString

        public String conditionalString​(String conditionalExpression)
        Return expression, instantiated expression or null if the expression is conditional and evaluation is falsy
        Parameters:
        conditionalExpression - can be static, or dynamic, can be conditional in which case it must be of following format $if${condition}someString. someString will be returned if condition is true, otherwise null
        Returns:
        instantiated expression or null if expression is conditional (see above) and condition is falsy
      • instantiateExpression

        public String instantiateExpression​(String expr)
        Expression is a function of variables from execution context, that we implement here as a String
        Parameters:
        expr - ecma like expression
        Returns:
        String that is the result of the expression
      • isBindingDefined

        public boolean isBindingDefined​(String name)
        check if a given bindings is defined or not
        Parameters:
        name - name of the binding
        Returns:
        true if name is registered
      • updateBindings

        public void updateBindings​(Pipe pipe,
                                   org.apache.sling.api.resource.Resource resource)
        Update current resource of a given pipe, and appropriate binding
        Parameters:
        pipe - pipe we'll extract the output binding from
        resource - current resource in the pipe execution
      • updateStaticBindings

        public void updateStaticBindings​(String name,
                                         org.apache.sling.api.resource.Resource resource)
        Update all the static bindings related to a given resource
        Parameters:
        name - name under which static bindings should be recorded
        resource - resource from which static bindings will be built
      • popCurrentError

        public String popCurrentError()
        Returns:
        current error if any, and reset it
      • setCurrentError

        public void setCurrentError​(String currentError)
        Parameters:
        currentError - error path to set