This document shows some common Spring Expression Language (SpEL) use cases for the accelerator.yaml file.

Variables

All the values added as options in the accelerator section from the yaml file can be referenced as variables in the engine section, you can access the value using the syntax #<option name> i.e.

options:
  - name: foo
    dataType: string
    inputType: text
...
engine:
  - include: ["some/file.txt"]
    chain:
    - type: ReplaceText
      substitutions:
      - text: bar
        with: "#foo"

This sample will replace every occurrence of the text bar in the file some/file.txt for the contents of the foo option.

Conditionals

You can use boolean options for conditional in your transformations.

options:
  - name: numbers
      inputType: select
      choices:
        first: First Option
        second: Second Option      
      defaultValue: first
...
engine:
  - include: ["some/file.txt"]
    condition: "#numbers == 'first'"
    chain:
    - type: ReplaceText
      substitutions:
      - text: bar
        with: "#foo"

This will replace the text only if the selected option is the first one.

Rewrite Path Concatenation

options:
  - name: renameTo
    dataType: string
    inputType: text
...
engine:
  - include: ["some/file.txt"]    
    chain:
    - type: RewritePath
      rewriteTo: "'somewhere/' + #renameTo + '.txt'"

Regular Expressions

Regular expressions let you use patterns to use as a matcher for strings, here is a small example of what you can do with them.

options:
  - name: foo
    dataType: string
    inputType: text
    defaultValue: abcZ123
...
engine:
  - include: ["some/file.txt"]
    condition: "#foo matches '[a-z]+Z\\d+'"
    chain:
    - type: ReplaceText
      substitutions:
      - text: bar
        with: "#foo"

This example uses RegEx to match a string of letters that ends with a capital z and ends with any number of digits. If this condition is fulfilled, the text wil be replaced in the file file.txt.

check-circle-line exclamation-circle-line close-line
Scroll to top icon