Wednesday, 8 January 2014

tJavaComponent Example in Talend

tJavaComponent complete referral
https://help.talend.com/display/TalendOpenStudioComponentsReferenceGuide521EN/5.3+tJava

 This post is about the excel file name from context variables

Let's say I have a file stored in my system location is : SADAKAR_DEMO_TABLE_1387461868.XLSX

Below java code gives the usage of tJava component

System.out.print(context.filename);

output:  
SADAKAR_DEMO_TABLE_1387461868.XLSX

String fileName = context.filename;
fileName.replaceAll("_\\d+.*", "").trim();

System.out.print("\n"+
           fileName.substring(0, fileName.lastIndexOf("_"))+"\n"+
           fileName.replaceAll("_[0-9]+", "")+"\n"+
            fileName.replaceAll("_\\d+.*", ""));
output:
SADAKAR_DEMO_TABLE
SADAKAR_DEMO_TABLE.XLSX

SADAKAR_DEMO_TABLE

System.out.print(context.filepath+context.filename);
output:
 \Users\sadakar002\Desktop\myproject\my_folder\my_sub_folder\SADAKAR_DEMO_TABLE.XLSX


Based up the file name you are inputting from context variable it'll display the corresponding results of your java code.