cFlatPack
library
cFlatPack Standard properties
These properties are used to configure cFlatPack running in the Standard Job framework.
The Standard
cFlatPack component belongs to the Transformation family.
Basic settings
When using as a start component in a route: |
 |
PZMAP FileType |
The PZMAP file is the Flatpack configuration file that is used to configure the Select the PZMAP file type from Filename and Repository Resource.
Filename: The PZMAP file is stored in the local file
Repository Resource: The PZMAP file is stored in the |
PZMAP Filename |
This option appears when Filename is selected in the |
PZMAP Repository Resource |
This option appears when Repository |
Fixed Positional file |
Select this option if the file is a fixed format file. |
Delimited file |
Select this option if the file is delimited.
Text Qualifier: Specify the text
Text Delimiter: Specify the |
Split Rows |
Select this check box to process each row one by one. |
Ignore First Record |
Select this check box to ignore the first line for delimited files |
Allow Short Lines |
Select this check box to allow lines shorter than expected by the PZMAP file. |
Ignore Extra Columns |
Select this check box to allow lines longer than expected by the PZMAP file and ignore |
When using as a middle or end component in a Route: |
 |
Use Exist cFlatPack |
Click […] and select the cFlatPack component to be used as the file parser in |
Usage
Usage rule |
cFlatPack can be a start, middle, or end component in |
Limitation |
 n/a |
Parsing delimited file using the cFlatPack component
This scenario applies only to Talend Open Studio for ESB, Talend Data Services Platform and Talend Data Fabric.
In this scenario, a cFile component reads a delimited file
from the local file system, which contains the customers information including id, first
name, surname, and order id, as shown below:
1 2 3 4 5 |
1,"Harry",Carter,21 2,Padre,Boulevard,22 3,Andrew,Polk,23 4,Herbert,Reagan,"24" 5,Chester,Eisenhower,25 |
The file is parsed by the cFlatPack component, using
a predefined PZMAP XML file:
1 2 3 4 5 6 7 8 9 10 |
<?xml version="1.0"?> <!-- DTD can be pulled from the Jar or over the web--> <!DOCTYPE PZMAP SYSTEM "flatpack.dtd" > <!--<!DOCTYPE PZMAP SYSTEM "http://flatpack.sourceforge.net/flatpack.dtd" >--> <PZMAP> <COLUMN name="id" length="5" /> <COLUMN name="name" length="20" /> <COLUMN name="surname" length="20" /> <COLUMN name="orderid" length="5" /> </PZMAP> |
The customer information is then printed in the execution console by a cBean component.
For more information about the PZMAP file configuration, see the website http://flatpack.sourceforge.net/documentation/index.html.
Creating a Bean
In this section, a Java bean is created to print the id, first name, and surname
from the customer information with the corresponding column names into the execution
console.
-
From the repository tree view, expand the Code node and right click the Beans node. In the contextual menu, select Create Bean.
The New Bean wizard opens. In the Name field, type in a name for the bean, for
example, ReadOrder. Click Finish to close the wizard. The bean is opened automatically
in the design workspace. -
Enter the following code in the design workspace.
1234567891011121314151617181920212223242526package beans;import org.apache.camel.Exchange;public class ReadOrder {public static void getCustomer(Exchange exch) {if(exch.getIn().getBody() !=null){java.util.Map data = exch.getIn().getBody(java.util.Map.class);if(data != null){String id= (String)(data.get("id"));System.out.println("id :"+id);String name= (String)(data.get("name"));System.out.println("name :"+name);String surname= (String)(data.get("surname"));System.out.println("surname :"+surname);exch.getIn().setBody("<customer><id>" + id + "</id><name>" + name + "</name><surname>" + surname + "</surname></customer>", String.class);}}}}
- Press Ctrl+S to save your bean.
For more information about creating and using Java Beans, see
Talend Studio User
Guide.
Dropping and linking the components
-
From the Palette, drag and drop a
cFile, two cFlatPack, a cBean, and a
cLog component onto the design
workspace. -
Link the components using the Row >
Route connection as shown above. - Label the components to better identify their roles in the Route.
Configuring the components and connections
-
Double-click Delimited_file in the design workspace to
display its Basic settings view in the
Component tab. -
In the Path field, browse to or enter the file path
where the flatpack file is located.In the FileName field, enter the name of
the file to be processed. -
Double-click Flat_file_parser to display its Basic settings view in the Component tab.
-
Click […] and in the Select a
Node: wizard, select FlatPack_config to configure the structure of the input
file. -
Double-click FlatPack_config to display its Basic settings view in the Component tab.
-
In the PZMAP FileType list, select Filename to use the PZMAP XML file from the local file
system to configure the structure of the input file. Then in the PZMAP Filename field, browse to path
where the PZMAP XML file is located.Select the Allow Short Lines check box to
allow lines shorter than expected by the PZMAP file.Keep the default settings of the other options. -
Double-click ReadOrder to display its Basic settings view in the Component tab.
-
Select the New Instance option to invoke a Java bean
that is stored in the Code node of the
Repository.In the Bean class field, enter the name of the bean
class, beans.ReadOrder.class which is just
created. -
Keep the default settings of the cLog
component to log the message exchanges. - Press Ctrl+S to save your Route.
Viewing code and executing the Route
-
Click the Code tab at the bottom of the
design workspace to have a look at the generated code.As shown in the code, one route is built from"Delimited_file_cFile_1"
, to
"cFlatPack_1"
. The other is built from
cFlatPack_2
, processed by"cBean_1"
and
"cLog_1"
sequentially. -
Click the Run view to display it and
click the Run button to launch the
execution of your Route. You can also press F6 to execute it.RESULT: The delimited file is parsed. The id, first name, and surname of the customer
information with the corresponding column names is shown in the execution
console.