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 Modifier and Type Field Description static StringCACONFIG_BINDINGprotected static PatternCONDITIONAL_STRINGstatic StringFALSE_BINDINGprotected static StringIF_PREFIXstatic StringINJECTED_SCRIPT_REGEXPstatic StringNAME_BINDINGadd ${name.pipeName} binding allowing to retrieve pipeName's current resource namestatic StringNN_ADDITIONALBINDINGSstatic StringNN_PROVIDERSstatic StringPATH_BINDINGadd ${path.pipeName} binding allowing to retrieve pipeName's current resource pathstatic StringPN_ADDITIONALSCRIPTSstatic StringPN_ENGINE
-
Constructor Summary
Constructors Constructor Description PipeBindings(@NotNull org.apache.sling.api.resource.Resource resource)public constructor, built from pipe's resourcePipeBindings(@NotNull org.apache.sling.api.resource.Resource resource, boolean allowAdditionalScripts)public constructor, built from pipe's resourcePipeBindings(@NotNull Plumber plumber, @NotNull org.apache.sling.api.resource.Resource resource)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddBinding(String name, Object value)add a bindingvoidaddBindings(Map<String,Object> bindings)adds additional bindings (global variables to use in child pipes expressions)voidaddScript(org.apache.sling.api.resource.ResourceResolver resolver, String path)add a script file to the engineStringconditionalString(String conditionalExpression)Return expression, instantiated expression or null if the expression is conditional and evaluation is falsystatic StringembedAsScript(String value)protected Objectevaluate(String expr)evaluate a given expressionBindingsgetBindings()return registered bindingsorg.apache.sling.api.resource.ResourcegetExecutedResource(String name)return Pipename's F bindingvoidinitializeScriptEngine(String engineName)Initialize the ScriptEngine.StringinstantiateExpression(String expr)Expression is a function of variables from execution context, that we implement here as a StringObjectinstantiateObject(String expr)Instantiate object from expressionbooleanisBindingDefined(String name)check if a given bindings is defined or notStringpopCurrentError()voidsetCurrentError(String currentError)voidupdateBindings(Pipe pipe, org.apache.sling.api.resource.Resource resource)Update current resource of a given pipe, and appropriate bindingvoidupdateStaticBindings(String name, org.apache.sling.api.resource.Resource resource)Update all the static bindings related to a given resource
-
-
-
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 resourceallowAdditionalScripts- 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 namevalue- 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 readpath- 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 Pipename'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
nameis 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 fromresource- 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 recordedresource- 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
-
-