Package org.apache.sling.pipes

## Class PipeBindings

- java.lang.Object
- - org.apache.sling.pipes.PipeBindings

    public class PipeBindings
    extends Object

Execution bindings of a pipe, and all expression related

### Field Summary

Fields
`static String` `CACONFIG_BINDING`
`protected static Pattern` `CONDITIONAL_STRING`
`static String` `FALSE_BINDING`
`protected static String` `IF_PREFIX`
`static String` `INJECTED_SCRIPT_REGEXP`
`static String` `NAME_BINDING` add ${name.pipeName} binding allowing to retrieve pipeName's current resource name
`static String` `NN_ADDITIONALBINDINGS`
`static String` `NN_PROVIDERS`
`static String` `PATH_BINDING` add ${path.pipeName} binding allowing to retrieve pipeName's current resource path
`static String` `PN_ADDITIONALSCRIPTS`
`static String` `PN_ENGINE`

### Constructor Summary

Constructors
`PipeBindings​(@NotNull org.apache.sling.api.resource.Resource resource)` public constructor, built from pipe's resource
`PipeBindings​(@NotNull org.apache.sling.api.resource.Resource resource, boolean allowAdditionalScripts)` public constructor, built from pipe's resource
`PipeBindings​(@NotNull Plumber plumber, @NotNull org.apache.sling.api.resource.Resource resource)`

### Method Summary

All Methods Static Methods Instance Methods Concrete Methods
`void` `addBinding​(String name, Object value)` add a binding
`void` `addBindings​(Map<String,​Object> bindings)` adds additional bindings (global variables to use in child pipes expressions)
`void` `addScript​(org.apache.sling.api.resource.ResourceResolver resolver, String path)` add a script file to the engine
`String` `conditionalString​(String conditionalExpression)` Return expression, instantiated expression or null if the expression is conditional and evaluation is falsy
`static String` `embedAsScript​(String value)`
`protected Object` `evaluate​(String expr)` evaluate a given expression
`Bindings` `getBindings()` return registered bindings
`org.apache.sling.api.resource.Resource` `getExecutedResource​(String name)` return Pipe `name`'s F binding
`void` `initializeScriptEngine​(String engineName)` Initialize the ScriptEngine.
`String` `instantiateExpression​(String expr)` Expression is a function of variables from execution context, that we implement here as a String
`Object` `instantiateObject​(String expr)` Instantiate object from expression
`boolean` `isBindingDefined​(String name)` check if a given bindings is defined or not
`String` `popCurrentError()`
`void` `setCurrentError​(String currentError)`
`void` `updateBindings​(Pipe pipe, org.apache.sling.api.resource.Resource resource)` Update current resource of a given pipe, and appropriate binding
`void` `updateStaticBindings​(String name, org.apache.sling.api.resource.Resource resource)` Update all the static bindings related to a given resource

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### NN_ADDITIONALBINDINGS

    public static final String NN_ADDITIONALBINDINGS

See Also:
  Constant Field Values

#### PN_ADDITIONALSCRIPTS

    public static final String PN_ADDITIONALSCRIPTS

See Also:
  Constant Field Values

#### NN_PROVIDERS

    public static final String NN_PROVIDERS

See Also:
  Constant Field Values

#### PN_ENGINE

    public static final String PN_ENGINE

See Also:
  Constant Field Values

#### FALSE_BINDING

    public static final String FALSE_BINDING

See Also:
  Constant Field Values

#### PATH_BINDING

    public static final String PATH_BINDING

add ${path.pipeName} binding allowing to retrieve pipeName's current resource path

See Also:
  Constant Field Values

#### CACONFIG_BINDING

    public static final String CACONFIG_BINDING

See Also:
  Constant Field Values

#### NAME_BINDING

    public static final String NAME_BINDING

add ${name.pipeName} binding allowing to retrieve pipeName's current resource name

See Also:
  Constant Field Values

#### INJECTED_SCRIPT_REGEXP

    public static final String INJECTED_SCRIPT_REGEXP

See Also:
  Constant Field Values

#### IF_PREFIX

    protected static final String IF_PREFIX

See Also:
  Constant Field Values

#### CONDITIONAL_STRING

    protected static final Pattern CONDITIONAL_STRING

### 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