// This JavaScript asks for a start and ending date with text dialog boxes. // It is a proof of concept if dialogs could be used out of JavaScript within transformations. // This could be a base for discussion if a general input step dialog should be created. // It runs within Spoon, Pan and launched by the "Test script" button within the JavaScript editor. // @author Jens Bleuel // @since 2006-07-11
// to get the "Test script" button at the editor working correctly we need the existing Display / Shell var display; var displayHasToBeDisposed=false; var shell=null;
try { display=Packages.org.eclipse.swt.widgets.Display.getCurrent(); shell=display.getActiveShell(); } catch(e) { // if it runs in batch mode (Pan or preview mode) no Display is available, so we have to create one display=new Packages.org.eclipse.swt.widgets.Display(); displayHasToBeDisposed=true; shell=new Packages.org.eclipse.swt.widgets.Shell(display); }
// if we run in Pan we need to load the properties: if(!Packages.org.pentaho.di.ui.core.PropsUI.isInitialized()) { Packages.org.pentaho.di.ui.core.PropsUI.init(display,2); //2=TYPE_PROPERTIES_PAN }
var dateDefaultFrom=DateFromProposal.getString().substr(0,10);//only the date and not the time var dialogDateFrom=newPackages.org.pentaho.di.ui.core.dialog.EnterTextDialog(shell,"Date from", "Please enter the beginning date", dateDefaultFrom); var dateFromAsString=dialogDateFrom.open();
if(dateFromAsString!=null&& dateFromAsString.length()>0) { var dateDefaultTo=DateToProposal.getString().substr(0,10);//only the date and not the time; var dialogDateTo=newPackages.org.pentaho.di.ui.core.dialog.EnterTextDialog(shell,"Date to", "Please enter the ending date", dateDefaultTo); var dateToAsString=dialogDateTo.open(); if(dateToAsString!=null&& dateToAsString.length()>0) { // here you could check or change formats a.s.o } else { // stop transformation when user cancels throw new Packages.java.lang.RuntimeException("Input canceled by the user."); } } else { // stop transformation when user cancels throw new Packages.java.lang.RuntimeException("Input canceled by the user."); } if(displayHasToBeDisposed) { display.dispose(); } |
文本文件输出
DateFromProposal@DateToProposal@dateFromAsString@dateToAsString 2006/01/01 00:00:00.000@2006/12/31 00:00:00.000@2014/01/02@2014/12/31 |
// C:\temp\LIM_kettle\ST18.PROTOKL.TENOPROD_2006*07_21_00_09 // rightstr(16),截取右边16个字符 var dat = DIR.Clone().rightstr(16).str2dat("yyyy*MM_dd_HH_mm"); |
文本文件输出:
DIR@@@dat C:\temp\LIM_kettle\ST18.PROTOKL.TENOPROD_2006*07_21_00_09@@@2006/07/21 00:09:00.000 |
var strArray = File.getString().split("/");//数组 var last = strArray[strArray.length-1];//数组中的最后一个即文件名 |
文本文件输出
File@@@@last C:/Test/file.txt@@@@file.txt |
java; //不写木发现影响,仅限本例 //16进制->10 var nummerke = Packages.java.lang.Integer.valueOf(Hex.getString(), 16).intValue(); //Alert(nummerke); |
文本文件输出:
Hex;nummerke DEAD; 0057005 |
var first = amountField.Clone().substr(0,1).getString(); var amount = amountField.Clone().substr(1).str2num("###.00",".").getNumber();
if (first.equals("D")) { amount = -amount; } |
文本文件输出:
amountField@@@first@@@amount C100.00 @@@C@@@00100.00 D100.00 @@@D@@@-00100.00 |