Wiki Markup |
---|
h2. 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] and [FTP] components for setting dynamic file patterns for both consumer and producer. h3. |
...
Syntax |
...
This language is an *extension* to the [Simple] language so the [Simple] syntax applies also. So the table below only lists the additional. |
...
As opposed to [Simple] language [File Language] also supports [Constant] expressions so you can enter a fixed filename. |
...
All the file tokens uses the same expression name as the method on the {{java.io.File}} object, for instance {{file:absolute}} refers to the {{java.io.File.getAbsolute()}} method. Notice that not all expressions is supported by the current Exchange. For instance the [FTP] component only supports a few of the options, where as the [File] component support all of them. |
...
Expression | Type | File Consumer | File Producer | FTP Consumer | FTP Producer | Description |
---|---|---|---|---|---|---|
file:name | String | yes | no | yes | no | refers to the file name |
file:name.ext | String | yes | no | yes | no | Camel 2.0: refers to the file extension only |
file:name.noext | String | yes | no | yes | no | refers to the file name with no extension |
file:parent | String | yes | no | yes | no | refers to the file parent |
file:path | String | yes | no | yes | no | refers to the file path |
file:absolute.path | String | yes | no | no | no | refers to the absolute file path |
file:canonical.path | String | yes | no | no | no | refers to the canonical path |
file:length | Long | yes | no | yes | no | refers to the file length returned as a Long type |
file:modified | Date | yes | no | yes | no | Camel 2.0: refers to the file last modified returned as a Date type |
date:command:pattern | String | yes | no | no | no | for date formatting using the |
File token example
...
{div:class=confluenceTableSmall} || Expression || Type || File Consumer || File Producer || FTP Consumer || FTP Producer || Description || | file:name | String | yes | no | yes | no | refers to the file name | | file:name.ext | String | yes | no | yes | no | Camel 2.0: refers to the file extension only | | file:name.noext | String | yes | no | yes | no | refers to the file name with no extension | | file:parent | String | yes | no | yes | no | refers to the file parent | | file:path | String | yes | no | yes | no | refers to the file path | | file:absolute.path | String | yes | no | no | no | refers to the absolute file path | | file:canonical.path | String | yes | no | no | no | refers to the canonical path | | file:length | Long | yes | no | yes | no | refers to the file length returned as a Long type | | file:modified | Date | yes | no | yes | no | Camel 2.0: refers to the file last modified returned as a Date type | | date:_command:pattern_ | String | yes | no | no | no | for date formatting using the {{java.text.SimepleDataFormat}} patterns. Is an *extension* to the [Simple] language. Additional command is: *file* for the last modified timestamp of the file. Notice: all the commands from the [Simple] language can also be used. | {div} h3. File token example We have a {{java.io.File}} handle for the file {{hello.txt}} in the following directory: {{D:\project\camel\camel-core\target\filelanguage}}. The file tokens will return as: |
...
Expression
...
Returns
|| Expression || Returns || | file:name |
...
| hello.txt |
...
| | file:name.ext |
...
txt
| txt | | file:name.noext |
...
hello
| hello | | file:parent |
...
| target\filelanguage |
...
| | file:path |
...
| target\filelanguage\hello.txt |
...
| | file:absolute.path |
...
| D:\project\camel\camel-core\target\filelanguage\hello.txt |
...
| | file:canonical.path |
...
| D:\project\camel\camel-core\target\filelanguage\hello.txt |
...
Samples
You can enter a fixed Constant expression such as myfile.txt
:
Code Block |
---|
| h3. Samples You can enter a fixed [Constant] expression such as {{myfile.txt}}: {code} expression="myfile.txt" {code} 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: |
...
{code |
} expression="backup/${date:now:yyyyMMdd}/${file:name.noext}.bak" {code} relative folder names is also supported so suppose the backup folder should be a sibling folder then you can append .. as: |
...
{code |
} expression="../backup/${date:now:yyyyMMdd}/${file:name.noext}.bak" {code} 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: |
...
{code |
} expression="../backup/${date:now:yyyyMMdd}/type-${in.header.type}/backup-of-${file:name.noext}.bak" {code} If you have a custom Date you want to use in the expression then Camel supports retrieving dates from the message header. |
...
{code |
} expression="orders/order-${in.header.customerId}-${date:in.header.orderDate:yyyyMMdd}.xml" {code} 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: |
...
{code |
} expression="uniquefile-${bean:myguidgenerator.generateid}.txt" {code} 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
...
h3. Dependencies The File language is part of *camel-core*. |