File Expression Language
Available as of Camel 1.5
The File Expression Language is an extension to the Simple language, adding file related capabilities. These capabilities is related to common use cases working with file path and names. The goal is to allow expression to be used with the File component for setting dynamic file patterns for both the file consumer and file producer.
Syntax
This language is an extension the the Simple language so the Simple syntax applies also.
All the file tokens uses the same as the method on the java.io.File
object, for instance file:absolute
refers to the java.io.File.getAbsolute()
method.
All options returns a String object.
Expression |
Description |
---|---|
file:name | refers to the file name |
file:name.noext | refers to the file name with no extension |
file:parent | refers to the file parent |
file:path | refers to the file path |
file:absolute | refers to the absolute file |
file:canonical.path | refers to the canonical path |
date:command:pattern |
for date formatting using the |
bean:bean expression |
invoking a bean expression using the Bean language. |
simple:simple expression |
to invoke the simple expression, however simple: can be omitted as this language extends the simple language |
Samples
Lets assume we use the file consumer to read files and want to move the read files to backup folder with the current date as a sub folder. This can be archived using an expression like:
expression="backup/${date:now:yyyyMMdd}/${file:name.noext}.bak"
relative folder names is also supported so suppose the backup folder should be a sibling folder then you can append .. as:
expression="../backup/${date:now:yyyyMMdd}/${file:name.noext}.bak"
As this is an extension to the Simple language we have access to all the goodies from this language also, so in this use case we want to use the in.header.type as a parameter in the dynamic expression:
expression="../backup/${date:now:yyyyMMdd}/type-${in.header.type}/backup-of-${file:name.noext}.bak"
If you have a custom Date you want to use in the expression then Camel supports retrieving dates from the message header.
expression="orders/order-${in.header.customerId}-${date:in.header.orderDate:yyyyMMdd}.xml"
And finally we can also use a bean expression to invoke a POJO class that generates some String output (or convertible to String) to be used:
expression="uniquefile-${bean:myguidgenerator.generateid}.txt"
And of course all this can be combined in one expression where you can use the File Language, Simple and the Bean language in one combined expression. This is pretty powerful for those common file path patterns.
Dependencies
The File language is part of camel-core.