HOP-83 writ to log, syslog transforms (#103)
diff --git a/archive-pipeline-transforms/src/main/java/engine/transforms/scriptvalues_mod/ScriptValuesAddClasses.java b/archive-pipeline-transforms/src/main/java/engine/transforms/scriptvalues_mod/ScriptValuesAddClasses.java
deleted file mode 100644
index 01cfa74..0000000
--- a/archive-pipeline-transforms/src/main/java/engine/transforms/scriptvalues_mod/ScriptValuesAddClasses.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*! ******************************************************************************
- *
- * Hop : The Hop Orchestration Platform
- *
- * http://www.project-hop.org
- *
- *******************************************************************************
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************************/
-
-package org.apache.hop.pipeline.transforms.scriptvalues_mod;
-
-public class ScriptValuesAddClasses {
-
- private Class<?> addClass;
- private Object addObject;
- private String strJSName;
-
- // private String strJarFile;
-
- public ScriptValuesAddClasses( Class<?> addClass, Object addObject, String strJSName ) {
- super();
- this.addClass = addClass;
- this.addObject = addObject;
- this.strJSName = strJSName;
- }
-
- public Class<?> getAddClass() {
- return this.addClass;
- }
-
- public Object getAddObject() {
- return this.addObject;
- }
-
- public String getJSName() {
- return this.strJSName;
- }
-}
diff --git a/archive-pipeline-transforms/src/main/java/engine/transforms/scriptvalues_mod/ScriptValuesAddedFunctions.java b/archive-pipeline-transforms/src/main/java/engine/transforms/scriptvalues_mod/ScriptValuesAddedFunctions.java
deleted file mode 100644
index 7fa5618..0000000
--- a/archive-pipeline-transforms/src/main/java/engine/transforms/scriptvalues_mod/ScriptValuesAddedFunctions.java
+++ /dev/null
@@ -1,2858 +0,0 @@
-// CHECKSTYLE:FileLength:OFF
-/*! ******************************************************************************
- *
- * Hop : The Hop Orchestration Platform
- *
- * http://www.project-hop.org
- *
- *******************************************************************************
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************************/
-
-package org.apache.hop.pipeline.transforms.scriptvalues_mod;
-
-import com.google.common.annotations.VisibleForTesting;
-import org.apache.commons.vfs2.FileObject;
-import org.apache.commons.vfs2.FileType;
-import org.apache.commons.vfs2.FileUtil;
-import org.apache.hop.core.Const;
-import org.apache.hop.core.database.Database;
-import org.apache.hop.core.database.DatabaseMeta;
-import org.apache.hop.core.exception.HopFileException;
-import org.apache.hop.core.gui.HopUiFactory;
-import org.apache.hop.core.gui.HopUiInterface;
-import org.apache.hop.core.row.RowDataUtil;
-import org.apache.hop.core.row.IRowMeta;
-import org.apache.hop.core.util.EnvUtil;
-import org.apache.hop.core.variables.iVariables;
-import org.apache.hop.core.vfs.HopVFS;
-import org.apache.hop.pipeline.Pipeline;
-import org.apache.hop.pipeline.transform.ITransform;
-import org.apache.hop.pipeline.transforms.loadfileinput.LoadFileInput;
-import org.mozilla.javascript.Context;
-import org.mozilla.javascript.EvaluatorException;
-import org.mozilla.javascript.Function;
-import org.mozilla.javascript.JavaScriptException;
-import org.mozilla.javascript.Scriptable;
-import org.mozilla.javascript.ScriptableObject;
-import org.mozilla.javascript.WrappedException;
-
-import javax.mail.Message;
-import javax.mail.Session;
-import javax.mail.Transport;
-import javax.mail.internet.InternetAddress;
-import javax.mail.internet.MimeMessage;
-import java.io.BufferedReader;
-import java.io.DataOutputStream;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.Reader;
-import java.net.InetAddress;
-import java.nio.ByteBuffer;
-import java.nio.CharBuffer;
-import java.nio.charset.Charset;
-import java.nio.charset.CharsetDecoder;
-import java.sql.ResultSet;
-import java.sql.ResultSetMetaData;
-import java.text.DateFormat;
-import java.text.DecimalFormat;
-import java.text.DecimalFormatSymbols;
-import java.text.Format;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.List;
-import java.util.Locale;
-import java.util.Properties;
-import java.util.TimeZone;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-public class ScriptValuesAddedFunctions extends ScriptableObject {
-
- public static final long serialVersionUID = 1L;
-
- public static final int STRING_FUNCTION = 0;
- public static final int NUMERIC_FUNCTION = 1;
- public static final int DATE_FUNCTION = 2;
- public static final int LOGIC_FUNCTION = 3;
- public static final int SPECIAL_FUNCTION = 4;
- public static final int FILE_FUNCTION = 5;
-
- public static String[] jsFunctionList = {
- "appendToFile", "getPipelineName", "writeToLog", "getFiscalDate", "getProcessCount", "ceil", "floor",
- "abs", "getDayNumber", "isWorkingDay", "fireToDB", "getNextWorkingDay", "quarter", "dateDiff", "dateAdd",
- "fillString", "isCodepage", "ltrim", "rtrim", "lpad", "rpad", "week", "month", "year", "str2RegExp",
- "fileExists", "touch", "isRegExp", "date2str", "str2date", "sendMail", "replace", "decode", "isNum",
- "isDate", "lower", "upper", "str2num", "num2str", "Alert", "setEnvironmentVar", "getEnvironmentVar",
- "LoadScriptFile", "LoadScriptFromTab", "print", "println", "resolveIP", "trim", "substr", "getVariable",
- "setVariable", "LuhnCheck", "getDigitsOnly", "indexOf", "getOutputRowMeta", "getInputRowMeta",
- "createRowCopy", "putRow", "deleteFile", "createFolder", "copyFile", "getFileSize", "isFile", "isFolder",
- "getShortFilename", "getFileExtension", "getParentFoldername", "getLastModifiedTime", "trunc", "truncDate",
- "moveFile", "execProcess", "isEmpty", "isMailValid", "escapeXml", "removeDigits", "initCap",
- "protectXMLCDATA", "unEscapeXml", "escapeSQL", "escapeHtml", "unEscapeHtml", "loadFileContent",
- "getOcuranceString", "removeCRLF" };
-
-
- enum VariableScope {
- SYSTEM,
- ROOT,
- PARENT,
- GRAND_PARENT
- }
-
-
- // This is only used for reading, so no concurrency problems.
- // todo: move in the real variables of the transform.
- // private static iVariables variables = Variables.getADefaultVariableSpace();
-
- // Functions to Add
- // date2num, num2date,
- // fisc_date, isNull
- //
-
- public static String getDigitsOnly( Context actualContext, Scriptable actualObject, Object[] ArgList,
- Function FunctionContext ) {
- if ( ArgList.length == 1 ) {
- return Const.getDigitsOnly( Context.toString( ArgList[ 0 ] ) );
- } else {
- throw Context.reportRuntimeError( "The function call getDigitsOnly requires 1 argument." );
-
- }
- }
-
- public static boolean LuhnCheck( Context actualContext, Scriptable actualObject, Object[] ArgList,
- Function FunctionContext ) {
-
- boolean returnCode = false;
-
- if ( ArgList.length == 1 ) {
- if ( !isNull( ArgList ) && !isUndefined( ArgList ) ) {
- try {
- int sum = 0;
- int digit = 0;
- int addend = 0;
- boolean timesTwo = false;
- String argstring = Context.toString( ArgList[ 0 ] );
-
- for ( int i = argstring.length() - 1; i >= 0; i-- ) {
- digit = Integer.parseInt( argstring.substring( i, i + 1 ) );
- if ( timesTwo ) {
- addend = digit * 2;
- if ( addend > 9 ) {
- addend -= 9;
- }
- } else {
- addend = digit;
- }
- sum += addend;
- timesTwo = !timesTwo;
- }
-
- int modulus = sum % 10;
- if ( modulus == 0 ) {
- returnCode = true;
- }
- } catch ( Exception e ) {
- // No Need to throw exception
- // This means that input can not be parsed to Integer
- }
-
- }
- } else {
- throw Context.reportRuntimeError( "The function call LuhnCheck requires 1 argument." );
-
- }
- return returnCode;
- }
-
- public static int indexOf( Context actualContext, Scriptable actualObject, Object[] ArgList,
- Function FunctionContext ) {
-
- int returnIndex = -1;
-
- if ( ArgList.length == 2 || ArgList.length == 3 ) {
- if ( !isNull( ArgList ) && !isUndefined( ArgList ) ) {
- String string = Context.toString( ArgList[ 0 ] );
- String subString = Context.toString( ArgList[ 1 ] );
-
- int fromIndex = 0;
- if ( ArgList.length == 3 ) {
- fromIndex = (int) Math.round( Context.toNumber( ArgList[ 2 ] ) );
- }
- returnIndex = string.indexOf( subString, fromIndex );
- }
- } else {
- throw Context.reportRuntimeError( "The function call indexOf requires 2 or 3 arguments" );
- }
- return returnIndex;
- }
-
- public static Object getTransformationName( Context actualContext, Scriptable actualObject, Object[] ArgList,
- Function FunctionContext ) {
- try {
- Object objTranName = Context.toString( actualObject.get( "_PipelineName_", actualObject ) );
- return objTranName;
- } catch ( Exception e ) {
- throw Context.reportRuntimeError( e.toString() );
- }
- }
-
- public static void appendToFile( Context actualContext, Scriptable actualObject, Object[] ArgList,
- Function FunctionContext ) {
-
- if ( !isNull( ArgList ) && !isUndefined( ArgList ) ) {
- try {
- FileOutputStream file = new FileOutputStream( Context.toString( ArgList[ 0 ] ), true );
- DataOutputStream out = new DataOutputStream( file );
- out.writeBytes( Context.toString( ArgList[ 1 ] ) );
- out.flush();
- out.close();
- } catch ( Exception er ) {
- throw Context.reportRuntimeError( er.toString() );
- }
- } else {
- throw Context.reportRuntimeError( "The function call appendToFile requires arguments." );
- }
- }
-
- public static Object getFiscalDate( Context actualContext, Scriptable actualObject, Object[] ArgList,
- Function FunctionContext ) {
-
- if ( ArgList.length == 2 ) {
- try {
- if ( isNull( ArgList ) ) {
- return null;
- } else if ( isUndefined( ArgList ) ) {
- return Context.getUndefinedValue();
- }
- java.util.Date dIn = (java.util.Date) Context.jsToJava( ArgList[ 0 ], java.util.Date.class );
- Calendar startDate = Calendar.getInstance();
- Calendar fisStartDate = Calendar.getInstance();
- Calendar fisOffsetDate = Calendar.getInstance();
- startDate.setTime( dIn );
- Format dfFormatter = new SimpleDateFormat( "dd.MM.yyyy" );
- String strOffsetDate = Context.toString( ArgList[ 1 ] ) + String.valueOf( startDate.get( Calendar.YEAR ) );
- java.util.Date dOffset = (java.util.Date) dfFormatter.parseObject( strOffsetDate );
- fisOffsetDate.setTime( dOffset );
-
- String strFisStartDate = "01.01." + String.valueOf( startDate.get( Calendar.YEAR ) + 1 );
- fisStartDate.setTime( (java.util.Date) dfFormatter.parseObject( strFisStartDate ) );
- int iDaysToAdd = (int) ( ( startDate.getTimeInMillis() - fisOffsetDate.getTimeInMillis() ) / 86400000 );
- fisStartDate.add( Calendar.DATE, iDaysToAdd );
- return fisStartDate.getTime();
- } catch ( Exception e ) {
- throw Context.reportRuntimeError( e.toString() );
- }
- } else {
- throw Context.reportRuntimeError( "The function call getFiscalDate requires 2 arguments." );
- }
-
- }
-
- public static double getProcessCount( Context actualContext, Scriptable actualObject, Object[] ArgList,
- Function FunctionContext ) {
-
- if ( ArgList.length == 1 ) {
- try {
- Object scmO = actualObject.get( "_transform_", actualObject );
- ITransform scm = (ITransform) Context.jsToJava( scmO, ITransform.class );
- String strType = Context.toString( ArgList[ 0 ] ).toLowerCase();
-
- if ( strType.equals( "i" ) ) {
- return scm.getLinesInput();
- } else if ( strType.equals( "o" ) ) {
- return scm.getLinesOutput();
- } else if ( strType.equals( "r" ) ) {
- return scm.getLinesRead();
- } else if ( strType.equals( "u" ) ) {
- return scm.getLinesUpdated();
- } else if ( strType.equals( "w" ) ) {
- return scm.getLinesWritten();
- } else if ( strType.equals( "e" ) ) {
- return scm.getLinesRejected();
- } else {
- return 0;
- }
- } catch ( Exception e ) {
- // throw Context.reportRuntimeError(e.toString());
- return 0;
- }
- } else {
- throw Context.reportRuntimeError( "The function call getProcessCount requires 1 argument." );
- }
- }
-
- public static void writeToLog( Context actualContext, Scriptable actualObject, Object[] ArgList,
- Function FunctionContext ) {
-
- switch ( ArgList.length ) {
- case 1:
- try {
- if ( !isNull( ArgList ) && !isUndefined( ArgList ) ) {
- Object scmO = actualObject.get( "_transform_", actualObject );
- ScriptValuesMod scm = (ScriptValuesMod) Context.jsToJava( scmO, ScriptValuesMod.class );
- String strMessage = Context.toString( ArgList[ 0 ] );
- scm.logDebug( strMessage );
- }
- } catch ( Exception e ) {
- // Ignore errors
- }
- break;
- case 2:
- try {
- if ( !isNull( ArgList ) && !isUndefined( ArgList ) ) {
- Object scmO = actualObject.get( "_transform_", actualObject );
- ScriptValuesMod scm = (ScriptValuesMod) Context.jsToJava( scmO, ScriptValuesMod.class );
-
- String strType = Context.toString( ArgList[ 0 ] ).toLowerCase();
- String strMessage = Context.toString( ArgList[ 1 ] );
- if ( strType.equals( "b" ) ) {
- scm.logBasic( strMessage );
- } else if ( strType.equals( "d" ) ) {
- scm.logDebug( strMessage );
- } else if ( strType.equals( "l" ) ) {
- scm.logDetailed( strMessage );
- } else if ( strType.equals( "e" ) ) {
- scm.logError( strMessage );
- } else if ( strType.equals( "m" ) ) {
- scm.logMinimal( strMessage );
- } else if ( strType.equals( "r" ) ) {
- scm.logRowlevel( strMessage );
- }
- }
- } catch ( Exception e ) {
- // Ignore errors
- }
- break;
- default:
- throw Context.reportRuntimeError( "The function call writeToLog requires 1 or 2 arguments." );
- }
- }
-
- private static boolean isUndefined( Object ArgList ) {
- return isUndefined( new Object[] { ArgList }, new int[] { 0 } );
- }
-
- private static boolean isUndefined( Object[] ArgList, int[] iArrToCheck ) {
- for ( int i = 0; i < iArrToCheck.length; i++ ) {
- if ( ArgList[ iArrToCheck[ i ] ].equals( Context.getUndefinedValue() ) ) {
- return true;
- }
- }
- return false;
- }
-
- private static boolean isNull( Object ArgList ) {
- return isNull( new Object[] { ArgList }, new int[] { 0 } );
- }
-
- private static boolean isNull( Object[] ArgList ) {
- for ( int i = 0; i < ArgList.length; i++ ) {
- if ( ArgList[ i ] == null || ArgList[ i ].equals( null ) ) {
- return true;
- }
- }
- return false;
- }
-
- private static boolean isNull( Object[] ArgList, int[] iArrToCheck ) {
- for ( int i = 0; i < iArrToCheck.length; i++ ) {
- if ( ArgList[ iArrToCheck[ i ] ] == null || ArgList[ iArrToCheck[ i ] ].equals( null ) ) {
- return true;
- }
- }
- return false;
- }
-
- public static Object abs( Context actualContext, Scriptable actualObject, Object[] ArgList,
- Function FunctionContext ) {
-
- if ( ArgList.length == 1 ) {
- try {
- if ( isNull( ArgList[ 0 ] ) ) {
- return new Double( Double.NaN );
- } else if ( isUndefined( ArgList[ 0 ] ) ) {
- return Context.getUndefinedValue();
- } else {
- return new Double( Math.abs( Context.toNumber( ArgList[ 0 ] ) ) );
- }
- } catch ( Exception e ) {
- return null;
- }
- } else {
- throw Context.reportRuntimeError( "The function call abs requires 1 argument." );
- }
- }
-
- public static Object ceil( Context actualContext, Scriptable actualObject, Object[] ArgList,
- Function FunctionContext ) {
- if ( ArgList.length == 1 ) {
- try {
- if ( isNull( ArgList[ 0 ] ) ) {
- return Double.NaN;
- } else if ( isUndefined( ArgList[ 0 ] ) ) {
- return Context.getUndefinedValue();
- } else {
- return Math.ceil( Context.toNumber( ArgList[ 0 ] ) );
- }
- } catch ( Exception e ) {
- return null;
- }
- } else {
- throw Context.reportRuntimeError( "The function call ceil requires 1 argument." );
- }
- }
-
- public static Object floor( Context actualContext, Scriptable actualObject, Object[] ArgList,
- Function FunctionContext ) {
- if ( ArgList.length == 1 ) {
- try {
- if ( isNull( ArgList[ 0 ] ) ) {
- return new Double( Double.NaN );
- } else if ( isUndefined( ArgList[ 0 ] ) ) {
- return Context.getUndefinedValue();
- } else {
- return new Double( Math.floor( Context.toNumber( ArgList[ 0 ] ) ) );
- }
- } catch ( Exception e ) {
- return null;
- // throw Context.reportRuntimeError(e.toString());
- }
- } else {
- throw Context.reportRuntimeError( "The function call floor requires 1 argument." );
- }
- }
-
- public static Object getDayNumber( Context actualContext, Scriptable actualObject, Object[] ArgList,
- Function FunctionContext ) {
- if ( ArgList.length == 2 ) {
- try {
- if ( isNull( ArgList[ 0 ] ) ) {
- return new Double( Double.NaN );
- } else if ( isUndefined( ArgList[ 0 ] ) ) {
- return Context.getUndefinedValue();
- } else {
- java.util.Date dIn = (java.util.Date) Context.jsToJava( ArgList[ 0 ], java.util.Date.class );
- String strType = Context.toString( ArgList[ 1 ] ).toLowerCase();
- Calendar startDate = Calendar.getInstance();
- startDate.setTime( dIn );
- if ( strType.equals( "y" ) ) {
- return new Double( startDate.get( Calendar.DAY_OF_YEAR ) );
- } else if ( strType.equals( "m" ) ) {
- return new Double( startDate.get( Calendar.DAY_OF_MONTH ) );
- } else if ( strType.equals( "w" ) ) {
- return new Double( startDate.get( Calendar.DAY_OF_WEEK ) );
- } else if ( strType.equals( "wm" ) ) {
- return new Double( startDate.get( Calendar.DAY_OF_WEEK_IN_MONTH ) );
- }
- return new Double( startDate.get( Calendar.DAY_OF_YEAR ) );
- }
- } catch ( Exception e ) {
- return null;
- // throw Context.reportRuntimeError(e.toString());
- }
- } else {
- throw Context.reportRuntimeError( "The function call getDayNumber requires 2 arguments." );
- }
- }
-
- public static Object isWorkingDay( Context actualContext, Scriptable actualObject, Object[] ArgList,
- Function FunctionContext ) {
- if ( ArgList.length == 1 ) {
- try {
- if ( isNull( ArgList[ 0 ] ) ) {
- return null;
- } else if ( isUndefined( ArgList[ 0 ] ) ) {
- return Context.getUndefinedValue();
- } else {
- java.util.Date dIn = (java.util.Date) Context.jsToJava( ArgList[ 0 ], java.util.Date.class );
- Calendar startDate = Calendar.getInstance();
- startDate.setTime( dIn );
- if ( startDate.get( Calendar.DAY_OF_WEEK ) != Calendar.SATURDAY
- && startDate.get( Calendar.DAY_OF_WEEK ) != Calendar.SUNDAY ) {
- return Boolean.TRUE;
- }
- return Boolean.FALSE;
- }
- } catch ( Exception e ) {
- return null;
- }
- } else {
- throw Context.reportRuntimeError( "The function call isWorkingDay requires 1 argument." );
- }
- }
-
- @SuppressWarnings( "unused" )
- public static Object fireToDB( Context actualContext, Scriptable actualObject, Object[] ArgList,
- Function FunctionContext ) {
-
- Object oRC = new Object();
- if ( ArgList.length == 2 ) {
- try {
- Object scmO = actualObject.get( "_transform_", actualObject );
- ScriptValuesMod scm = (ScriptValuesMod) Context.jsToJava( scmO, ScriptValuesMod.class );
- String strDBName = Context.toString( ArgList[ 0 ] );
- String strSQL = Context.toString( ArgList[ 1 ] );
- DatabaseMeta ci = DatabaseMeta.findDatabase( scm.getPipelineMeta().getDatabases(), strDBName );
- if ( ci == null ) {
- throw Context.reportRuntimeError( "Database connection not found: " + strDBName );
- }
- ci.shareVariablesWith( scm );
-
- Database db = new Database( scm, ci );
- db.setQueryLimit( 0 );
- try {
- db.connect( scm.getPartitionID() );
-
- ResultSet rs = db.openQuery( strSQL );
- ResultSetMetaData resultSetMetaData = rs.getMetaData();
- int columnCount = resultSetMetaData.getColumnCount();
- if ( rs != null ) {
- List<Object[]> list = new ArrayList<Object[]>();
- while ( rs.next() ) {
- Object[] objRow = new Object[ columnCount ];
- for ( int i = 0; i < columnCount; i++ ) {
- objRow[ i ] = rs.getObject( i + 1 );
- }
- list.add( objRow );
- }
- Object[][] resultArr = new Object[ list.size() ][];
- list.toArray( resultArr );
- db.disconnect();
- return resultArr;
- }
- } catch ( Exception er ) {
- throw Context.reportRuntimeError( er.toString() );
- }
- } catch ( Exception e ) {
- throw Context.reportRuntimeError( e.toString() );
- }
- } else {
- throw Context.reportRuntimeError( "The function call fireToDB requires 2 arguments." );
- }
- return oRC;
- }
-
- public static Object dateDiff( Context actualContext, Scriptable actualObject, Object[] ArgList,
- Function FunctionContext ) {
- if ( ArgList.length == 3 ) {
- try {
- if ( isNull( ArgList, new int[] { 0, 1, 2 } ) ) {
- return new Double( Double.NaN );
- } else if ( isUndefined( ArgList, new int[] { 0, 1, 2 } ) ) {
- return Context.getUndefinedValue();
- } else {
- java.util.Date dIn1 = (java.util.Date) Context.jsToJava( ArgList[ 0 ], java.util.Date.class );
- java.util.Date dIn2 = (java.util.Date) Context.jsToJava( ArgList[ 1 ], java.util.Date.class );
- String strType = Context.toString( ArgList[ 2 ] ).toLowerCase();
- int iRC = 0;
-
- Calendar startDate = Calendar.getInstance();
- Calendar endDate = Calendar.getInstance();
- startDate.setTime( dIn1 );
- endDate.setTime( dIn2 );
-
- /*
- * Changed by: Ingo Klose, SHS VIVEON AG, Date: 27.04.2007
- *
- * Calculating time differences using getTimeInMillis() leads to false results when crossing Daylight
- * Savingstime borders. In order to get correct results the time zone offsets have to be added.
- *
- * Fix: 1. calculate correct milli seconds for start and end date 2. replace endDate.getTimeInMillis() with
- * endL and startDate.getTimeInMillis() with startL
- */
- long endL = endDate.getTimeInMillis() + endDate.getTimeZone().getOffset( endDate.getTimeInMillis() );
- long startL =
- startDate.getTimeInMillis() + startDate.getTimeZone().getOffset( startDate.getTimeInMillis() );
-
- if ( strType.equals( "y" ) ) {
- return new Double( endDate.get( Calendar.YEAR ) - startDate.get( Calendar.YEAR ) );
- } else if ( strType.equals( "m" ) ) {
- int iMonthsToAdd = ( endDate.get( Calendar.YEAR ) - startDate.get( Calendar.YEAR ) ) * 12;
- return new Double( ( endDate.get( Calendar.MONTH ) - startDate.get( Calendar.MONTH ) ) + iMonthsToAdd );
- } else if ( strType.equals( "d" ) ) {
- return new Double( ( ( endL - startL ) / 86400000 ) );
- } else if ( strType.equals( "wd" ) ) {
- int iOffset = -1;
- if ( endDate.before( startDate ) ) {
- iOffset = 1;
- }
- while ( ( iOffset == 1 && endL < startL ) || ( iOffset == -1 && endL > startL ) ) {
- int day = endDate.get( Calendar.DAY_OF_WEEK );
- if ( ( day != Calendar.SATURDAY ) && ( day != Calendar.SUNDAY ) ) {
- iRC++;
- }
- endDate.add( Calendar.DATE, iOffset );
- endL = endDate.getTimeInMillis() + endDate.getTimeZone().getOffset( endDate.getTimeInMillis() );
- }
- return new Double( iRC );
- } else if ( strType.equals( "w" ) ) {
- int iDays = (int) ( ( endL - startL ) / 86400000 );
- return new Double( iDays / 7 );
- } else if ( strType.equals( "ss" ) ) {
- return new Double( ( ( endL - startL ) / 1000 ) );
- } else if ( strType.equals( "mi" ) ) {
- return new Double( ( ( endL - startL ) / 60000 ) );
- } else if ( strType.equals( "hh" ) ) {
- return new Double( ( ( endL - startL ) / 3600000 ) );
- } else {
- return new Double( ( ( endL - startL ) / 86400000 ) );
- }
- /*
- * End Bugfix
- */
- }
- } catch ( Exception e ) {
- throw Context.reportRuntimeError( e.toString() );
- }
- } else {
- throw Context.reportRuntimeError( "The function call dateDiff requires 3 arguments." );
- }
- }
-
- public static Object getNextWorkingDay( Context actualContext, Scriptable actualObject, Object[] ArgList,
- Function FunctionContext ) {
- // (Date dIn){
- if ( ArgList.length == 1 ) {
- try {
- if ( isNull( ArgList[ 0 ] ) ) {
- return null;
- } else if ( isUndefined( ArgList[ 0 ] ) ) {
- return Context.getUndefinedValue();
- }
- java.util.Date dIn = (java.util.Date) Context.jsToJava( ArgList[ 0 ], java.util.Date.class );
- Calendar startDate = Calendar.getInstance();
- startDate.setTime( dIn );
- startDate.add( Calendar.DATE, 1 );
- while ( startDate.get( Calendar.DAY_OF_WEEK ) == Calendar.SATURDAY
- || startDate.get( Calendar.DAY_OF_WEEK ) == Calendar.SUNDAY ) {
- startDate.add( Calendar.DATE, 1 );
- }
- return startDate.getTime();
- } catch ( Exception e ) {
- throw Context.reportRuntimeError( e.toString() );
- }
- } else {
- throw Context.reportRuntimeError( "The function call getNextWorkingDay requires 1 argument." );
- }
- }
-
- public static Object dateAdd( Context actualContext, Scriptable actualObject, Object[] ArgList,
- Function FunctionContext ) {
- if ( ArgList.length == 3 ) {
- try {
- if ( isNull( ArgList, new int[] { 0, 1, 2 } ) ) {
- return null;
- } else if ( isUndefined( ArgList, new int[] { 0, 1, 2 } ) ) {
- return Context.getUndefinedValue();
- }
- java.util.Date dIn = (java.util.Date) Context.jsToJava( ArgList[ 0 ], java.util.Date.class );
- String strType = Context.toString( ArgList[ 1 ] ).toLowerCase();
- int iValue = (int) Context.toNumber( ArgList[ 2 ] );
- Calendar cal = Calendar.getInstance();
- cal.setTime( dIn );
- if ( strType.equals( "y" ) ) {
- cal.add( Calendar.YEAR, iValue );
- } else if ( strType.equals( "m" ) ) {
- cal.add( Calendar.MONTH, iValue );
- } else if ( strType.equals( "d" ) ) {
- cal.add( Calendar.DATE, iValue );
- } else if ( strType.equals( "w" ) ) {
- cal.add( Calendar.WEEK_OF_YEAR, iValue );
- } else if ( strType.equals( "wd" ) ) {
- int iOffset = 0;
- while ( iOffset < iValue ) {
- cal.add( Calendar.DATE, 1 );
- int day = cal.get( Calendar.DAY_OF_WEEK );
- if ( ( day != Calendar.SATURDAY ) && ( day != Calendar.SUNDAY ) ) {
- iOffset++;
- }
- }
- } else if ( strType.equals( "hh" ) ) {
- cal.add( Calendar.HOUR, iValue );
- } else if ( strType.equals( "mi" ) ) {
- cal.add( Calendar.MINUTE, iValue );
- } else if ( strType.equals( "ss" ) ) {
- cal.add( Calendar.SECOND, iValue );
- }
- return cal.getTime();
- } catch ( Exception e ) {
- throw Context.reportRuntimeError( e.toString() );
- }
- } else {
- throw Context.reportRuntimeError( "The function call dateAdd requires 3 arguments." );
- }
- }
-
- public static String fillString( Context actualContext, Scriptable actualObject, Object[] ArgList,
- Function FunctionContext ) {
- if ( ArgList.length == 2 ) {
- try {
- if ( isNull( ArgList, new int[] { 0, 1 } ) ) {
- return null;
- } else if ( isUndefined( ArgList, new int[] { 0, 1 } ) ) {
- return (String) Context.getUndefinedValue();
- }
- String fillChar = Context.toString( ArgList[ 0 ] );
- int count = (int) Context.toNumber( ArgList[ 1 ] );
- if ( fillChar.length() != 1 ) {
- throw Context.reportRuntimeError( "Please provide a valid Char to the fillString" );
- } else {
- char[] chars = new char[ count ];
- while ( count > 0 ) {
- chars[ --count ] = fillChar.charAt( 0 );
- }
- return new String( chars );
- }
- } catch ( Exception e ) {
- throw Context.reportRuntimeError( e.toString() );
- }
- } else {
- throw Context.reportRuntimeError( "The function call fillString requires 2 arguments." );
- }
- }
-
- public static Object isCodepage( Context actualContext, Scriptable actualObject, Object[] ArgList,
- Function FunctionContext ) {
- boolean bRC = false;
- if ( ArgList.length == 2 ) {
- try {
- if ( isNull( ArgList, new int[] { 0, 1 } ) ) {
- return null;
- } else if ( isUndefined( ArgList, new int[] { 0, 1 } ) ) {
- return Context.getUndefinedValue();
- }
- String strValueToCheck = Context.toString( ArgList[ 0 ] );
- String strCodePage = Context.toString( ArgList[ 1 ] );
- byte[] bytearray = strValueToCheck.getBytes();
- CharsetDecoder d = Charset.forName( strCodePage ).newDecoder();
- CharBuffer r = d.decode( ByteBuffer.wrap( bytearray ) );
- r.toString();
- bRC = true;
- } catch ( Exception e ) {
- bRC = false;
- }
- } else {
- throw Context.reportRuntimeError( "The function call isCodepage requires 2 arguments." );
- }
- return Boolean.valueOf( bRC );
- }
-
- public static String ltrim( Context actualContext, Scriptable actualObject, Object[] ArgList,
- Function FunctionContext ) {
- try {
- if ( ArgList.length == 1 ) {
- if ( isNull( ArgList[ 0 ] ) ) {
- return null;
- } else if ( isUndefined( ArgList[ 0 ] ) ) {
- return (String) Context.getUndefinedValue();
- }
- String strValueToTrim = Context.toString( ArgList[ 0 ] );
- return strValueToTrim.replaceAll( "^\\s+", "" );
- } else {
- throw Context.reportRuntimeError( "The function call ltrim requires 1 argument." );
- }
- } catch ( Exception e ) {
- throw Context.reportRuntimeError( "The function call ltrim is not valid : " + e.getMessage() );
- }
- }
-
- public static String rtrim( Context actualContext, Scriptable actualObject, Object[] ArgList,
- Function FunctionContext ) {
- try {
- if ( ArgList.length == 1 ) {
- if ( isNull( ArgList[ 0 ] ) ) {
- return null;
- } else if ( isUndefined( ArgList[ 0 ] ) ) {
- return (String) Context.getUndefinedValue();
- }
- String strValueToTrim = Context.toString( ArgList[ 0 ] );
- return strValueToTrim.replaceAll( "\\s+$", "" );
- } else {
- throw Context.reportRuntimeError( "The function call rtrim requires 1 argument." );
- }
- } catch ( Exception e ) {
- throw Context.reportRuntimeError( "The function call rtrim is not valid : " + e.getMessage() );
- }
- }
-
- public static String lpad( Context actualContext, Scriptable actualObject, Object[] ArgList,
- Function FunctionContext ) {
-
- // (String valueToPad, String filler, int size) {
- try {
- if ( ArgList.length == 3 ) {
- if ( isNull( ArgList, new int[] { 0, 1, 2 } ) ) {
- return null;
- } else if ( isUndefined( ArgList, new int[] { 0, 1, 2 } ) ) {
- return (String) Context.getUndefinedValue();
- }
- String valueToPad = Context.toString( ArgList[ 0 ] );
- String filler = Context.toString( ArgList[ 1 ] );
- int size = (int) Context.toNumber( ArgList[ 2 ] );
-
- while ( valueToPad.length() < size ) {
- valueToPad = filler + valueToPad;
- }
- return valueToPad;
- }
- } catch ( Exception e ) {
- throw Context.reportRuntimeError( "The function call lpad requires 3 arguments." );
- }
- return null;
- }
-
- public static String rpad( Context actualContext, Scriptable actualObject, Object[] ArgList,
- Function FunctionContext ) {
- try {
- if ( ArgList.length == 3 ) {
- if ( isNull( ArgList, new int[] { 0, 1, 2 } ) ) {
- return null;
- } else if ( isUndefined( ArgList, new int[] { 0, 1, 2 } ) ) {
- return (String) Context.getUndefinedValue();
- }
- String valueToPad = Context.toString( ArgList[ 0 ] );
- String filler = Context.toString( ArgList[ 1 ] );
- int size = (int) Context.toNumber( ArgList[ 2 ] );
-
- while ( valueToPad.length() < size ) {
- valueToPad = valueToPad + filler;
- }
- return valueToPad;
- }
- } catch ( Exception e ) {
- throw Context.reportRuntimeError( "The function call rpad requires 3 arguments." );
- }
- return null;
- }
-
- public static Object year( Context actualContext, Scriptable actualObject, Object[] ArgList,
- Function FunctionContext ) {
- try {
- if ( ArgList.length == 1 ) {
- if ( isNull( ArgList[ 0 ] ) ) {
- return new Double( Double.NaN );
- } else if ( isUndefined( ArgList[ 0 ] ) ) {
- return Context.getUndefinedValue();
- }
- java.util.Date dArg1 = (java.util.Date) Context.jsToJava( ArgList[ 0 ], java.util.Date.class );
- Calendar cal = Calendar.getInstance();
- cal.setTime( dArg1 );
- return new Double( cal.get( Calendar.YEAR ) );
- } else {
- throw Context.reportRuntimeError( "The function call year requires 1 argument." );
- }
- } catch ( Exception e ) {
- throw Context.reportRuntimeError( e.toString() );
- }
- }
-
- public static Object month( Context actualContext, Scriptable actualObject, Object[] ArgList,
- Function FunctionContext ) {
- try {
- if ( ArgList.length == 1 ) {
- if ( isNull( ArgList[ 0 ] ) ) {
- return new Double( Double.NaN );
- } else if ( isUndefined( ArgList[ 0 ] ) ) {
- return Context.getUndefinedValue();
- }
- java.util.Date dArg1 = (java.util.Date) Context.jsToJava( ArgList[ 0 ], java.util.Date.class );
- Calendar cal = Calendar.getInstance();
- cal.setTime( dArg1 );
- return new Double( cal.get( Calendar.MONTH ) );
- } else {
- throw Context.reportRuntimeError( "The function call month requires 1 argument." );
- }
- } catch ( Exception e ) {
- throw Context.reportRuntimeError( e.toString() );
- }
-
- }
-
- public static Object quarter( Context actualContext, Scriptable actualObject, Object[] ArgList,
- Function FunctionContext ) {
- try {
- if ( ArgList.length == 1 ) {
- if ( isNull( ArgList[ 0 ] ) ) {
- return new Double( Double.NaN );
- } else if ( isUndefined( ArgList[ 0 ] ) ) {
- return Context.getUndefinedValue();
- }
- java.util.Date dArg1 = (java.util.Date) Context.jsToJava( ArgList[ 0 ], java.util.Date.class );
- Calendar cal = Calendar.getInstance();
- cal.setTime( dArg1 );
-
- // Patch by Ingo Klose: calendar months start at 0 in java.
- int iMonth = cal.get( Calendar.MONTH );
- if ( iMonth <= 2 ) {
- return new Double( 1 );
- } else if ( iMonth <= 5 ) {
- return new Double( 2 );
- } else if ( iMonth <= 8 ) {
- return new Double( 3 );
- } else {
- return new Double( 4 );
- }
- } else {
- throw Context.reportRuntimeError( "The function call quarter requires 1 argument." );
- }
- } catch ( Exception e ) {
- throw Context.reportRuntimeError( e.toString() );
- }
- }
-
- public static Object week( Context actualContext, Scriptable actualObject, Object[] ArgList,
- Function FunctionContext ) {
- try {
- if ( ArgList.length == 1 ) {
- if ( isNull( ArgList[ 0 ] ) ) {
- return new Double( Double.NaN );
- } else if ( isUndefined( ArgList[ 0 ] ) ) {
- return Context.getUndefinedValue();
- }
- java.util.Date dArg1 = (java.util.Date) Context.jsToJava( ArgList[ 0 ], java.util.Date.class );
- Calendar cal = Calendar.getInstance();
- cal.setTime( dArg1 );
- return new Double( cal.get( Calendar.WEEK_OF_YEAR ) );
- } else {
- throw Context.reportRuntimeError( "The function call week requires 1 argument." );
- }
- } catch ( Exception e ) {
- throw Context.reportRuntimeError( e.toString() );
- }
- }
-
- public static Object str2RegExp( Context actualContext, Scriptable actualObject, Object[] ArgList,
- Function FunctionContext ) {
- String[] strArr = null;
- if ( ArgList.length == 2 ) {
- try {
- if ( isNull( ArgList, new int[] { 0, 1 } ) ) {
- return null;
- } else if ( isUndefined( ArgList, new int[] { 0, 1 } ) ) {
- return Context.getUndefinedValue();
- }
- String strToMatch = Context.toString( ArgList[ 0 ] );
- Pattern p = Pattern.compile( Context.toString( ArgList[ 1 ] ) );
- Matcher m = p.matcher( strToMatch );
- if ( m.matches() && m.groupCount() > 0 ) {
- strArr = new String[ m.groupCount() ];
- for ( int i = 1; i <= m.groupCount(); i++ ) {
- strArr[ i - 1 ] = m.group( i );
- }
- }
- } catch ( Exception e ) {
- throw Context.reportRuntimeError( e.toString() );
- }
- } else {
- throw Context.reportRuntimeError( "The function call str2RegExp requires 2 arguments." );
- }
- return strArr;
- }
-
- public static void touch( Context actualContext, Scriptable actualObject, Object[] ArgList,
- Function FunctionContext ) {
- try {
- if ( ArgList.length == 1 && !isNull( ArgList[ 0 ] ) && !isUndefined( ArgList[ 0 ] ) ) {
- File file = new File( Context.toString( ArgList[ 0 ] ) );
- boolean success = file.createNewFile();
- if ( !success ) {
- file.setLastModified( System.currentTimeMillis() );
- }
- } else {
- throw Context.reportRuntimeError( "The function call touch requires 1 valid argument." );
- }
- } catch ( Exception e ) {
- throw Context.reportRuntimeError( e.toString() );
- }
- }
-
- public static Object fileExists( Context actualContext, Scriptable actualObject, Object[] ArgList,
- Function FunctionContext ) {
- try {
- if ( ArgList.length == 1 && !isNull( ArgList[ 0 ] ) && !isUndefined( ArgList[ 0 ] ) ) {
- if ( ArgList[ 0 ].equals( null ) ) {
- return null;
- }
- File file = new File( Context.toString( ArgList[ 0 ] ) );
- return Boolean.valueOf( file.isFile() );
- } else {
- throw Context.reportRuntimeError( "The function call fileExists requires 1 valid argument." );
- }
- } catch ( Exception e ) {
- throw Context.reportRuntimeError( e.toString() );
- }
- }
-
- public static Object str2date( Context actualContext, Scriptable actualObject, Object[] ArgList,
- Function FunctionContext ) {
- Object oRC = new Object();
- String sArg1 = "";
- String sArg2 = "";
- String sArg3 = "";
- String sArg4 = "";
- switch ( ArgList.length ) {
- case 0:
- throw Context.reportRuntimeError( "Please provide a valid string to the function call str2date." );
- case 1:
- try {
- if ( isNull( ArgList[ 0 ] ) ) {
- return null;
- } else if ( isUndefined( ArgList[ 0 ] ) ) {
- return Context.getUndefinedValue();
- }
- sArg1 = Context.toString( ArgList[ 0 ] );
- Format dfFormatter = new SimpleDateFormat();
- oRC = dfFormatter.parseObject( sArg1 );
- // if(Double.isNaN(sArg1)) throw Context.reportRuntimeError("The first Argument must be a Number.");
- // DecimalFormat formatter = new DecimalFormat();
- // sRC= formatter.format(sArg1);
- } catch ( Exception e ) {
- throw Context.reportRuntimeError( "Could not apply local format for " + sArg1 + " : " + e.getMessage() );
- }
- break;
- case 2:
- try {
- if ( isNull( ArgList, new int[] { 0, 1 } ) ) {
- return null;
- } else if ( isUndefined( ArgList, new int[] { 0, 1 } ) ) {
- return Context.getUndefinedValue();
- }
- sArg1 = Context.toString( ArgList[ 0 ] );
- sArg2 = Context.toString( ArgList[ 1 ] );
- Format dfFormatter = new SimpleDateFormat( sArg2 );
- oRC = dfFormatter.parseObject( sArg1 );
- } catch ( Exception e ) {
- throw Context.reportRuntimeError( "Could not apply the given format "
- + sArg2 + " on the string for " + sArg1 + " : " + e.getMessage() );
- }
- break;
- case 3:
- try {
- if ( isNull( ArgList, new int[] { 0, 1, 2 } ) ) {
- return null;
- } else if ( isUndefined( ArgList, new int[] { 0, 1, 2 } ) ) {
- return Context.getUndefinedValue();
- }
- sArg1 = Context.toString( ArgList[ 0 ] );
- Format dfFormatter;
- sArg2 = Context.toString( ArgList[ 1 ] );
- sArg3 = Context.toString( ArgList[ 2 ] );
- if ( sArg3.length() == 2 ) {
- Locale dfLocale = EnvUtil.createLocale( sArg3 );
- dfFormatter = new SimpleDateFormat( sArg2, dfLocale );
- oRC = dfFormatter.parseObject( sArg1 );
- } else {
- throw Context.reportRuntimeError( "Locale " + sArg3 + " is not 2 characters long." );
- }
- } catch ( Exception e ) {
- throw Context
- .reportRuntimeError( "Could not apply the local format for locale "
- + sArg3 + " with the given format " + sArg2 + " on the string for " + sArg1 + " : "
- + e.getMessage() );
- }
- break;
- case 4:
- try {
- if ( isNull( ArgList, new int[] { 0, 1, 2, 3 } ) ) {
- return null;
- } else if ( isUndefined( ArgList, new int[] { 0, 1, 2, 3 } ) ) {
- return Context.getUndefinedValue();
- }
- sArg1 = Context.toString( ArgList[ 0 ] );
- DateFormat dfFormatter;
- sArg2 = Context.toString( ArgList[ 1 ] );
- sArg3 = Context.toString( ArgList[ 2 ] );
- sArg4 = Context.toString( ArgList[ 3 ] );
-
- // If the timezone is not recognized, java will automatically
- // take GMT.
- TimeZone tz = TimeZone.getTimeZone( sArg4 );
-
- if ( sArg3.length() == 2 ) {
- Locale dfLocale = EnvUtil.createLocale( sArg3 );
- dfFormatter = new SimpleDateFormat( sArg2, dfLocale );
- dfFormatter.setTimeZone( tz );
- oRC = dfFormatter.parseObject( sArg1 );
- } else {
- throw Context.reportRuntimeError( "Locale " + sArg3 + " is not 2 characters long." );
- }
- } catch ( Exception e ) {
- throw Context
- .reportRuntimeError( "Could not apply the local format for locale "
- + sArg3 + " with the given format " + sArg2 + " on the string for " + sArg1 + " : "
- + e.getMessage() );
- }
- break;
- default:
- throw Context.reportRuntimeError( "The function call str2date requires 1, 2, 3, or 4 arguments." );
- }
- return oRC;
- }
-
- public static Object date2str( Context actualContext, Scriptable actualObject, Object[] ArgList,
- Function FunctionContext ) {
- Object oRC = new Object();
- switch ( ArgList.length ) {
- case 0:
- throw Context.reportRuntimeError( "Please provide a valid date to the function call date2str." );
- case 1:
- try {
- if ( isNull( ArgList ) ) {
- return null;
- } else if ( isUndefined( ArgList ) ) {
- return Context.getUndefinedValue();
- }
- java.util.Date dArg1 = (java.util.Date) Context.jsToJava( ArgList[ 0 ], java.util.Date.class );
- if ( dArg1.equals( null ) ) {
- return null;
- }
- Format dfFormatter = new SimpleDateFormat();
- oRC = dfFormatter.format( dArg1 );
- } catch ( Exception e ) {
- throw Context.reportRuntimeError( "Could not convert to local format." );
- }
- break;
- case 2:
- try {
- if ( isNull( ArgList, new int[] { 0, 1 } ) ) {
- return null;
- } else if ( isUndefined( ArgList, new int[] { 0, 1 } ) ) {
- return Context.getUndefinedValue();
- }
- java.util.Date dArg1 = (java.util.Date) Context.jsToJava( ArgList[ 0 ], java.util.Date.class );
- String sArg2 = Context.toString( ArgList[ 1 ] );
- Format dfFormatter = new SimpleDateFormat( sArg2 );
- oRC = dfFormatter.format( dArg1 );
- } catch ( Exception e ) {
- throw Context.reportRuntimeError( "Could not convert to the given format." );
- }
- break;
- case 3:
- try {
- if ( isNull( ArgList, new int[] { 0, 1, 2 } ) ) {
- return null;
- } else if ( isUndefined( ArgList, new int[] { 0, 1, 2 } ) ) {
- return Context.getUndefinedValue();
- }
- java.util.Date dArg1 = (java.util.Date) Context.jsToJava( ArgList[ 0 ], java.util.Date.class );
- DateFormat dfFormatter;
- String sArg2 = Context.toString( ArgList[ 1 ] );
- String sArg3 = Context.toString( ArgList[ 2 ] );
- if ( sArg3.length() == 2 ) {
- Locale dfLocale = EnvUtil.createLocale( sArg3.toLowerCase() );
- dfFormatter = new SimpleDateFormat( sArg2, dfLocale );
- oRC = dfFormatter.format( dArg1 );
- } else {
- throw Context.reportRuntimeError( "Locale is not 2 characters long." );
- }
- } catch ( Exception e ) {
- throw Context.reportRuntimeError( "Could not convert to the given local format." );
- }
- break;
- case 4:
- try {
- if ( isNull( ArgList, new int[] { 0, 1, 2, 3 } ) ) {
- return null;
- } else if ( isUndefined( ArgList, new int[] { 0, 1, 2, 3 } ) ) {
- return Context.getUndefinedValue();
- }
- java.util.Date dArg1 = (java.util.Date) Context.jsToJava( ArgList[ 0 ], java.util.Date.class );
- DateFormat dfFormatter;
- String sArg2 = Context.toString( ArgList[ 1 ] );
- String sArg3 = Context.toString( ArgList[ 2 ] );
- String sArg4 = Context.toString( ArgList[ 3 ] );
-
- // If the timezone is not recognized, java will automatically
- // take GMT.
- TimeZone tz = TimeZone.getTimeZone( sArg4 );
-
- if ( sArg3.length() == 2 ) {
- Locale dfLocale = EnvUtil.createLocale( sArg3.toLowerCase() );
- dfFormatter = new SimpleDateFormat( sArg2, dfLocale );
- dfFormatter.setTimeZone( tz );
- oRC = dfFormatter.format( dArg1 );
- } else {
- throw Context.reportRuntimeError( "Locale is not 2 characters long." );
- }
- } catch ( Exception e ) {
- throw Context.reportRuntimeError( "Could not convert to the given local format." );
- }
- break;
- default:
- throw Context.reportRuntimeError( "The function call date2str requires 1, 2, 3, or 4 arguments." );
- }
- return oRC;
- }
-
- public static Object isRegExp( Context actualContext, Scriptable actualObject, Object[] ArgList,
- Function FunctionContext ) {
-
- if ( ArgList.length >= 2 ) {
- if ( isNull( ArgList, new int[] { 0, 1 } ) ) {
- return null;
- } else if ( isUndefined( ArgList, new int[] { 0, 1 } ) ) {
- return Context.getUndefinedValue();
- }
- String strToMatch = Context.toString( ArgList[ 0 ] );
- for ( int i = 1; i < ArgList.length; i++ ) {
- Pattern p = Pattern.compile( Context.toString( ArgList[ i ] ) );
- Matcher m = p.matcher( strToMatch );
- if ( m.matches() ) {
- return new Double( i );
- }
- }
- }
- return new Double( -1 );
- }
-
- public static void sendMail( Context actualContext, Scriptable actualObject, Object[] ArgList,
- Function FunctionContext ) {
-
- boolean debug = false;
-
- // Arguments:
- // String smtp, String from, String recipients[ ], String subject, String message
- if ( ArgList.length == 5 ) {
-
- try {
- // Set the host smtp address
- Properties props = new Properties();
- props.put( "mail.smtp.host", ArgList[ 0 ] );
-
- // create some properties and get the default Session
- Session session = Session.getDefaultInstance( props, null );
- session.setDebug( debug );
-
- // create a message
- Message msg = new MimeMessage( session );
-
- // set the from and to address
- InternetAddress addressFrom = new InternetAddress( (String) ArgList[ 1 ] );
- msg.setFrom( addressFrom );
-
- // Get Recipients
- String[] strArrRecipients = ( (String) ArgList[ 2 ] ).split( "," );
-
- InternetAddress[] addressTo = new InternetAddress[ strArrRecipients.length ];
- for ( int i = 0; i < strArrRecipients.length; i++ ) {
- addressTo[ i ] = new InternetAddress( strArrRecipients[ i ] );
- }
- msg.setRecipients( Message.RecipientType.TO, addressTo );
-
- // Optional : You can also set your custom headers in the Email if you Want
- msg.addHeader( "MyHeaderName", "myHeaderValue" );
-
- // Setting the Subject and Content Type
- msg.setSubject( (String) ArgList[ 3 ] );
- msg.setContent( ArgList[ 4 ], "text/plain" );
- Transport.send( msg );
- } catch ( Exception e ) {
- throw Context.reportRuntimeError( "sendMail: " + e.toString() );
- }
- } else {
- throw Context.reportRuntimeError( "The function call sendMail requires 5 arguments." );
- }
- }
-
- public static String upper( Context actualContext, Scriptable actualObject, Object[] ArgList,
- Function FunctionContext ) {
- String sRC = "";
- if ( ArgList.length == 1 ) {
- try {
- if ( isNull( ArgList[ 0 ] ) ) {
- return null;
- } else if ( isUndefined( ArgList[ 0 ] ) ) {
- return (String) Context.getUndefinedValue();
- }
- sRC = Context.toString( ArgList[ 0 ] );
- sRC = sRC.toUpperCase();
- } catch ( Exception e ) {
- throw Context.reportRuntimeError( "The function call upper is not valid : " + e.getMessage() );
- }
- } else {
- throw Context.reportRuntimeError( "The function call upper requires 1 argument." );
- }
- return sRC;
- }
-
- public static String lower( Context actualContext, Scriptable actualObject, Object[] ArgList,
- Function FunctionContext ) {
- String sRC = "";
- if ( ArgList.length == 1 ) {
- try {
- if ( isNull( ArgList[ 0 ] ) ) {
- return null;
- } else if ( isUndefined( ArgList[ 0 ] ) ) {
- return (String) Context.getUndefinedValue();
- }
- sRC = Context.toString( ArgList[ 0 ] );
- sRC = sRC.toLowerCase();
- } catch ( Exception e ) {
- throw Context.reportRuntimeError( "The function call lower is not valid : " + e.getMessage() );
- }
- } else {
- throw Context.reportRuntimeError( "The function call lower requires 1 argument." );
- }
- return sRC;
- }
-
- // Converts the given Numeric to a JScript String
- public static String num2str( Context actualContext, Scriptable actualObject, Object[] ArgList,
- Function FunctionContext ) {
- String sRC = "";
- switch ( ArgList.length ) {
- case 0:
- throw Context.reportRuntimeError( "The function call num2str requires at least 1 argument." );
- case 1:
- try {
- if ( isNull( ArgList[ 0 ] ) ) {
- return null;
- } else if ( isUndefined( ArgList[ 0 ] ) ) {
- return (String) Context.getUndefinedValue();
- }
- double sArg1 = Context.toNumber( ArgList[ 0 ] );
- if ( Double.isNaN( sArg1 ) ) {
- throw Context.reportRuntimeError( "The first Argument must be a Number." );
- }
- DecimalFormat formatter = new DecimalFormat();
- sRC = formatter.format( sArg1 );
- } catch ( IllegalArgumentException e ) {
- throw Context.reportRuntimeError( "Could not apply the given format on the number : " + e.getMessage() );
- }
- break;
- case 2:
- try {
- if ( isNull( ArgList, new int[] { 0, 1 } ) ) {
- return null;
- } else if ( isUndefined( ArgList, new int[] { 0, 1 } ) ) {
- return (String) Context.getUndefinedValue();
- }
- double sArg1 = Context.toNumber( ArgList[ 0 ] );
- if ( Double.isNaN( sArg1 ) ) {
- throw Context.reportRuntimeError( "The first Argument must be a Number." );
- }
- String sArg2 = Context.toString( ArgList[ 1 ] );
- DecimalFormat formatter = new DecimalFormat( sArg2 );
- sRC = formatter.format( sArg1 );
- } catch ( IllegalArgumentException e ) {
- throw Context.reportRuntimeError( "Could not apply the given format on the number : " + e.getMessage() );
- }
- break;
- case 3:
- try {
- if ( isNull( ArgList, new int[] { 0, 1, 2 } ) ) {
- return null;
- } else if ( isUndefined( ArgList, new int[] { 0, 1, 2 } ) ) {
- return (String) Context.getUndefinedValue();
- }
- double sArg1 = Context.toNumber( ArgList[ 0 ] );
- if ( Double.isNaN( sArg1 ) ) {
- throw Context.reportRuntimeError( "The first Argument must be a Number." );
- }
- String sArg2 = Context.toString( ArgList[ 1 ] );
- String sArg3 = Context.toString( ArgList[ 2 ] );
- if ( sArg3.length() == 2 ) {
- DecimalFormatSymbols dfs = new DecimalFormatSymbols( EnvUtil.createLocale( sArg3.toLowerCase() ) );
- DecimalFormat formatter = new DecimalFormat( sArg2, dfs );
- sRC = formatter.format( sArg1 );
- }
- } catch ( Exception e ) {
- throw Context.reportRuntimeError( e.toString() );
- }
- break;
- default:
- throw Context.reportRuntimeError( "The function call num2str requires 1, 2, or 3 arguments." );
- }
-
- return sRC;
- }
-
- // Converts the given String to a JScript Numeric
- public static Object str2num( Context actualContext, Scriptable actualObject, Object[] ArgList,
- Function FunctionContext ) {
- double dRC = 0.00;
- switch ( ArgList.length ) {
- case 0:
- throw Context.reportRuntimeError( "The function call str2num requires at least 1 argument." );
- case 1:
- try {
- if ( isNull( ArgList[ 0 ] ) ) {
- return new Double( Double.NaN );
- } else if ( isUndefined( ArgList[ 0 ] ) ) {
- return Context.getUndefinedValue();
- }
- if ( ArgList[ 0 ].equals( null ) ) {
- return null;
- }
- String sArg1 = Context.toString( ArgList[ 0 ] );
- DecimalFormat formatter = new DecimalFormat();
- dRC = ( formatter.parse( Const.ltrim( sArg1 ) ) ).doubleValue();
- } catch ( Exception e ) {
- throw Context.reportRuntimeError( "Could not convert the given String : " + e.getMessage() );
- }
- break;
- case 2:
- try {
- if ( isNull( ArgList, new int[] { 0, 1 } ) ) {
- return new Double( Double.NaN );
- } else if ( isUndefined( ArgList, new int[] { 0, 1 } ) ) {
- return Context.getUndefinedValue();
- }
- String sArg1 = Context.toString( ArgList[ 0 ] );
- String sArg2 = Context.toString( ArgList[ 1 ] );
- if ( sArg1.equals( "null" ) || sArg2.equals( "null" ) ) {
- return null;
- }
- DecimalFormat formatter = new DecimalFormat( sArg2 );
- dRC = ( formatter.parse( sArg1 ) ).doubleValue();
- return new Double( dRC );
- } catch ( Exception e ) {
- throw Context.reportRuntimeError( "Could not convert the String with the given format :"
- + e.getMessage() );
- }
- // break;
- case 3:
- try {
- if ( isNull( ArgList, new int[] { 0, 1, 2 } ) ) {
- return new Double( Double.NaN );
- } else if ( isUndefined( ArgList, new int[] { 0, 1, 2 } ) ) {
- return Context.getUndefinedValue();
- }
- String sArg1 = Context.toString( ArgList[ 0 ] );
- String sArg2 = Context.toString( ArgList[ 1 ] );
- String sArg3 = Context.toString( ArgList[ 2 ] );
- if ( sArg3.length() == 2 ) {
- DecimalFormatSymbols dfs = new DecimalFormatSymbols( EnvUtil.createLocale( sArg3.toLowerCase() ) );
- DecimalFormat formatter = new DecimalFormat( sArg2, dfs );
- dRC = ( formatter.parse( sArg1 ) ).doubleValue();
- return new Double( dRC );
- }
- } catch ( Exception e ) {
- throw Context.reportRuntimeError( e.getMessage() );
- }
- break;
- default:
- throw Context.reportRuntimeError( "The function call str2num requires 1, 2, or 3 arguments." );
- }
- return new Double( dRC );
- }
-
- public static Object isNum( Context actualContext, Scriptable actualObject, Object[] ArgList,
- Function FunctionContext ) {
-
- if ( ArgList.length == 1 ) {
- try {
- if ( isNull( ArgList[ 0 ] ) ) {
- return null;
- } else if ( isUndefined( ArgList[ 0 ] ) ) {
- return Context.getUndefinedValue();
- }
- double sArg1 = Context.toNumber( ArgList[ 0 ] );
- if ( Double.isNaN( sArg1 ) ) {
- return Boolean.FALSE;
- } else {
- return Boolean.TRUE;
- }
- } catch ( Exception e ) {
- return Boolean.FALSE;
- }
- } else {
- throw Context.reportRuntimeError( "The function call isNum requires 1 argument." );
- }
- }
-
- public static Object isDate( Context actualContext, Scriptable actualObject, Object[] ArgList,
- Function FunctionContext ) {
-
- if ( ArgList.length == 1 ) {
- try {
- if ( isNull( ArgList[ 0 ] ) ) {
- return null;
- } else if ( isUndefined( ArgList[ 0 ] ) ) {
- return Context.getUndefinedValue();
- }
- /* java.util.Date d = (java.util.Date) */
- Context.jsToJava( ArgList[ 0 ], java.util.Date.class );
- return Boolean.TRUE;
- } catch ( Exception e ) {
- return Boolean.FALSE;
- }
- } else {
- throw Context.reportRuntimeError( "The function call isDate requires 1 argument." );
- }
- }
-
- public static Object decode( Context actualContext, Scriptable actualObject, Object[] ArgList,
- Function FunctionContext ) {
- try {
- if ( ArgList.length >= 2 ) {
- if ( isNull( ArgList, new int[] { 0, 1 } ) ) {
- return null;
- } else if ( isUndefined( ArgList, new int[] { 0, 1 } ) ) {
- return Context.getUndefinedValue();
- }
- Object objToCompare = ArgList[ 0 ];
- for ( int i = 1; i < ArgList.length - 1; i = i + 2 ) {
- if ( ArgList[ i ].equals( objToCompare ) ) {
- return ArgList[ i + 1 ];
- }
- }
- if ( ArgList.length % 2 == 0 ) {
- return ArgList[ ArgList.length - 1 ];
- } else {
- return objToCompare;
- }
- } else {
- throw Context.reportRuntimeError( "The function call decode requires more than 1 argument." );
- }
- } catch ( Exception e ) {
- throw Context.reportRuntimeError( "The function call decode is not valid : " + e.getMessage() );
- }
- }
-
- public static String replace( Context actualContext, Scriptable actualObject, Object[] ArgList,
- Function FunctionContext ) {
- try {
- if ( ArgList.length >= 2 && ( ArgList.length - 1 ) % 2 == 0 ) {
- if ( isNull( ArgList, new int[] { 0, 1 } ) ) {
- return null;
- } else if ( isUndefined( ArgList, new int[] { 0, 1 } ) ) {
- return (String) Context.getUndefinedValue();
- }
- String objForReplace = Context.toString( ArgList[ 0 ] );
- for ( int i = 1; i < ArgList.length - 1; i = i + 2 ) {
- objForReplace =
- objForReplace.replaceAll( Context.toString( ArgList[ i ] ), Context.toString( ArgList[ i + 1 ] ) );
- }
- return objForReplace;
- } else {
- throw Context.reportRuntimeError( "The function call replace is not valid (wrong number of arguments)" );
- }
- } catch ( Exception e ) {
- throw Context.reportRuntimeError( "Function call replace is not valid : " + e.getMessage() );
- }
- }
-
- // Implementation of the JS AlertBox
- public static String Alert( Context actualContext, Scriptable actualObject, Object[] ArgList,
- Function FunctionContext ) {
-
- HopUiInterface hopGui = HopUiFactory.getInstance();
- if ( ArgList.length == 1 && hopGui != null ) {
- String strMessage = Context.toString( ArgList[ 0 ] );
- boolean ok = hopGui.messageBox( strMessage, "Alert", true, Const.INFO );
- if ( !ok ) {
- throw new RuntimeException( "Alert dialog cancelled by user." );
- }
- }
-
- return "";
- }
-
- // Setting EnvironmentVar
- public static void setEnvironmentVar( Context actualContext, Scriptable actualObject, Object[] ArgList,
- Function FunctionContext ) {
- String sArg1 = "";
- String sArg2 = "";
- if ( ArgList.length == 2 ) {
- try {
- sArg1 = Context.toString( ArgList[ 0 ] );
- sArg2 = Context.toString( ArgList[ 1 ] );
- System.setProperty( sArg1, sArg2 );
- } catch ( Exception e ) {
- throw Context.reportRuntimeError( e.toString() );
- }
- } else {
- throw Context.reportRuntimeError( "The function call setEnvironmentVar requires 2 arguments." );
- }
- }
-
- // Returning EnvironmentVar
- public static String getEnvironmentVar( Context actualContext, Scriptable actualObject, Object[] ArgList,
- Function FunctionContext ) {
- String sRC = "";
- if ( ArgList.length == 1 ) {
- try {
-
- String sArg1 = Context.toString( ArgList[ 0 ] );
- // PDI-1276 Function getEnvironmentVar() does not work for user defined variables.
- // check if the system property exists, and if it does not, try getting a Hop var instead
- if ( System.getProperties().containsValue( sArg1 ) ) {
- sRC = System.getProperty( sArg1, "" );
- } else {
- Object scmo = actualObject.get( "_transform_", actualObject );
- Object scmO = Context.jsToJava( scmo, ITransform.class );
-
- if ( scmO instanceof ITransform ) {
- ITransform scm = (ITransform) Context.jsToJava( scmO, ITransform.class );
- sArg1 = Context.toString( ArgList[ 0 ] );
- sRC = scm.getVariable( sArg1, "" );
- } else {
- // running in test mode, return ""
- sRC = "";
- }
-
- }
-
- } catch ( Exception e ) {
- sRC = "";
- }
- } else {
- throw Context.reportRuntimeError( "The function call getEnvironmentVar requires 1 argument." );
- }
- return sRC;
- }
-
- public static String trim( Context actualContext, Scriptable actualObject, Object[] ArgList,
- Function FunctionContext ) {
- String sRC = "";
- if ( ArgList.length == 1 ) {
- try {
- if ( isNull( ArgList[ 0 ] ) ) {
- return null;
- } else if ( isUndefined( ArgList[ 0 ] ) ) {
- return (String) Context.getUndefinedValue();
- }
- sRC = Context.toString( ArgList[ 0 ] );
- sRC = Const.trim( sRC );
- } catch ( Exception e ) {
- throw Context.reportRuntimeError( "The function call trim is not valid : " + e.getMessage() );
- }
- } else {
- throw Context.reportRuntimeError( "The function call trim requires 1 argument." );
- }
- return sRC;
- }
-
- public static String substr( Context actualContext, Scriptable actualObject, Object[] ArgList,
- Function FunctionContext ) {
- String sRC = "";
-
- if ( ArgList.length == 2 ) {
- try {
- if ( isNull( ArgList[ 0 ] ) ) {
- return null;
- } else if ( isUndefined( ArgList[ 0 ] ) ) {
- return (String) Context.getUndefinedValue();
- }
- sRC = Context.toString( ArgList[ 0 ] );
- int from = (int) Math.round( Context.toNumber( ArgList[ 1 ] ) );
- sRC = sRC.substring( from );
- } catch ( Exception e ) {
- throw Context.reportRuntimeError( "The function call substr is not valid : " + e.getMessage() );
- }
- } else if ( ArgList.length == 3 ) {
- try {
- int to;
- int strLen;
-
- if ( isNull( ArgList[ 0 ] ) ) {
- return null;
- } else if ( isUndefined( ArgList[ 0 ] ) ) {
- return (String) Context.getUndefinedValue();
- }
- sRC = Context.toString( ArgList[ 0 ] );
- int from = (int) Math.round( Context.toNumber( ArgList[ 1 ] ) );
- int len = (int) Math.round( Context.toNumber( ArgList[ 2 ] ) );
-
- if ( from < 0 ) {
- throw Context.reportRuntimeError( "start smaller than 0" );
- }
- if ( len < 0 ) {
- len = 0; // Make it compatible with Javascript substr
- }
-
- to = from + len;
- strLen = sRC.length();
- if ( to > strLen ) {
- to = strLen;
- }
- sRC = sRC.substring( from, to );
- } catch ( Exception e ) {
- throw Context.reportRuntimeError( "The function call substr is not valid : " + e.getMessage() );
- }
- } else {
- throw Context.reportRuntimeError( "The function call substr requires 2 or 3 arguments." );
- }
- return sRC;
- }
-
- // Resolve an IP address
- public static String resolveIP( Context actualContext, Scriptable actualObject, Object[] ArgList,
- Function FunctionContext ) {
- String sRC;
- if ( ArgList.length == 2 ) {
- try {
- InetAddress address = InetAddress.getByName( Context.toString( ArgList[ 0 ] ) );
- if ( Context.toString( ArgList[ 1 ] ).equals( "IP" ) ) {
- sRC = address.getHostName();
- } else {
- sRC = address.getHostAddress();
- }
- if ( sRC.equals( Context.toString( ArgList[ 0 ] ) ) ) {
- sRC = "-";
- }
- } catch ( Exception e ) {
- sRC = "-";
- }
- } else {
- throw Context.reportRuntimeError( "The function call resolveIP requires 2 arguments." );
- }
-
- return sRC;
- }
-
- // Loading additional JS Files inside the JavaScriptCode
- public static void LoadScriptFile( Context actualContext, Scriptable actualObject, Object[] ArgList,
- Function FunctionContext ) {
- for ( int i = 0; i < ArgList.length; i++ ) { // don't worry about "undefined" arguments
- checkAndLoadJSFile( actualContext, actualObject, Context.toString( ArgList[ i ] ) );
- }
- }
-
- // Adding the ScriptsItemTab to the actual running Context
- public static void LoadScriptFromTab( Context actualContext, Scriptable actualObject, Object[] ArgList,
- Function FunctionContext ) {
- try {
- for ( int i = 0; i < ArgList.length; i++ ) { // don't worry about "undefined" arguments
- String strToLoad = Context.toString( ArgList[ i ] );
- String strScript = actualObject.get( strToLoad, actualObject ).toString();
- actualContext.evaluateString( actualObject, strScript, "_" + strToLoad + "_", 0, null );
- }
- } catch ( Exception e ) {
- // TODO: DON'T EAT EXCEPTION
- // System.out.println(e.toString());
- }
- }
-
- // Print
- public static void print( Context actualContext, Scriptable actualObject, Object[] ArgList,
- Function FunctionContext ) {
- for ( int i = 0; i < ArgList.length; i++ ) { // don't worry about "undefined" arguments
- java.lang.System.out.print( Context.toString( ArgList[ i ] ) );
- }
- }
-
- // Prints Line to the actual System.out
- public static void println( Context actualContext, Scriptable actualObject, Object[] ArgList,
- Function FunctionContext ) {
- print( actualContext, actualObject, ArgList, FunctionContext );
- java.lang.System.out.println();
- }
-
- // Returns the actual ClassName
- public String getClassName() {
- return "SciptValuesAddedFunctions";
- }
-
- // Evaluates the given ScriptFile
- private static void checkAndLoadJSFile( Context actualContext, Scriptable eval_scope, String fileName ) {
- Reader inStream = null;
- try {
- inStream = new InputStreamReader( HopVFS.getInputStream( fileName ) );
- actualContext.evaluateReader( eval_scope, inStream, fileName, 1, null );
- } catch ( FileNotFoundException Signal ) {
- Context.reportError( "Unable to open file \"" + fileName + "\" (reason: \"" + Signal.getMessage() + "\")" );
- } catch ( WrappedException Signal ) {
- Context.reportError( "WrappedException while evaluating file \""
- + fileName + "\" (reason: \"" + Signal.getMessage() + "\")" );
- } catch ( EvaluatorException Signal ) {
- Context.reportError( "EvaluatorException while evaluating file \""
- + fileName + "\" (reason: \"" + Signal.getMessage() + "\")" );
- } catch ( JavaScriptException Signal ) {
- Context.reportError( "JavaScriptException while evaluating file \""
- + fileName + "\" (reason: \"" + Signal.getMessage() + "\")" );
- } catch ( IOException Signal ) {
- Context.reportError( "Error while reading file \""
- + fileName + "\" (reason: \"" + Signal.getMessage() + "\")" );
- } catch ( HopFileException Signal ) {
- Context.reportError( "Error while reading file \""
- + fileName + "\" (reason: \"" + Signal.getMessage() + "\")" );
- } finally {
- try {
- if ( inStream != null ) {
- inStream.close();
- }
- } catch ( Exception Signal ) {
- // Ignore
- }
- }
- }
-
- public static void setVariable( Context actualContext, Scriptable actualObject, Object[] arguments,
- Function functionContext ) {
-
- if ( arguments.length != 3 ) {
- throw Context.reportRuntimeError( "The function call setVariable requires 3 arguments." );
- }
-
- Object transformObject = Context.jsToJava( actualObject.get( "_transform_", actualObject ), ITransform.class );
- if ( transformObject instanceof ITransform ) {
- ITransform transform = (ITransform) transformObject;
- Pipeline pipeline = transform.getPipeline();
- final String variableName = Context.toString( arguments[ 0 ] );
- final String variableValue = Context.toString( arguments[ 1 ] );
- final VariableScope variableScope = getVariableScope( Context.toString( arguments[ 2 ] ) );
-
- // Set variable in transform's scope so that it can be retrieved in the same transform using getVariable
- transform.setVariable( variableName, variableValue );
-
- switch ( variableScope ) {
- case PARENT:
- setParentScopeVariable( pipeline, variableName, variableValue );
- break;
- case GRAND_PARENT:
- setGrandParentScopeVariable( pipeline, variableName, variableValue );
- break;
- case ROOT:
- setRootScopeVariable( pipeline, variableName, variableValue );
- break;
- case SYSTEM:
- setSystemScopeVariable( pipeline, variableName, variableValue );
- break;
- }
- }
- }
-
- static void setRootScopeVariable( Pipeline pipeline, String variableName, String variableValue ) {
- pipeline.setVariable( variableName, variableValue );
-
- iVariables parentSpace = pipeline.getParentVariableSpace();
- while ( parentSpace != null ) {
- parentSpace.setVariable( variableName, variableValue );
- parentSpace = parentSpace.getParentVariableSpace();
- }
- }
-
- static void setSystemScopeVariable( Pipeline pipeline, final String variableName, final String variableValue ) {
- System.setProperty( variableName, variableValue );
-
- // Set also all the way to the root as else we will take
- // stale values
- setRootScopeVariable( pipeline, variableName, variableValue );
- }
-
- static void setParentScopeVariable( Pipeline pipeline, String variableName, String variableValue ) {
- pipeline.setVariable( variableName, variableValue );
-
- iVariables parentSpace = pipeline.getParentVariableSpace();
- if ( parentSpace != null ) {
- parentSpace.setVariable( variableName, variableValue );
- }
- }
-
- static void setGrandParentScopeVariable( Pipeline pipeline, String variableName, String variableValue ) {
- pipeline.setVariable( variableName, variableValue );
-
- iVariables parentSpace = pipeline.getParentVariableSpace();
- if ( parentSpace != null ) {
- parentSpace.setVariable( variableName, variableValue );
- iVariables grandParentSpace = parentSpace.getParentVariableSpace();
- if ( grandParentSpace != null ) {
- grandParentSpace.setVariable( variableName, variableValue );
- }
- }
- }
-
-
- static VariableScope getVariableScope( String codeOfScope ) {
- switch ( codeOfScope ) {
- case "s":
- return VariableScope.SYSTEM;
- case "r":
- return VariableScope.ROOT;
- case "p":
- return VariableScope.PARENT;
- case "g":
- return VariableScope.GRAND_PARENT;
- default:
- throw Context.reportRuntimeError( "The argument type of function call "
- + "setVariable should either be \"s\", \"r\", \"p\", or \"g\"." );
- }
- }
-
- // Returning EnvironmentVar
- public static String getVariable( Context actualContext, Scriptable actualObject, Object[] ArgList,
- Function FunctionContext ) {
- String sRC = "";
- String sArg1 = "";
- String sArg2 = "";
- if ( ArgList.length == 2 ) {
- try {
- Object scmo = actualObject.get( "_transform_", actualObject );
- Object scmO = Context.jsToJava( scmo, ITransform.class );
-
- if ( scmO instanceof ITransform ) {
- ITransform scm = (ITransform) Context.jsToJava( scmO, ITransform.class );
-
- sArg1 = Context.toString( ArgList[ 0 ] );
- sArg2 = Context.toString( ArgList[ 1 ] );
- return scm.getVariable( sArg1, sArg2 );
- } else {
- // running via the Test button in a dialog
- sArg2 = Context.toString( ArgList[ 1 ] );
- return sArg2;
- }
- } catch ( Exception e ) {
- sRC = "";
- }
- } else {
- throw Context.reportRuntimeError( "The function call getVariable requires 2 arguments." );
- }
- return sRC;
- }
-
- // Return the output row metadata
- public static IRowMeta getOutputRowMeta( Context actualContext, Scriptable actualObject,
- Object[] ArgList, Function FunctionContext ) {
- if ( ArgList.length == 0 ) {
- try {
- Object scmO = actualObject.get( "_transform_", actualObject );
- try {
- ScriptValuesMod scm = (ScriptValuesMod) Context.jsToJava( scmO, ScriptValuesMod.class );
- return scm.getOutputRowMeta();
- } catch ( Exception e ) {
- ScriptValuesModDummy scm = (ScriptValuesModDummy) Context.jsToJava( scmO, ScriptValuesModDummy.class );
- return scm.getOutputRowMeta();
- }
- } catch ( Exception e ) {
- throw Context.reportRuntimeError( "Unable to get the output row metadata because of an error: "
- + Const.CR + e.toString() );
- }
- } else {
- throw Context.reportRuntimeError( "The function call getOutputRowMeta doesn't require arguments." );
- }
- }
-
- // Return the input row metadata
- public static IRowMeta getInputRowMeta( Context actualContext, Scriptable actualObject,
- Object[] ArgList, Function FunctionContext ) {
- if ( ArgList.length == 0 ) {
- try {
- Object scmO = actualObject.get( "_transform_", actualObject );
- try {
- ScriptValuesMod scm = (ScriptValuesMod) Context.jsToJava( scmO, ScriptValuesMod.class );
- return scm.getInputRowMeta();
- } catch ( Exception e ) {
- ScriptValuesModDummy scm = (ScriptValuesModDummy) Context.jsToJava( scmO, ScriptValuesModDummy.class );
- return scm.getInputRowMeta();
- }
- } catch ( Exception e ) {
- throw Context.reportRuntimeError( "Unable to get the input row metadata because of an error: "
- + Const.CR + e.toString() );
- }
- } else {
- throw Context.reportRuntimeError( "The function call getInputRowMeta doesn't require arguments." );
- }
- }
-
- // Return the input row metadata
- public static Object[] createRowCopy( Context actualContext, Scriptable actualObject, Object[] ArgList,
- Function FunctionContext ) {
- if ( ArgList.length == 1 ) {
- try {
- int newSize = (int) Math.round( Context.toNumber( ArgList[ 0 ] ) );
-
- Object scmO = actualObject.get( "row", actualObject );
- Object[] row = (Object[]) Context.jsToJava( scmO, ( new Object[] {} ).getClass() );
-
- return RowDataUtil.createResizedCopy( row, newSize );
- } catch ( Exception e ) {
- throw Context.reportRuntimeError( "Unable to create a row copy: " + Const.CR + e.toString() );
- }
- } else {
- throw Context
- .reportRuntimeError( "The function call createRowCopy requires a single arguments : the new size of the row" );
- }
- }
-
- // put a row out to the next transforms...
- //
- public static void putRow( Context actualContext, Scriptable actualObject, Object[] ArgList,
- Function FunctionContext ) {
- if ( ArgList.length == 1 ) {
- try {
- Object[] newRow = (Object[]) Context.jsToJava( ArgList[ 0 ], ( new Object[] {} ).getClass() );
-
- Object scmO = actualObject.get( "_transform_", actualObject );
- try {
- ScriptValuesMod transform = (ScriptValuesMod) Context.jsToJava( scmO, ScriptValuesMod.class );
- transform.putRow( transform.getOutputRowMeta(), newRow );
- } catch ( Exception e ) {
- ScriptValuesModDummy transform = (ScriptValuesModDummy) Context.jsToJava( scmO, ScriptValuesModDummy.class );
- transform.putRow( transform.getOutputRowMeta(), newRow );
- }
-
- } catch ( Exception e ) {
- throw Context.reportRuntimeError( "Unable to pass the new row to the next transform(s) because of an error: "
- + Const.CR + e.toString() );
- }
- } else {
- throw Context
- .reportRuntimeError( "The function call putRow requires 1 argument : the output row data (Object[])" );
- }
- }
-
- public static void deleteFile( Context actualContext, Scriptable actualObject, Object[] ArgList,
- Function FunctionContext ) {
-
- try {
- if ( ArgList.length == 1 && !isNull( ArgList[ 0 ] ) && !isUndefined( ArgList[ 0 ] ) ) {
- // Object act = actualObject.get("_transform_", actualObject);
- // ScriptValuesMod act = (ScriptValuesMod)Context.toType(scm_delete, ScriptValuesMod.class);
-
- FileObject fileObject = null;
-
- try {
- fileObject = HopVFS.getFileObject( Context.toString( ArgList[ 0 ] ) );
- if ( fileObject.exists() ) {
- if ( fileObject.getType() == FileType.FILE ) {
- if ( !fileObject.delete() ) {
- Context.reportRuntimeError( "We can not delete file [" + Context.toString( ArgList[ 0 ] ) + "]!" );
- }
- }
-
- } else {
- Context.reportRuntimeError( "file [" + Context.toString( ArgList[ 0 ] ) + "] can not be found!" );
- }
- } catch ( IOException e ) {
- throw Context.reportRuntimeError( "The function call deleteFile is not valid." );
- } finally {
- if ( fileObject != null ) {
- try {
- fileObject.close();
- } catch ( Exception e ) {
- // Ignore errors
- }
- }
- }
-
- } else {
- throw Context.reportRuntimeError( "The function call deleteFile is not valid." );
- }
- } catch ( Exception e ) {
- throw Context.reportRuntimeError( e.toString() );
- }
- }
-
- public static void createFolder( Context actualContext, Scriptable actualObject, Object[] ArgList,
- Function FunctionContext ) {
-
- try {
- if ( ArgList.length == 1 && !isNull( ArgList[ 0 ] ) && !isUndefined( ArgList[ 0 ] ) ) {
- FileObject fileObject = null;
-
- try {
- fileObject = HopVFS.getFileObject( Context.toString( ArgList[ 0 ] ) );
- if ( !fileObject.exists() ) {
- fileObject.createFolder();
- } else {
- Context.reportRuntimeError( "folder [" + Context.toString( ArgList[ 0 ] ) + "] already exist!" );
- }
- } catch ( IOException e ) {
- throw Context.reportRuntimeError( "The function call createFolder is not valid." );
- } finally {
- if ( fileObject != null ) {
- try {
- fileObject.close();
- } catch ( Exception e ) {
- // Ignore errors
- }
- }
- }
-
- } else {
- throw Context.reportRuntimeError( "The function call createFolder is not valid." );
- }
- } catch ( Exception e ) {
- throw Context.reportRuntimeError( e.toString() );
- }
- }
-
- public static void copyFile( Context actualContext, Scriptable actualObject, Object[] ArgList,
- Function FunctionContext ) {
-
- try {
- if ( ArgList.length == 3
- && !isNull( ArgList[ 0 ] ) && !isNull( ArgList[ 1 ] ) && !isUndefined( ArgList[ 0 ] )
- && !isUndefined( ArgList[ 1 ] ) ) {
- FileObject fileSource = null, fileDestination = null;
-
- try {
- // Source file to copy
- fileSource = HopVFS.getFileObject( Context.toString( ArgList[ 0 ] ) );
- // Destination filename
- fileDestination = HopVFS.getFileObject( Context.toString( ArgList[ 1 ] ) );
- if ( fileSource.exists() ) {
- // Source file exists...
- if ( fileSource.getType() == FileType.FILE ) {
- // Great..source is a file ...
- boolean overwrite = false;
- if ( !ArgList[ 1 ].equals( null ) ) {
- overwrite = Context.toBoolean( ArgList[ 2 ] );
- }
- boolean destinationExists = fileDestination.exists();
- // Let's copy the file...
- if ( ( destinationExists && overwrite ) || !destinationExists ) {
- FileUtil.copyContent( fileSource, fileDestination );
- }
-
- }
- } else {
- Context.reportRuntimeError( "file to copy [" + Context.toString( ArgList[ 0 ] ) + "] can not be found!" );
- }
- } catch ( IOException e ) {
- throw Context.reportRuntimeError( "The function call copyFile throw an error : " + e.toString() );
- } finally {
- if ( fileSource != null ) {
- try {
- fileSource.close();
- } catch ( Exception e ) {
- // Ignore errors
- }
- }
- if ( fileDestination != null ) {
- try {
- fileDestination.close();
- } catch ( Exception e ) {
- // Ignore errors
- }
- }
- }
-
- } else {
- throw Context.reportRuntimeError( "The function call copyFileis not valid." );
- }
- } catch ( Exception e ) {
- throw Context.reportRuntimeError( e.toString() );
- }
- }
-
- public static double getFileSize( Context actualContext, Scriptable actualObject, Object[] ArgList,
- Function FunctionContext ) {
- try {
- if ( ArgList.length == 1 && !isNull( ArgList[ 0 ] ) && !isUndefined( ArgList[ 0 ] ) ) {
- if ( ArgList[ 0 ].equals( null ) ) {
- return 0;
- }
- FileObject file = null;
-
- try {
- // Source file
- file = HopVFS.getFileObject( Context.toString( ArgList[ 0 ] ) );
- long filesize = 0;
- if ( file.exists() ) {
- if ( file.getType().equals( FileType.FILE ) ) {
- filesize = file.getContent().getSize();
- } else {
- Context.reportRuntimeError( "[" + Context.toString( ArgList[ 0 ] ) + "] is not a file!" );
- }
- } else {
- Context.reportRuntimeError( "file [" + Context.toString( ArgList[ 0 ] ) + "] can not be found!" );
- }
- return filesize;
- } catch ( IOException e ) {
- throw Context.reportRuntimeError( "The function call getFileSize throw an error : " + e.toString() );
- } finally {
- if ( file != null ) {
- try {
- file.close();
- } catch ( Exception e ) {
- // Ignore close errors
- }
- }
- }
-
- } else {
- throw Context.reportRuntimeError( "The function call getFileSize is not valid." );
- }
- } catch ( Exception e ) {
- throw Context.reportRuntimeError( e.toString() );
- }
- }
-
- public static boolean isFile( Context actualContext, Scriptable actualObject, Object[] ArgList,
- Function FunctionContext ) {
- try {
- if ( ArgList.length == 1 && !isNull( ArgList[ 0 ] ) && !isUndefined( ArgList[ 0 ] ) ) {
- if ( ArgList[ 0 ].equals( null ) ) {
- return false;
- }
- FileObject file = null;
-
- try {
- // Source file
- file = HopVFS.getFileObject( Context.toString( ArgList[ 0 ] ) );
- boolean isafile = false;
- if ( file.exists() ) {
- if ( file.getType().equals( FileType.FILE ) ) {
- isafile = true;
- } else {
- Context.reportRuntimeError( "[" + Context.toString( ArgList[ 0 ] ) + "] is not a file!" );
- }
- } else {
- Context.reportRuntimeError( "file [" + Context.toString( ArgList[ 0 ] ) + "] can not be found!" );
- }
- return isafile;
- } catch ( IOException e ) {
- throw Context.reportRuntimeError( "The function call is File throw an error : " + e.toString() );
- } finally {
- if ( file != null ) {
- try {
- file.close();
- } catch ( Exception e ) {
- // Ignore errors
- }
- }
- }
-
- } else {
- throw Context.reportRuntimeError( "The function call isFile is not valid." );
- }
- } catch ( Exception e ) {
- throw Context.reportRuntimeError( e.toString() );
- }
- }
-
- public static boolean isFolder( Context actualContext, Scriptable actualObject, Object[] ArgList,
- Function FunctionContext ) {
- try {
- if ( ArgList.length == 1 && !isNull( ArgList[ 0 ] ) && !isUndefined( ArgList[ 0 ] ) ) {
- if ( ArgList[ 0 ].equals( null ) ) {
- return false;
- }
- FileObject file = null;
-
- try {
- // Source file
- file = HopVFS.getFileObject( Context.toString( ArgList[ 0 ] ) );
- boolean isafolder = false;
- if ( file.exists() ) {
- if ( file.getType().equals( FileType.FOLDER ) ) {
- isafolder = true;
- } else {
- Context.reportRuntimeError( "[" + Context.toString( ArgList[ 0 ] ) + "] is not a folder!" );
- }
- } else {
- Context.reportRuntimeError( "folder [" + Context.toString( ArgList[ 0 ] ) + "] can not be found!" );
- }
- return isafolder;
- } catch ( IOException e ) {
- throw Context.reportRuntimeError( "The function call isFolder throw an error : " + e.toString() );
- } finally {
- if ( file != null ) {
- try {
- file.close();
- } catch ( Exception e ) {
- // Ignore errors
- }
- }
- }
-
- } else {
- throw Context.reportRuntimeError( "The function call isFolder is not valid." );
- }
- } catch ( Exception e ) {
- throw Context.reportRuntimeError( e.toString() );
- }
- }
-
- public static String getShortFilename( Context actualContext, Scriptable actualObject, Object[] ArgList,
- Function FunctionContext ) {
- try {
- if ( ArgList.length == 1 && !isNull( ArgList[ 0 ] ) && !isUndefined( ArgList[ 0 ] ) ) {
- if ( ArgList[ 0 ].equals( null ) ) {
- return null;
- }
- FileObject file = null;
-
- try {
- // Source file
- file = HopVFS.getFileObject( Context.toString( ArgList[ 0 ] ) );
- String Filename = null;
- if ( file.exists() ) {
- Filename = file.getName().getBaseName().toString();
-
- } else {
- Context.reportRuntimeError( "file [" + Context.toString( ArgList[ 0 ] ) + "] can not be found!" );
- }
-
- return Filename;
- } catch ( IOException e ) {
- throw Context.reportRuntimeError( "The function call getShortFilename throw an error : " + e.toString() );
- } finally {
- if ( file != null ) {
- try {
- file.close();
- } catch ( Exception e ) {
- // Ignore errors
- }
- }
- }
-
- } else {
- throw Context.reportRuntimeError( "The function call getShortFilename is not valid." );
- }
- } catch ( Exception e ) {
- throw Context.reportRuntimeError( e.toString() );
- }
- }
-
- public static String getFileExtension( Context actualContext, Scriptable actualObject, Object[] ArgList,
- Function FunctionContext ) {
- try {
- if ( ArgList.length == 1 && !isNull( ArgList[ 0 ] ) && !isUndefined( ArgList[ 0 ] ) ) {
- if ( ArgList[ 0 ].equals( null ) ) {
- return null;
- }
- FileObject file = null;
-
- try {
- // Source file
- file = HopVFS.getFileObject( Context.toString( ArgList[ 0 ] ) );
- String Extension = null;
- if ( file.exists() ) {
- Extension = file.getName().getExtension().toString();
-
- } else {
- Context.reportRuntimeError( "file [" + Context.toString( ArgList[ 0 ] ) + "] can not be found!" );
- }
-
- return Extension;
- } catch ( IOException e ) {
- throw Context.reportRuntimeError( "The function call getFileExtension throw an error : " + e.toString() );
- } finally {
- if ( file != null ) {
- try {
- file.close();
- } catch ( Exception e ) {
- // Ignore errors
- }
- }
- }
-
- } else {
- throw Context.reportRuntimeError( "The function call getFileExtension is not valid." );
- }
- } catch ( Exception e ) {
- throw Context.reportRuntimeError( e.toString() );
- }
- }
-
- public static String getParentFoldername( Context actualContext, Scriptable actualObject, Object[] ArgList,
- Function FunctionContext ) {
- try {
- if ( ArgList.length == 1 && !isNull( ArgList[ 0 ] ) && !isUndefined( ArgList[ 0 ] ) ) {
- if ( ArgList[ 0 ].equals( null ) ) {
- return null;
- }
- FileObject file = null;
-
- try {
- // Source file
- file = HopVFS.getFileObject( Context.toString( ArgList[ 0 ] ) );
- String foldername = null;
- if ( file.exists() ) {
- foldername = HopVFS.getFilename( file.getParent() );
-
- } else {
- Context.reportRuntimeError( "file [" + Context.toString( ArgList[ 0 ] ) + "] can not be found!" );
- }
-
- return foldername;
- } catch ( IOException e ) {
- throw Context.reportRuntimeError( "The function call getParentFoldername throw an error : "
- + e.toString() );
- } finally {
- if ( file != null ) {
- try {
- file.close();
- } catch ( Exception e ) {
- // Ignore errors
- }
- }
- }
-
- } else {
- throw Context.reportRuntimeError( "The function call getParentFoldername is not valid." );
- }
- } catch ( Exception e ) {
- throw Context.reportRuntimeError( e.toString() );
- }
- }
-
- public static String getLastModifiedTime( Context actualContext, Scriptable actualObject, Object[] ArgList,
- Function FunctionContext ) {
- try {
- if ( ArgList.length == 2 && !isNull( ArgList[ 0 ] ) && !isUndefined( ArgList[ 0 ] ) ) {
- if ( ArgList[ 0 ].equals( null ) ) {
- return null;
- }
- FileObject file = null;
-
- try {
- // Source file
- file = HopVFS.getFileObject( Context.toString( ArgList[ 0 ] ) );
- String dateformat = Context.toString( ArgList[ 1 ] );
- if ( isNull( dateformat ) ) {
- dateformat = "yyyy-MM-dd";
- }
- String lastmodifiedtime = null;
- if ( file.exists() ) {
- java.util.Date lastmodifiedtimedate = new java.util.Date( file.getContent().getLastModifiedTime() );
- java.text.DateFormat dateFormat = new SimpleDateFormat( dateformat );
- lastmodifiedtime = dateFormat.format( lastmodifiedtimedate );
-
- } else {
- Context.reportRuntimeError( "file [" + Context.toString( ArgList[ 0 ] ) + "] can not be found!" );
- }
-
- return lastmodifiedtime;
- } catch ( IOException e ) {
- throw Context.reportRuntimeError( "The function call getLastModifiedTime throw an error : "
- + e.toString() );
- } finally {
- if ( file != null ) {
- try {
- file.close();
- } catch ( Exception e ) {
- // Ignore errors
- }
- }
- }
-
- } else {
- throw Context.reportRuntimeError( "The function call getLastModifiedTime is not valid." );
- }
- } catch ( Exception e ) {
- throw Context.reportRuntimeError( e.toString() );
- }
- }
-
- public static Object trunc( Context actualContext, Scriptable actualObject, Object[] ArgList,
- Function FunctionContext ) {
- try {
- // 1 argument: normal truncation of numbers
- //
- if ( ArgList.length == 1 ) {
- if ( isNull( ArgList[ 0 ] ) ) {
- return null;
- } else if ( isUndefined( ArgList[ 0 ] ) ) {
- return Context.getUndefinedValue();
- }
-
- // This is the truncation of a number...
- //
- Double dArg1 = (Double) Context.jsToJava( ArgList[ 0 ], Double.class );
- return Double.valueOf( Math.floor( dArg1 ) );
-
- } else {
- throw Context.reportRuntimeError( "The function call trunc requires 1 argument, a number." );
- }
- } catch ( Exception e ) {
- throw Context.reportRuntimeError( e.toString() );
- }
- }
-
- @SuppressWarnings( "fallthrough" )
- public static Object truncDate( Context actualContext, Scriptable actualObject, Object[] ArgList, Function FunctionContext ) {
- // 2 arguments: truncation of dates to a certain precision
- //
- if ( ArgList.length == 2 ) {
- if ( isNull( ArgList[ 0 ] ) ) {
- return null;
- } else if ( isUndefined( ArgList[ 0 ] ) ) {
- return Context.getUndefinedValue();
- }
-
- // This is the truncation of a date...
- // The second argument specifies the level: ms, s, min, hour, day, month, year
- //
- Date dArg1 = null;
- Integer level = null;
- try {
- dArg1 = (java.util.Date) Context.jsToJava( ArgList[ 0 ], java.util.Date.class );
- level = (Integer) Context.jsToJava( ArgList[ 1 ], Integer.class );
- } catch ( Exception e ) {
- throw Context.reportRuntimeError( e.toString() );
- }
- return truncDate( dArg1, level );
- } else {
- throw Context
- .reportRuntimeError( "The function call truncDate requires 2 arguments: a date and a level (int)" );
- }
- }
-
- @VisibleForTesting
- static Date truncDate( Date dArg1, Integer level ) {
- Calendar cal = Calendar.getInstance();
- cal.setTime( dArg1 );
-
- switch ( level.intValue() ) {
- // MONTHS
- case 5:
- cal.set( Calendar.MONTH, 0 );
- // DAYS
- case 4:
- cal.set( Calendar.DAY_OF_MONTH, 1 );
- // HOURS
- case 3:
- cal.set( Calendar.HOUR_OF_DAY, 0 );
- // MINUTES
- case 2:
- cal.set( Calendar.MINUTE, 0 );
- // SECONDS
- case 1:
- cal.set( Calendar.SECOND, 0 );
- // MILI-SECONDS
- case 0:
- cal.set( Calendar.MILLISECOND, 0 );
- break;
- default:
- throw Context.reportRuntimeError( "Argument of TRUNC of date has to be between 0 and 5" );
- }
- return cal.getTime();
- }
-
- public static void moveFile( Context actualContext, Scriptable actualObject, Object[] ArgList,
- Function FunctionContext ) {
-
- try {
- if ( ArgList.length == 3
- && !isNull( ArgList[ 0 ] ) && !isNull( ArgList[ 1 ] ) && !isUndefined( ArgList[ 0 ] )
- && !isUndefined( ArgList[ 1 ] ) ) {
- FileObject fileSource = null, fileDestination = null;
-
- try {
- // Source file to move
- fileSource = HopVFS.getFileObject( Context.toString( ArgList[ 0 ] ) );
- // Destination filename
- fileDestination = HopVFS.getFileObject( Context.toString( ArgList[ 1 ] ) );
- if ( fileSource.exists() ) {
- // Source file exists...
- if ( fileSource.getType() == FileType.FILE ) {
- // Great..source is a file ...
- boolean overwrite = false;
- if ( !ArgList[ 1 ].equals( null ) ) {
- overwrite = Context.toBoolean( ArgList[ 2 ] );
- }
- boolean destinationExists = fileDestination.exists();
- // Let's move the file...
- if ( ( destinationExists && overwrite ) || !destinationExists ) {
- fileSource.moveTo( fileDestination );
- }
-
- }
- } else {
- Context.reportRuntimeError( "file to move [" + Context.toString( ArgList[ 0 ] ) + "] can not be found!" );
- }
- } catch ( IOException e ) {
- throw Context.reportRuntimeError( "The function call moveFile throw an error : " + e.toString() );
- } finally {
- if ( fileSource != null ) {
- try {
- fileSource.close();
- } catch ( Exception e ) {
- // Ignore errors
- }
- }
- if ( fileDestination != null ) {
- try {
- fileDestination.close();
- } catch ( Exception e ) {
- // Ignore errors
- }
- }
- }
-
- } else {
- throw Context.reportRuntimeError( "The function call copyFile is not valid." );
- }
- } catch ( Exception e ) {
- throw Context.reportRuntimeError( e.toString() );
- }
- }
-
- public static String execProcess( Context actualContext, Scriptable actualObject, Object[] ArgList,
- Function FunctionContext ) {
- String retval = null;
- if ( !isNull( ArgList ) && !isUndefined( ArgList ) ) {
- Process processrun = null;
- try {
-
- String ligne = "";
- StringBuilder buffer = new StringBuilder();
- processrun = Runtime.getRuntime().exec( Context.toString( ArgList[ 0 ] ) );
-
- // Get process response
- BufferedReader br = new BufferedReader( new InputStreamReader( processrun.getInputStream() ) );
-
- // Read response lines
- while ( ( ligne = br.readLine() ) != null ) {
- buffer.append( ligne );
- }
- // if (processrun.exitValue()!=0) throw Context.reportRuntimeError("Error while running " + arguments[0]);
-
- retval = buffer.toString();
-
- } catch ( Exception er ) {
- throw Context.reportRuntimeError( er.toString() );
- } finally {
- if ( processrun != null ) {
- processrun.destroy();
- }
- }
- } else {
- throw Context.reportRuntimeError( "The function call execProcess is not valid." );
- }
- return retval;
- }
-
- public static Boolean isEmpty( Context actualContext, Scriptable actualObject, Object[] ArgList,
- Function FunctionContext ) {
- if ( ArgList.length == 1 ) {
- try {
- if ( isUndefined( ArgList[ 0 ] ) ) {
- throw new Exception( ArgList[ 0 ] + " is undefined!" );
- }
- if ( isNull( ArgList[ 0 ] ) ) {
- return Boolean.TRUE;
- }
- if ( Context.toString( ArgList[ 0 ] ).length() == 0 ) {
- return Boolean.TRUE;
- } else {
- return Boolean.FALSE;
- }
-
- } catch ( Exception e ) {
- throw Context.reportRuntimeError( "Error in isEmpty function: " + e.getMessage() );
- }
- } else {
- throw Context.reportRuntimeError( "The function call isEmpty is not valid" );
- }
- }
-
- public static Boolean isMailValid( Context actualContext, Scriptable actualObject, Object[] ArgList,
- Function FunctionContext ) {
- Boolean isValid;
- if ( ArgList.length == 1 ) {
- try {
- if ( isUndefined( ArgList[ 0 ] ) ) {
- throw new Exception( ArgList[ 0 ] + " is undefined!" );
- }
- if ( isNull( ArgList[ 0 ] ) ) {
- return Boolean.FALSE;
- }
- if ( Context.toString( ArgList[ 0 ] ).length() == 0 ) {
- return Boolean.FALSE;
- }
-
- String email = Context.toString( ArgList[ 0 ] );
- if ( email.indexOf( '@' ) == -1 || email.indexOf( '.' ) == -1 ) {
- return Boolean.FALSE;
- }
-
- isValid = Boolean.TRUE;
-
- } catch ( Exception e ) {
- throw Context.reportRuntimeError( "Error in isMailValid function: " + e.getMessage() );
- }
- return isValid;
- } else {
- throw Context.reportRuntimeError( "The function call isMailValid is not valid" );
- }
- }
-
- public static String escapeXml( Context actualContext, Scriptable actualObject, Object[] ArgList,
- Function FunctionContext ) {
- if ( ArgList.length == 1 ) {
- return Const.escapeXML( Context.toString( ArgList[ 0 ] ) );
- } else {
- throw Context.reportRuntimeError( "The function call escapeXml requires 1 argument." );
-
- }
- }
-
- public static String escapeHtml( Context actualContext, Scriptable actualObject, Object[] ArgList,
- Function FunctionContext ) {
- if ( ArgList.length == 1 ) {
- return Const.escapeHtml( Context.toString( ArgList[ 0 ] ) );
- } else {
- throw Context.reportRuntimeError( "The function call escapeHtml requires 1 argument." );
- }
- }
-
- public static String unEscapeHtml( Context actualContext, Scriptable actualObject, Object[] ArgList,
- Function FunctionContext ) {
- if ( ArgList.length == 1 ) {
- return Const.unEscapeHtml( Context.toString( ArgList[ 0 ] ) );
- } else {
- throw Context.reportRuntimeError( "The function call unEscapeHtml requires 1 argument." );
- }
- }
-
- public static String unEscapeXml( Context actualContext, Scriptable actualObject, Object[] ArgList,
- Function FunctionContext ) {
- if ( ArgList.length == 1 ) {
- return Const.unEscapeXml( Context.toString( ArgList[ 0 ] ) );
- } else {
- throw Context.reportRuntimeError( "The function call unEscapeXml requires 1 argument." );
-
- }
- }
-
- public static String escapeSQL( Context actualContext, Scriptable actualObject, Object[] ArgList,
- Function FunctionContext ) {
- if ( ArgList.length == 1 ) {
- return Const.escapeSQL( Context.toString( ArgList[ 0 ] ) );
- } else {
- throw Context.reportRuntimeError( "The function call escapeSQL requires 1 argument." );
-
- }
- }
-
- public static String protectXMLCDATA( Context actualContext, Scriptable actualObject, Object[] ArgList,
- Function FunctionContext ) {
- if ( ArgList.length == 1 ) {
- return Const.protectXMLCDATA( Context.toString( ArgList[ 0 ] ) );
- } else {
- throw Context.reportRuntimeError( "The function call protectXMLCDATA requires 1 argument." );
-
- }
- }
-
- public static String removeDigits( Context actualContext, Scriptable actualObject, Object[] ArgList,
- Function FunctionContext ) {
- if ( ArgList.length == 1 ) {
- return Const.removeDigits( Context.toString( ArgList[ 0 ] ) );
- } else {
- throw Context.reportRuntimeError( "The function call removeDigits requires 1 argument." );
-
- }
- }
-
- public static String initCap( Context actualContext, Scriptable actualObject, Object[] ArgList,
- Function FunctionContext ) {
- if ( ArgList.length == 1 ) {
- return Const.initCap( Context.toString( ArgList[ 0 ] ) );
- } else {
- throw Context.reportRuntimeError( "The function call initCap requires 1 argument." );
-
- }
- }
-
- public static Object loadFileContent( Context actualContext, Scriptable actualObject, Object[] ArgList,
- Function FunctionContext ) {
- Object oRC = new Object();
- try {
-
- switch ( ArgList.length ) {
- case 0:
- throw Context.reportRuntimeError( "Please provide a filename to the function call loadFileContent." );
- case 1:
- try {
- if ( isNull( ArgList ) ) {
- return null;
- } else if ( isUndefined( ArgList ) ) {
- return Context.getUndefinedValue();
- }
- // Returns file content
- oRC = new String( LoadFileInput.getFileBinaryContent( Context.toString( ArgList[ 0 ] ) ) );
- } catch ( Exception e ) {
- throw Context
- .reportRuntimeError( "The function call loadFileContent throw an error : " + e.toString() );
- }
- break;
- case 2:
- try {
- if ( ArgList[ 0 ].equals( null ) ) {
- return null;
- } else if ( isUndefined( ArgList[ 0 ] ) ) {
- return Context.getUndefinedValue();
- }
- String encoding = null;
- if ( !isUndefined( ArgList[ 1 ] ) && !ArgList[ 1 ].equals( null ) ) {
- encoding = Context.toString( ArgList[ 1 ] );
- }
- // Returns file content
- oRC = new String( LoadFileInput.getFileBinaryContent( Context.toString( ArgList[ 0 ] ) ), encoding );
- } catch ( Exception e ) {
- throw Context
- .reportRuntimeError( "The function call loadFileContent throw an error : " + e.toString() );
- }
- break;
-
- default:
- throw Context.reportRuntimeError( "The function call loadFileContentrequires 1 ou 2 arguments." );
- }
-
- } catch ( Exception e ) {
- throw Context.reportRuntimeError( e.toString() );
- }
- return oRC;
- }
-
- public static int getOcuranceString( Context actualContext, Scriptable actualObject, Object[] ArgList,
- Function FunctionContext ) {
- int nr = 0;
- if ( ArgList.length == 2 ) {
- try {
- if ( isNull( ArgList[ 0 ] ) ) {
- return 0;
- } else if ( isUndefined( ArgList[ 0 ] ) ) {
- return (Integer) Context.getUndefinedValue();
- }
- if ( isNull( ArgList[ 1 ] ) ) {
- return 0;
- } else if ( isUndefined( ArgList[ 1 ] ) ) {
- return (Integer) Context.getUndefinedValue();
- }
- String string = Context.toString( ArgList[ 0 ] );
- String searchFor = Context.toString( ArgList[ 1 ] );
- nr = Const.getOcuranceString( string, searchFor );
- } catch ( Exception e ) {
- throw Context.reportRuntimeError( "The function call getOcuranceString is not valid" );
- }
- } else {
- throw Context.reportRuntimeError( "The function call getOcuranceString is not valid" );
- }
- return nr;
- }
-
- public static String removeCRLF( Context actualContext, Scriptable actualObject, Object[] ArgList,
- Function FunctionContext ) {
- if ( ArgList.length == 1 ) {
- try {
- if ( isNull( ArgList[ 0 ] ) ) {
- return null;
- } else if ( isUndefined( ArgList[ 0 ] ) ) {
- return (String) Context.getUndefinedValue();
- }
-
- return Const.removeCRLF( Context.toString( ArgList[ 0 ] ) );
- } catch ( Exception e ) {
- throw Context.reportRuntimeError( "The function call removeCRLF is not valid" );
- }
- } else {
- throw Context.reportRuntimeError( "The function call removeCRLF is not valid" );
- }
- }
-}
diff --git a/archive-pipeline-transforms/src/main/java/engine/transforms/scriptvalues_mod/ScriptValuesMetaMod.java b/archive-pipeline-transforms/src/main/java/engine/transforms/scriptvalues_mod/ScriptValuesMetaMod.java
deleted file mode 100644
index d535104..0000000
--- a/archive-pipeline-transforms/src/main/java/engine/transforms/scriptvalues_mod/ScriptValuesMetaMod.java
+++ /dev/null
@@ -1,990 +0,0 @@
-/*! ******************************************************************************
- *
- * Hop : The Hop Orchestration Platform
- *
- * http://www.project-hop.org
- *
- *******************************************************************************
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************************/
-
-package org.apache.hop.pipeline.transforms.scriptvalues_mod;
-
-import com.google.common.annotations.VisibleForTesting;
-import org.apache.hop.compatibility.Row;
-import org.apache.hop.compatibility.Value;
-import org.apache.hop.core.CheckResult;
-import org.apache.hop.core.CheckResultInterface;
-import org.apache.hop.core.Const;
-import org.apache.hop.core.annotations.Transform;
-import org.apache.hop.core.exception.HopException;
-import org.apache.hop.core.exception.HopTransformException;
-import org.apache.hop.core.exception.HopXmlException;
-import org.apache.hop.core.injection.AfterInjection;
-import org.apache.hop.core.injection.Injection;
-import org.apache.hop.core.injection.InjectionDeep;
-import org.apache.hop.core.injection.InjectionSupported;
-import org.apache.hop.core.injection.NullNumberConverter;
-import org.apache.hop.core.plugins.HopURLClassLoader;
-import org.apache.hop.core.row.RowMeta;
-import org.apache.hop.core.row.IRowMeta;
-import org.apache.hop.core.row.IValueMeta;
-import org.apache.hop.core.row.value.ValueMetaFactory;
-import org.apache.hop.core.util.Utils;
-import org.apache.hop.core.variables.iVariables;
-import org.apache.hop.core.xml.XmlHandler;
-import org.apache.hop.i18n.BaseMessages;
-import org.apache.hop.metastore.api.IMetaStore;
-import org.apache.hop.pipeline.Pipeline;
-import org.apache.hop.pipeline.PipelineMeta;
-import org.apache.hop.pipeline.transform.BaseTransformMeta;
-import org.apache.hop.pipeline.transform.ITransformData;
-import org.apache.hop.pipeline.transform.ITransform;
-import org.apache.hop.pipeline.transform.TransformMeta;
-import org.apache.hop.pipeline.transform.ITransform;
-import org.apache.hop.pipeline.transforms.fieldsplitter.DataTypeConverter;
-import org.mozilla.javascript.Context;
-import org.mozilla.javascript.ContextFactory;
-import org.mozilla.javascript.JavaScriptException;
-import org.mozilla.javascript.Script;
-import org.mozilla.javascript.Scriptable;
-import org.mozilla.javascript.ScriptableObject;
-import org.w3c.dom.Document;
-import org.w3c.dom.Node;
-
-import java.math.BigDecimal;
-import java.net.URL;
-import java.util.Arrays;
-import java.util.Date;
-import java.util.List;
-import java.util.Properties;
-
-/*
- * Created on 2-jun-2003
- *
- */
-@Transform( id = "ScriptValuesMod", i18nPackageName = "org.apache.hop.pipeline.transforms.scriptvalues_mod",
- name = "ScriptValuesMod.Name", description = "ScriptValuesMod.Description",
- categoryDescription = "i18n:org.apache.hop.pipeline.transform:BaseTransform.Category.Scripting" )
-@InjectionSupported( localizationPrefix = "ScriptValuesMod.Injection.", groups = { "FIELDS", "SCRIPTS" } )
-public class ScriptValuesMetaMod extends BaseTransformMeta implements ITransform {
- private static Class<?> PKG = ScriptValuesMetaMod.class; // for i18n purposes, needed by Translator!!
-
- private static final String JSSCRIPT_TAG_TYPE = "jsScript_type";
- private static final String JSSCRIPT_TAG_NAME = "jsScript_name";
- private static final String JSSCRIPT_TAG_SCRIPT = "jsScript_script";
-
- public static final String OPTIMIZATION_LEVEL_DEFAULT = "9";
-
- private ScriptValuesAddClasses[] additionalClasses;
-
- @InjectionDeep
- private ScriptValuesScript[] jsScripts;
-
- @Injection( name = "FIELD_NAME", group = "FIELDS" )
- private String[] fieldname;
-
- @Injection( name = "FIELD_RENAME_TO", group = "FIELDS" )
- private String[] rename;
-
- @Injection( name = "FIELD_TYPE", group = "FIELDS", convertEmpty = true, converter = DataTypeConverter.class )
- private int[] type;
-
- @Injection( name = "FIELD_LENGTH", group = "FIELDS", convertEmpty = true, converter = NullNumberConverter.class )
- private int[] length;
-
- @Injection( name = "FIELD_PRECISION", group = "FIELDS", convertEmpty = true, converter = NullNumberConverter.class )
- private int[] precision;
-
- @Injection( name = "FIELD_REPLACE", group = "FIELDS" )
- private boolean[] replace; // Replace the specified field.
-
- @Injection( name = "COMPATIBILITY_MODE" )
- private boolean compatible;
-
- @Injection( name = "OPTIMIZATION_LEVEL" )
- private String optimizationLevel;
-
- public ScriptValuesMetaMod() {
- super(); // allocate BaseTransformMeta
- compatible = true;
- try {
- parseXmlForAdditionalClasses();
- } catch ( Exception e ) { /* Ignore */
- }
- }
-
- /**
- * @return Returns the length.
- */
- public int[] getLength() {
- return length;
- }
-
- /**
- * @param length The length to set.
- */
- public void setLength( int[] length ) {
- this.length = length;
- }
-
- /**
- * @return Returns the name.
- */
- public String[] getFieldname() {
- return fieldname;
- }
-
- /**
- * @param fieldname The name to set.
- */
- public void setFieldname( String[] fieldname ) {
- this.fieldname = fieldname;
- }
-
- /**
- * @return Returns the precision.
- */
- public int[] getPrecision() {
- return precision;
- }
-
- /**
- * @param precision The precision to set.
- */
- public void setPrecision( int[] precision ) {
- this.precision = precision;
- }
-
- /**
- * @return Returns the rename.
- */
- public String[] getRename() {
- return rename;
- }
-
- /**
- * @param rename The rename to set.
- */
- public void setRename( String[] rename ) {
- this.rename = rename;
- }
-
- /**
- * @return Returns the type.
- */
- public int[] getType() {
- return this.type;
- }
-
- @AfterInjection
- public void afterInjection() {
- // extend all fields related arrays to match the length of the fieldname array, as they may all be different
- // sizes, after meta injection
- extend( fieldname.length );
- }
-
- /**
- * @param type The type to set.
- */
- public void setType( int[] type ) {
- this.type = type;
- }
-
- public int getNumberOfJSScripts() {
- return jsScripts.length;
- }
-
- public String[] getJSScriptNames() {
- String[] strJSNames = new String[ jsScripts.length ];
- for ( int i = 0; i < jsScripts.length; i++ ) {
- strJSNames[ i ] = jsScripts[ i ].getScriptName();
- }
- return strJSNames;
- }
-
- public ScriptValuesScript[] getJSScripts() {
- return jsScripts;
- }
-
- public void setJSScripts( ScriptValuesScript[] jsScripts ) {
- this.jsScripts = jsScripts;
- }
-
- public void loadXml( Node transformNode, IMetaStore metaStore ) throws HopXmlException {
- readData( transformNode );
- }
-
- public void allocate( int nrFields ) {
- fieldname = new String[ nrFields ];
- rename = new String[ nrFields ];
- type = new int[ nrFields ];
- for ( int i = 0; i < nrFields; i++ ) {
- type[ i ] = -1;
- }
- length = new int[ nrFields ];
- for ( int i = 0; i < nrFields; i++ ) {
- length[ i ] = -1;
- }
- precision = new int[ nrFields ];
- for ( int i = 0; i < nrFields; i++ ) {
- precision[ i ] = -1;
- }
- replace = new boolean[ nrFields ];
- }
-
- /**
- * Extends all field related arrays so that they are the same size.
- *
- * @param nrFields
- */
- @VisibleForTesting
- void extend( int nrFields ) {
- fieldname = extend( fieldname, nrFields );
- rename = extend( rename, nrFields );
- type = extend( type, nrFields );
- length = extend( length, nrFields );
- precision = extend( precision, nrFields );
- replace = extend( replace, nrFields );
- }
-
- private String[] extend( final String[] array, final int nrFields ) {
- if ( array == null ) {
- return new String[ nrFields ];
- } else if ( array.length < nrFields ) {
- return Arrays.copyOf( array, nrFields );
- } else {
- return array;
- }
- }
-
- private int[] extend( final int[] array, final int nrFields ) {
- if ( array == null || array.length < nrFields ) {
- int originalLength = array == null ? 0 : array.length;
- final int[] newArray = array == null ? new int[ nrFields ] : Arrays.copyOf( array, nrFields );
- for ( int i = originalLength; i < nrFields; i++ ) {
- newArray[ i ] = -1;
- }
- return newArray;
- } else {
- return array;
- }
- }
-
- private boolean[] extend( final boolean[] array, final int nrFields ) {
- if ( array == null ) {
- return new boolean[ nrFields ];
- } else if ( array.length < nrFields ) {
- return Arrays.copyOf( array, nrFields );
- } else {
- return array;
- }
- }
-
- public Object clone() {
- ScriptValuesMetaMod retval = (ScriptValuesMetaMod) super.clone();
-
- int nrFields = fieldname.length;
-
- retval.allocate( nrFields );
- System.arraycopy( fieldname, 0, retval.fieldname, 0, nrFields );
- System.arraycopy( rename, 0, retval.rename, 0, nrFields );
- System.arraycopy( type, 0, retval.type, 0, nrFields );
- System.arraycopy( length, 0, retval.length, 0, nrFields );
- System.arraycopy( precision, 0, retval.precision, 0, nrFields );
- System.arraycopy( replace, 0, retval.replace, 0, nrFields );
-
- return retval;
- }
-
- private void readData( Node transformNode ) throws HopXmlException {
- try {
- String script = XmlHandler.getTagValue( transformNode, "script" );
- String strCompatible = XmlHandler.getTagValue( transformNode, "compatible" );
- optimizationLevel = XmlHandler.getTagValue( transformNode, "optimizationLevel" );
-
- if ( strCompatible == null ) {
- compatible = true;
- } else {
- compatible = "Y".equalsIgnoreCase( strCompatible );
- }
-
- // When in compatibility mode, we load the script, not the other tabs...
- //
- if ( !Utils.isEmpty( script ) ) {
- jsScripts = new ScriptValuesScript[ 1 ];
- jsScripts[ 0 ] = new ScriptValuesScript( ScriptValuesScript.TRANSFORM_SCRIPT, "ScriptValue", script );
- } else {
- Node scripts = XmlHandler.getSubNode( transformNode, "jsScripts" );
- int nrscripts = XmlHandler.countNodes( scripts, "jsScript" );
- jsScripts = new ScriptValuesScript[ nrscripts ];
- for ( int i = 0; i < nrscripts; i++ ) {
- Node fnode = XmlHandler.getSubNodeByNr( scripts, "jsScript", i );
-
- jsScripts[ i ] =
- new ScriptValuesScript(
- Integer.parseInt( XmlHandler.getTagValue( fnode, JSSCRIPT_TAG_TYPE ) ), XmlHandler.getTagValue(
- fnode, JSSCRIPT_TAG_NAME ), XmlHandler.getTagValue( fnode, JSSCRIPT_TAG_SCRIPT ) );
- }
- }
-
- Node fields = XmlHandler.getSubNode( transformNode, "fields" );
- int nrFields = XmlHandler.countNodes( fields, "field" );
-
- allocate( nrFields );
-
- for ( int i = 0; i < nrFields; i++ ) {
- Node fnode = XmlHandler.getSubNodeByNr( fields, "field", i );
-
- fieldname[ i ] = XmlHandler.getTagValue( fnode, "name" );
- rename[ i ] = XmlHandler.getTagValue( fnode, "rename" );
- type[ i ] = ValueMetaFactory.getIdForValueMeta( XmlHandler.getTagValue( fnode, "type" ) );
-
- String slen = XmlHandler.getTagValue( fnode, "length" );
- String sprc = XmlHandler.getTagValue( fnode, "precision" );
- length[ i ] = Const.toInt( slen, -1 );
- precision[ i ] = Const.toInt( sprc, -1 );
- replace[ i ] = "Y".equalsIgnoreCase( XmlHandler.getTagValue( fnode, "replace" ) );
- }
- } catch ( Exception e ) {
- throw new HopXmlException( BaseMessages.getString(
- PKG, "ScriptValuesMetaMod.Exception.UnableToLoadTransformMetaFromXML" ), e );
- }
- }
-
- public void setDefault() {
- jsScripts = new ScriptValuesScript[ 1 ];
- jsScripts[ 0 ] =
- new ScriptValuesScript( ScriptValuesScript.TRANSFORM_SCRIPT, BaseMessages.getString(
- PKG, "ScriptValuesMod.Script1" ), "//"
- + BaseMessages.getString( PKG, "ScriptValuesMod.ScriptHere" ) + Const.CR + Const.CR );
-
- int nrFields = 0;
- allocate( nrFields );
-
- for ( int i = 0; i < nrFields; i++ ) {
- fieldname[ i ] = "newvalue";
- rename[ i ] = "newvalue";
- type[ i ] = IValueMeta.TYPE_NUMBER;
- length[ i ] = -1;
- precision[ i ] = -1;
- replace[ i ] = false;
- }
-
- compatible = false;
- optimizationLevel = OPTIMIZATION_LEVEL_DEFAULT;
- }
-
- public void getFields( IRowMeta row, String originTransformName, IRowMeta[] info, TransformMeta nextTransform,
- iVariables variables, IMetaStore metaStore ) throws HopTransformException {
- try {
- for ( int i = 0; i < fieldname.length; i++ ) {
- if ( !Utils.isEmpty( fieldname[ i ] ) ) {
- int valueIndex = -1;
- IValueMeta v;
- if ( replace[ i ] ) {
- valueIndex = row.indexOfValue( fieldname[ i ] );
- if ( valueIndex < 0 ) {
- // The field was not found using the "name" field
- if ( Utils.isEmpty( rename[ i ] ) ) {
- // There is no "rename" field to try; Therefore we cannot find the
- // field to replace
- throw new HopTransformException( BaseMessages.getString(
- PKG, "ScriptValuesMetaMod.Exception.FieldToReplaceNotFound", fieldname[ i ] ) );
- } else {
- // Lookup the field to replace using the "rename" field
- valueIndex = row.indexOfValue( rename[ i ] );
- if ( valueIndex < 0 ) {
- // The field was not found using the "rename" field"; Therefore
- // we cannot find the field to replace
- //
- throw new HopTransformException( BaseMessages.getString(
- PKG, "ScriptValuesMetaMod.Exception.FieldToReplaceNotFound", rename[ i ] ) );
- }
- }
- }
-
- // Change the data type to match what's specified...
- //
- IValueMeta source = row.getValueMeta( valueIndex );
- v = ValueMetaFactory.cloneValueMeta( source, type[ i ] );
- row.setValueMeta( valueIndex, v );
- } else {
- if ( !Utils.isEmpty( rename[ i ] ) ) {
- v = ValueMetaFactory.createValueMeta( rename[ i ], type[ i ] );
- } else {
- v = ValueMetaFactory.createValueMeta( fieldname[ i ], type[ i ] );
- }
- }
- v.setLength( length[ i ] );
- v.setPrecision( precision[ i ] );
- v.setOrigin( originTransformName );
- if ( !replace[ i ] ) {
- row.addValueMeta( v );
- }
- }
- }
- } catch ( HopException e ) {
- throw new HopTransformException( e );
- }
- }
-
- public String getXml() {
- StringBuilder retval = new StringBuilder( 300 );
-
- retval.append( " " ).append( XmlHandler.addTagValue( "compatible", compatible ) );
- retval.append( " " ).append( XmlHandler.addTagValue( "optimizationLevel", optimizationLevel ) );
-
- retval.append( " <jsScripts>" );
- for ( int i = 0; i < jsScripts.length; i++ ) {
- retval.append( " <jsScript>" );
- retval
- .append( " " ).append( XmlHandler.addTagValue( JSSCRIPT_TAG_TYPE, jsScripts[ i ].getScriptType() ) );
- retval
- .append( " " ).append( XmlHandler.addTagValue( JSSCRIPT_TAG_NAME, jsScripts[ i ].getScriptName() ) );
- retval.append( " " ).append( XmlHandler.addTagValue( JSSCRIPT_TAG_SCRIPT, jsScripts[ i ].getScript() ) );
- retval.append( " </jsScript>" );
- }
- retval.append( " </jsScripts>" );
-
- retval.append( " <fields>" );
- for ( int i = 0; i < fieldname.length; i++ ) {
- retval.append( " <field>" );
- retval.append( " " ).append( XmlHandler.addTagValue( "name", fieldname[ i ] ) );
- retval.append( " " ).append( XmlHandler.addTagValue( "rename", rename[ i ] ) );
- retval.append( " " ).append( XmlHandler.addTagValue( "type",
- ValueMetaFactory.getValueMetaName( type[ i ] ) ) );
- retval.append( " " ).append( XmlHandler.addTagValue( "length", length[ i ] ) );
- retval.append( " " ).append( XmlHandler.addTagValue( "precision", precision[ i ] ) );
- retval.append( " " ).append( XmlHandler.addTagValue( "replace", replace[ i ] ) );
- retval.append( " </field>" );
- }
- retval.append( " </fields>" );
-
- return retval.toString();
- }
-
- public void check( List<CheckResultInterface> remarks, PipelineMeta pipelineMeta, TransformMeta transformMeta,
- IRowMeta prev, String[] input, String[] output, IRowMeta info, iVariables variables,
- IMetaStore metaStore ) {
- boolean error_found = false;
- String error_message = "";
- CheckResult cr;
-
- Context jscx;
- Scriptable jsscope;
- Script jsscript;
-
- jscx = ContextFactory.getGlobal().enterContext();
- jsscope = jscx.initStandardObjects( null, false );
- try {
- jscx.setOptimizationLevel( Integer.valueOf( pipelineMeta.environmentSubstitute( optimizationLevel ) ) );
- } catch ( NumberFormatException nfe ) {
- error_message =
- "Error with optimization level. Could not convert the value of "
- + pipelineMeta.environmentSubstitute( optimizationLevel ) + " to an integer.";
- cr = new CheckResult( CheckResultInterface.TYPE_RESULT_ERROR, error_message, transformMeta );
- remarks.add( cr );
- } catch ( IllegalArgumentException iae ) {
- cr = new CheckResult( CheckResultInterface.TYPE_RESULT_ERROR, iae.getMessage(), transformMeta );
- remarks.add( cr );
- }
-
- String strActiveStartScriptName = "";
- String strActiveEndScriptName = "";
-
- String strActiveScript = "";
- String strActiveStartScript = "";
- String strActiveEndScript = "";
-
- // Building the Scripts
- if ( jsScripts.length > 0 ) {
- for ( int i = 0; i < jsScripts.length; i++ ) {
- if ( jsScripts[ i ].isTransformScript() ) {
- // strActiveScriptName =jsScripts[i].getScriptName();
- strActiveScript = jsScripts[ i ].getScript();
- } else if ( jsScripts[ i ].isStartScript() ) {
- strActiveStartScriptName = jsScripts[ i ].getScriptName();
- strActiveStartScript = jsScripts[ i ].getScript();
- } else if ( jsScripts[ i ].isEndScript() ) {
- strActiveEndScriptName = jsScripts[ i ].getScriptName();
- strActiveEndScript = jsScripts[ i ].getScript();
- }
- }
- }
-
- if ( prev != null && strActiveScript.length() > 0 ) {
- cr =
- new CheckResult( CheckResultInterface.TYPE_RESULT_OK, BaseMessages.getString(
- PKG, "ScriptValuesMetaMod.CheckResult.ConnectedTransformOK", String.valueOf( prev.size() ) ), transformMeta );
- remarks.add( cr );
-
- // Adding the existing Scripts to the Context
- for ( int i = 0; i < getNumberOfJSScripts(); i++ ) {
- Scriptable jsR = Context.toObject( jsScripts[ i ].getScript(), jsscope );
- jsscope.put( jsScripts[ i ].getScriptName(), jsscope, jsR );
- }
-
- // Modification for Additional Script parsing
- try {
- if ( getAddClasses() != null ) {
- for ( int i = 0; i < getAddClasses().length; i++ ) {
- Object jsOut = Context.javaToJS( getAddClasses()[ i ].getAddObject(), jsscope );
- ScriptableObject.putProperty( jsscope, getAddClasses()[ i ].getJSName(), jsOut );
- }
- }
- } catch ( Exception e ) {
- error_message = ( "Couldn't add JavaClasses to Context! Error:" );
- cr = new CheckResult( CheckResultInterface.TYPE_RESULT_ERROR, error_message, transformMeta );
- remarks.add( cr );
- }
-
- // Adding some default JavaScriptFunctions to the System
- try {
- Context.javaToJS( ScriptValuesAddedFunctions.class, jsscope );
- ( (ScriptableObject) jsscope )
- .defineFunctionProperties(
- ScriptValuesAddedFunctions.jsFunctionList, ScriptValuesAddedFunctions.class,
- ScriptableObject.DONTENUM );
- } catch ( Exception ex ) {
- error_message = "Couldn't add Default Functions! Error:" + Const.CR + ex.toString();
- cr = new CheckResult( CheckResultInterface.TYPE_RESULT_ERROR, error_message, transformMeta );
- remarks.add( cr );
- }
-
- // Adding some Constants to the JavaScript
- try {
- jsscope.put( "SKIP_PIPELINE", jsscope, Integer.valueOf( ScriptValuesMod.SKIP_PIPELINE ) );
- jsscope.put( "ABORT_PIPELINE", jsscope, Integer.valueOf( ScriptValuesMod.ABORT_PIPELINE ) );
- jsscope.put( "ERROR_PIPELINE", jsscope, Integer.valueOf( ScriptValuesMod.ERROR_PIPELINE ) );
- jsscope
- .put( "CONTINUE_PIPELINE", jsscope, Integer.valueOf( ScriptValuesMod.CONTINUE_PIPELINE ) );
- } catch ( Exception ex ) {
- error_message = "Couldn't add Pipeline Constants! Error:" + Const.CR + ex.toString();
- cr = new CheckResult( CheckResultInterface.TYPE_RESULT_ERROR, error_message, transformMeta );
- remarks.add( cr );
- }
-
- try {
- ScriptValuesModDummy dummyTransform = new ScriptValuesModDummy( prev, pipelineMeta.getTransformFields( transformMeta ) );
- Scriptable jsvalue = Context.toObject( dummyTransform, jsscope );
- jsscope.put( "_transform_", jsscope, jsvalue );
-
- Object[] row = new Object[ prev.size() ];
- Scriptable jsRowMeta = Context.toObject( prev, jsscope );
- jsscope.put( "rowMeta", jsscope, jsRowMeta );
- for ( int i = 0; i < prev.size(); i++ ) {
- IValueMeta valueMeta = prev.getValueMeta( i );
- Object valueData = null;
-
- // Set date and string values to something to simulate real thing
- //
- if ( valueMeta.isDate() ) {
- valueData = new Date();
- }
- if ( valueMeta.isString() ) {
- valueData = "test value test value test value test value test value "
- + "test value test value test value test value test value";
- }
- if ( valueMeta.isInteger() ) {
- valueData = Long.valueOf( 0L );
- }
- if ( valueMeta.isNumber() ) {
- valueData = new Double( 0.0 );
- }
- if ( valueMeta.isBigNumber() ) {
- valueData = BigDecimal.ZERO;
- }
- if ( valueMeta.isBoolean() ) {
- valueData = Boolean.TRUE;
- }
- if ( valueMeta.isBinary() ) {
- valueData = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, };
- }
-
- row[ i ] = valueData;
-
- if ( isCompatible() ) {
- Value value = valueMeta.createOriginalValue( valueData );
- Scriptable jsarg = Context.toObject( value, jsscope );
- jsscope.put( valueMeta.getName(), jsscope, jsarg );
- } else {
- Scriptable jsarg = Context.toObject( valueData, jsscope );
- jsscope.put( valueMeta.getName(), jsscope, jsarg );
- }
- }
- // Add support for Value class (new Value())
- Scriptable jsval = Context.toObject( Value.class, jsscope );
- jsscope.put( "Value", jsscope, jsval );
-
- // Add the old style row object for compatibility reasons...
- //
- if ( isCompatible() ) {
- Row v2Row = RowMeta.createOriginalRow( prev, row );
- Scriptable jsV2Row = Context.toObject( v2Row, jsscope );
- jsscope.put( "row", jsscope, jsV2Row );
- } else {
- Scriptable jsRow = Context.toObject( row, jsscope );
- jsscope.put( "row", jsscope, jsRow );
- }
- } catch ( Exception ev ) {
- error_message = "Couldn't add Input fields to Script! Error:" + Const.CR + ev.toString();
- cr = new CheckResult( CheckResultInterface.TYPE_RESULT_ERROR, error_message, transformMeta );
- remarks.add( cr );
- }
-
- try {
- // Checking for StartScript
- if ( strActiveStartScript != null && strActiveStartScript.length() > 0 ) {
- /* Object startScript = */
- jscx.evaluateString( jsscope, strActiveStartScript, "pipeline_Start", 1, null );
- error_message = "Found Start Script. " + strActiveStartScriptName + " Processing OK";
- cr = new CheckResult( CheckResultInterface.TYPE_RESULT_OK, error_message, transformMeta );
- remarks.add( cr );
- }
- } catch ( Exception e ) {
- error_message = "Couldn't process Start Script! Error:" + Const.CR + e.toString();
- cr = new CheckResult( CheckResultInterface.TYPE_RESULT_ERROR, error_message, transformMeta );
- remarks.add( cr );
- }
-
- try {
- jsscript = jscx.compileString( strActiveScript, "script", 1, null );
-
- cr =
- new CheckResult( CheckResultInterface.TYPE_RESULT_OK, BaseMessages.getString(
- PKG, "ScriptValuesMetaMod.CheckResult.ScriptCompiledOK" ), transformMeta );
- remarks.add( cr );
-
- try {
-
- jsscript.exec( jscx, jsscope );
-
- cr =
- new CheckResult( CheckResultInterface.TYPE_RESULT_OK, BaseMessages.getString(
- PKG, "ScriptValuesMetaMod.CheckResult.ScriptCompiledOK2" ), transformMeta );
- remarks.add( cr );
-
- if ( fieldname.length > 0 ) {
- StringBuilder message =
- new StringBuilder( BaseMessages.getString(
- PKG, "ScriptValuesMetaMod.CheckResult.FailedToGetValues", String.valueOf( fieldname.length ) )
- + Const.CR + Const.CR );
-
- if ( error_found ) {
- cr = new CheckResult( CheckResultInterface.TYPE_RESULT_ERROR, message.toString(), transformMeta );
- } else {
- cr = new CheckResult( CheckResultInterface.TYPE_RESULT_OK, message.toString(), transformMeta );
- }
- remarks.add( cr );
- }
- } catch ( JavaScriptException jse ) {
- Context.exit();
- error_message =
- BaseMessages.getString( PKG, "ScriptValuesMetaMod.CheckResult.CouldNotExecuteScript" )
- + Const.CR + jse.toString();
- cr = new CheckResult( CheckResultInterface.TYPE_RESULT_ERROR, error_message, transformMeta );
- remarks.add( cr );
- } catch ( Exception e ) {
- Context.exit();
- error_message =
- BaseMessages.getString( PKG, "ScriptValuesMetaMod.CheckResult.CouldNotExecuteScript2" )
- + Const.CR + e.toString();
- cr = new CheckResult( CheckResultInterface.TYPE_RESULT_ERROR, error_message, transformMeta );
- remarks.add( cr );
- }
-
- // Checking End Script
- try {
- if ( strActiveEndScript != null && strActiveEndScript.length() > 0 ) {
- /* Object endScript = */
- jscx.evaluateString( jsscope, strActiveEndScript, "pipeline_End", 1, null );
- error_message = "Found End Script. " + strActiveEndScriptName + " Processing OK";
- cr = new CheckResult( CheckResultInterface.TYPE_RESULT_OK, error_message, transformMeta );
- remarks.add( cr );
- }
- } catch ( Exception e ) {
- error_message = "Couldn't process End Script! Error:" + Const.CR + e.toString();
- cr = new CheckResult( CheckResultInterface.TYPE_RESULT_ERROR, error_message, transformMeta );
- remarks.add( cr );
- }
- } catch ( Exception e ) {
- Context.exit();
- error_message =
- BaseMessages.getString( PKG, "ScriptValuesMetaMod.CheckResult.CouldNotCompileScript" )
- + Const.CR + e.toString();
- cr = new CheckResult( CheckResultInterface.TYPE_RESULT_ERROR, error_message, transformMeta );
- remarks.add( cr );
- }
- } else {
- Context.exit();
- error_message =
- BaseMessages.getString( PKG, "ScriptValuesMetaMod.CheckResult.CouldNotGetFieldsFromPreviousTransform" );
- cr = new CheckResult( CheckResultInterface.TYPE_RESULT_ERROR, error_message, transformMeta );
- remarks.add( cr );
- }
-
- // See if we have input streams leading to this transform!
- if ( input.length > 0 ) {
- cr =
- new CheckResult( CheckResultInterface.TYPE_RESULT_OK, BaseMessages.getString(
- PKG, "ScriptValuesMetaMod.CheckResult.ConnectedTransformOK2" ), transformMeta );
- remarks.add( cr );
- } else {
- cr =
- new CheckResult( CheckResultInterface.TYPE_RESULT_ERROR, BaseMessages.getString(
- PKG, "ScriptValuesMetaMod.CheckResult.NoInputReceived" ), transformMeta );
- remarks.add( cr );
- }
- }
-
- public String getFunctionFromScript( String strFunction, String strScript ) {
- String sRC = "";
- int iStartPos = strScript.indexOf( strFunction );
- if ( iStartPos > 0 ) {
- iStartPos = strScript.indexOf( '{', iStartPos );
- int iCounter = 1;
- while ( iCounter != 0 ) {
- if ( strScript.charAt( iStartPos++ ) == '{' ) {
- iCounter++;
- } else if ( strScript.charAt( iStartPos++ ) == '}' ) {
- iCounter--;
- }
- sRC = sRC + strScript.charAt( iStartPos );
- }
- }
- return sRC;
- }
-
- public boolean getValue( Scriptable scope, int i, Value res, StringBuilder message ) {
- boolean error_found = false;
-
- if ( fieldname[ i ] != null && fieldname[ i ].length() > 0 ) {
- res.setName( rename[ i ] );
- res.setType( type[ i ] );
-
- try {
-
- Object result = scope.get( fieldname[ i ], scope );
- if ( result != null ) {
-
- String classname = result.getClass().getName();
-
- switch ( type[ i ] ) {
- case IValueMeta.TYPE_NUMBER:
- if ( classname.equalsIgnoreCase( "org.mozilla.javascript.Undefined" ) ) {
- res.setNull();
- } else if ( classname.equalsIgnoreCase( "org.mozilla.javascript.NativeJavaObject" ) ) {
- // Is it a java Value class ?
- Value v = (Value) Context.jsToJava( result, Value.class );
- res.setValue( v.getNumber() );
- } else {
- res.setValue( ( (Double) result ).doubleValue() );
- }
- break;
- case IValueMeta.TYPE_INTEGER:
- if ( classname.equalsIgnoreCase( "java.lang.Byte" ) ) {
- res.setValue( ( (java.lang.Byte) result ).longValue() );
- } else if ( classname.equalsIgnoreCase( "java.lang.Short" ) ) {
- res.setValue( ( (Short) result ).longValue() );
- } else if ( classname.equalsIgnoreCase( "java.lang.Integer" ) ) {
- res.setValue( ( (Integer) result ).longValue() );
- } else if ( classname.equalsIgnoreCase( "java.lang.Long" ) ) {
- res.setValue( ( (Long) result ).longValue() );
- } else if ( classname.equalsIgnoreCase( "org.mozilla.javascript.Undefined" ) ) {
- res.setNull();
- } else if ( classname.equalsIgnoreCase( "org.mozilla.javascript.NativeJavaObject" ) ) {
- // Is it a java Value class ?
- Value v = (Value) Context.jsToJava( result, Value.class );
- res.setValue( v.getInteger() );
- } else {
- res.setValue( Math.round( ( (Double) result ).doubleValue() ) );
- }
- break;
- case IValueMeta.TYPE_STRING:
- if ( classname.equalsIgnoreCase( "org.mozilla.javascript.NativeJavaObject" )
- || classname.equalsIgnoreCase( "org.mozilla.javascript.Undefined" ) ) {
- // Is it a java Value class ?
- try {
- Value v = (Value) Context.jsToJava( result, Value.class );
- res.setValue( v.getString() );
- } catch ( Exception ev ) {
- // A String perhaps?
- String s = (String) Context.jsToJava( result, String.class );
- res.setValue( s );
- }
- } else {
- res.setValue( ( (String) result ) );
- }
- break;
- case IValueMeta.TYPE_DATE:
- double dbl = 0;
- if ( classname.equalsIgnoreCase( "org.mozilla.javascript.Undefined" ) ) {
- res.setNull();
- } else {
- if ( classname.equalsIgnoreCase( "org.mozilla.javascript.NativeDate" ) ) {
- dbl = Context.toNumber( result );
- } else if ( classname.equalsIgnoreCase( "org.mozilla.javascript.NativeJavaObject" ) ) {
- // Is it a java Date() class ?
- try {
- Date dat = (Date) Context.jsToJava( result, java.util.Date.class );
- dbl = dat.getTime();
- } catch ( Exception e ) { // Nope, try a Value
-
- Value v = (Value) Context.jsToJava( result, Value.class );
- Date dat = v.getDate();
- if ( dat != null ) {
- dbl = dat.getTime();
- } else {
- res.setNull();
- }
- }
- } else { // Finally, try a number conversion to time
-
- dbl = ( (Double) result ).doubleValue();
- }
- long lng = Math.round( dbl );
- Date dat = new Date( lng );
- res.setValue( dat );
- }
- break;
- case IValueMeta.TYPE_BOOLEAN:
- res.setValue( ( (Boolean) result ).booleanValue() );
- break;
- default:
- res.setNull();
- }
- } else {
- res.setNull();
- }
- } catch ( Exception e ) {
- message.append( BaseMessages.getString(
- PKG, "ScriptValuesMetaMod.CheckResult.ErrorRetrievingValue", fieldname[ i ] )
- + " : " + e.toString() );
- error_found = true;
- }
- res.setLength( length[ i ], precision[ i ] );
-
- message.append( BaseMessages.getString(
- PKG, "ScriptValuesMetaMod.CheckResult.RetrievedValue", fieldname[ i ], res.toStringMeta() ) );
- } else {
- message.append( BaseMessages.getString( PKG, "ScriptValuesMetaMod.CheckResult.ValueIsEmpty", String
- .valueOf( i ) ) );
- error_found = true;
- }
-
- return error_found;
- }
-
- public ITransform getTransform( TransformMeta transformMeta, ITransformData data, int cnr,
- PipelineMeta pipelineMeta, Pipeline pipeline ) {
- return new ScriptValuesMod( transformMeta, this, data, cnr, pipelineMeta, pipeline );
- }
-
- public ITransformData getTransformData() {
- return new ScriptValuesModData();
- }
-
- // This is for Additional Classloading
- public void parseXmlForAdditionalClasses() throws HopException {
- try {
- Properties sysprops = System.getProperties();
- String strActPath = sysprops.getProperty( "user.dir" );
- Document dom = XmlHandler.loadXmlFile( strActPath + "/plugins/transforms/ScriptValues_mod/plugin.xml" );
- Node transformNode = dom.getDocumentElement();
- Node libraries = XmlHandler.getSubNode( transformNode, "js_libraries" );
- int nbOfLibs = XmlHandler.countNodes( libraries, "js_lib" );
- additionalClasses = new ScriptValuesAddClasses[ nbOfLibs ];
- for ( int i = 0; i < nbOfLibs; i++ ) {
- Node fnode = XmlHandler.getSubNodeByNr( libraries, "js_lib", i );
- String strJarName = XmlHandler.getTagAttribute( fnode, "name" );
- String strClassName = XmlHandler.getTagAttribute( fnode, "classname" );
- String strJSName = XmlHandler.getTagAttribute( fnode, "js_name" );
-
- Class<?> addClass =
- LoadAdditionalClass( strActPath + "/plugins/transforms/ScriptValues_mod/" + strJarName, strClassName );
- Object addObject = addClass.newInstance();
- additionalClasses[ i ] = new ScriptValuesAddClasses( addClass, addObject, strJSName );
- }
- } catch ( Exception e ) {
- throw new HopException( BaseMessages.getString(
- PKG, "ScriptValuesMetaMod.Exception.UnableToParseXMLforAdditionalClasses" ), e );
- }
- }
-
- private static Class<?> LoadAdditionalClass( String strJar, String strClassName ) throws HopException {
- try {
- Thread t = Thread.currentThread();
- ClassLoader cl = t.getContextClassLoader();
- URL u = new URL( "jar:file:" + strJar + "!/" );
- // We never know what else the script wants to load with the class loader, so lets not close it just like that.
- @SuppressWarnings( "resource" )
- HopURLClassLoader kl = new HopURLClassLoader( new URL[] { u }, cl );
- Class<?> toRun = kl.loadClass( strClassName );
- return toRun;
- } catch ( Exception e ) {
- throw new HopException( BaseMessages.getString(
- PKG, "ScriptValuesMetaMod.Exception.UnableToLoadAdditionalClass" ), e );
- }
- }
-
- public ScriptValuesAddClasses[] getAddClasses() {
- return additionalClasses;
- }
-
- /**
- * @return the compatible
- */
- public boolean isCompatible() {
- return compatible;
- }
-
- /**
- * @param compatible the compatible to set
- */
- public void setCompatible( boolean compatible ) {
- this.compatible = compatible;
- }
-
- public boolean supportsErrorHandling() {
- return true;
- }
-
- public String getDialogClassName() {
- return "org.apache.hop.ui.pipeline.transforms.scriptvalues_mod.ScriptValuesModDialog";
- }
-
- /**
- * @return the replace
- */
- public boolean[] getReplace() {
- return replace;
- }
-
- /**
- * @param replace the replace to set
- */
- public void setReplace( boolean[] replace ) {
- this.replace = replace;
- }
-
- public void setOptimizationLevel( String optimizationLevel ) {
- this.optimizationLevel = optimizationLevel;
- }
-
- public String getOptimizationLevel() {
- return this.optimizationLevel;
- }
-}
diff --git a/archive-pipeline-transforms/src/main/java/engine/transforms/scriptvalues_mod/ScriptValuesMod.java b/archive-pipeline-transforms/src/main/java/engine/transforms/scriptvalues_mod/ScriptValuesMod.java
deleted file mode 100644
index e87bde0..0000000
--- a/archive-pipeline-transforms/src/main/java/engine/transforms/scriptvalues_mod/ScriptValuesMod.java
+++ /dev/null
@@ -1,607 +0,0 @@
-/*! ******************************************************************************
- *
- * Hop : The Hop Orchestration Platform
- *
- * http://www.project-hop.org
- *
- *******************************************************************************
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************************/
-
-package org.apache.hop.pipeline.transforms.scriptvalues_mod;
-
-import org.apache.hop.compatibility.Row;
-import org.apache.hop.compatibility.Value;
-import org.apache.hop.compatibility.ValueUsedListener;
-import org.apache.hop.core.Const;
-import org.apache.hop.core.exception.HopException;
-import org.apache.hop.core.exception.HopTransformException;
-import org.apache.hop.core.exception.HopValueException;
-import org.apache.hop.core.row.RowDataUtil;
-import org.apache.hop.core.row.RowMeta;
-import org.apache.hop.core.row.IRowMeta;
-import org.apache.hop.core.row.IValueMeta;
-import org.apache.hop.core.util.JavaScriptUtils;
-import org.apache.hop.core.util.Utils;
-import org.apache.hop.i18n.BaseMessages;
-import org.apache.hop.pipeline.Pipeline;
-import org.apache.hop.pipeline.PipelineMeta;
-import org.apache.hop.pipeline.transform.BaseTransform;
-import org.apache.hop.pipeline.transform.ITransformData;
-import org.apache.hop.pipeline.transform.ITransform;
-import org.apache.hop.pipeline.transform.TransformMeta;
-import org.apache.hop.pipeline.transform.ITransform;
-import org.mozilla.javascript.Context;
-import org.mozilla.javascript.ContextFactory;
-import org.mozilla.javascript.EvaluatorException;
-import org.mozilla.javascript.Script;
-import org.mozilla.javascript.Scriptable;
-import org.mozilla.javascript.ScriptableObject;
-
-import java.util.Hashtable;
-import java.util.Map;
-
-/**
- * Executes a JavaScript on the values in the input stream. Selected calculated values can then be put on the output
- * stream.
- *
- * @author Matt
- * @since 5-April-2003
- */
-public class ScriptValuesMod extends BaseTransform implements ITransform {
- private static Class<?> PKG = ScriptValuesMetaMod.class; // for i18n purposes, needed by Translator!!
-
- private ScriptValuesMetaMod meta;
-
- private ScriptValuesModData data;
-
- public static final int SKIP_PIPELINE = 1;
-
- public static final int ABORT_PIPELINE = -1;
-
- public static final int ERROR_PIPELINE = -2;
-
- public static final int CONTINUE_PIPELINE = 0;
-
- private boolean bWithPipelineStat = false;
-
- private boolean bRC = false;
-
- private int iPipelineStat = CONTINUE_PIPELINE;
-
- private boolean bFirstRun = false;
-
- private ScriptValuesScript[] jsScripts;
-
- private String strTransformScript = "";
-
- private String strStartScript = "";
-
- private String strEndScript = "";
-
- // public static Row insertRow;
-
- public Script script;
-
- public ScriptValuesMod( TransformMeta transformMeta, ITransformData data, int copyNr, PipelineMeta pipelineMeta,
- Pipeline pipeline ) {
- super( transformMeta, meta, data, copyNr, pipelineMeta, pipeline );
- }
-
- private void determineUsedFields( IRowMeta row ) {
- int nr = 0;
- // Count the occurrences of the values.
- // Perhaps we find values in comments, but we take no risk!
- //
- for ( int i = 0; i < row.size(); i++ ) {
- String valname = row.getValueMeta( i ).getName().toUpperCase();
- if ( strTransformScript.toUpperCase().indexOf( valname ) >= 0 ) {
- nr++;
- }
- }
-
- // Allocate fields_used
- data.fields_used = new int[ nr ];
- data.values_used = new Value[ nr ];
-
- nr = 0;
- // Count the occurrences of the values.
- // Perhaps we find values in comments, but we take no risk!
- //
- for ( int i = 0; i < row.size(); i++ ) {
- // Values are case-insensitive in JavaScript.
- //
- String valname = row.getValueMeta( i ).getName();
- if ( strTransformScript.indexOf( valname ) >= 0 ) {
- if ( log.isDetailed() ) {
- logDetailed( BaseMessages.getString(
- PKG, "ScriptValuesMod.Log.UsedValueName", String.valueOf( i ), valname ) );
- }
- data.fields_used[ nr ] = i;
- nr++;
- }
- }
-
- if ( log.isDetailed() ) {
- logDetailed( BaseMessages.getString( PKG, "ScriptValuesMod.Log.UsingValuesFromInputStream", String
- .valueOf( data.fields_used.length ) ) );
- }
- }
-
- private boolean addValues( IRowMeta rowMeta, Object[] row ) throws HopException {
- if ( first ) {
- first = false;
-
- // What is the output row looking like?
- //
- data.outputRowMeta = getInputRowMeta().clone();
- meta.getFields( data.outputRowMeta, getTransformName(), null, null, this, metaStore );
-
- // Determine the indexes of the fields used!
- //
- determineUsedFields( rowMeta );
-
- // Get the indexes of the replaced fields...
- //
- data.replaceIndex = new int[ meta.getFieldname().length ];
- for ( int i = 0; i < meta.getFieldname().length; i++ ) {
- if ( meta.getReplace()[ i ] ) {
- data.replaceIndex[ i ] = rowMeta.indexOfValue( meta.getFieldname()[ i ] );
- if ( data.replaceIndex[ i ] < 0 ) {
- if ( Utils.isEmpty( meta.getFieldname()[ i ] ) ) {
- throw new HopTransformException( BaseMessages.getString(
- PKG, "ScriptValuesMetaMod.Exception.FieldToReplaceNotFound", meta.getFieldname()[ i ] ) );
- }
- data.replaceIndex[ i ] = rowMeta.indexOfValue( meta.getRename()[ i ] );
- if ( data.replaceIndex[ i ] < 0 ) {
- throw new HopTransformException( BaseMessages.getString(
- PKG, "ScriptValuesMetaMod.Exception.FieldToReplaceNotFound", meta.getRename()[ i ] ) );
- }
- }
- } else {
- data.replaceIndex[ i ] = -1;
- }
- }
-
- // set the optimization level
- data.cx = ContextFactory.getGlobal().enterContext();
-
- try {
- String optimizationLevelAsString = environmentSubstitute( meta.getOptimizationLevel() );
- if ( !Utils.isEmpty( Const.trim( optimizationLevelAsString ) ) ) {
- data.cx.setOptimizationLevel( Integer.parseInt( optimizationLevelAsString.trim() ) );
- logBasic( BaseMessages.getString( PKG, "ScriptValuesMod.Optimization.Level", environmentSubstitute( meta
- .getOptimizationLevel() ) ) );
- } else {
- data.cx.setOptimizationLevel( Integer.parseInt( ScriptValuesMetaMod.OPTIMIZATION_LEVEL_DEFAULT ) );
- logBasic( BaseMessages.getString(
- PKG, "ScriptValuesMod.Optimization.UsingDefault", ScriptValuesMetaMod.OPTIMIZATION_LEVEL_DEFAULT ) );
- }
- } catch ( NumberFormatException nfe ) {
- throw new HopTransformException( BaseMessages.getString(
- PKG, "ScriptValuesMetaMod.Exception.NumberFormatException", environmentSubstitute( meta
- .getOptimizationLevel() ) ) );
- } catch ( IllegalArgumentException iae ) {
- throw new HopException( iae.getMessage() );
- }
-
- data.scope = data.cx.initStandardObjects( null, false );
-
- bFirstRun = true;
-
- Scriptable jsvalue = Context.toObject( this, data.scope );
- data.scope.put( "_transform_", data.scope, jsvalue );
-
- // Adding the existing Scripts to the Context
- for ( int i = 0; i < meta.getNumberOfJSScripts(); i++ ) {
- Scriptable jsR = Context.toObject( jsScripts[ i ].getScript(), data.scope );
- data.scope.put( jsScripts[ i ].getScriptName(), data.scope, jsR );
- }
-
- // Adding the Name of the Pipeline to the Context
- data.scope.put( "_PipelineName_", data.scope, getPipelineMeta().getName() );
-
- try {
- // add these now (they will be re-added later) to make compilation succeed
- //
-
- // Add the old style row object for compatibility reasons...
- //
- if ( meta.isCompatible() ) {
- Row v2Row = RowMeta.createOriginalRow( rowMeta, row );
- Scriptable jsV2Row = Context.toObject( v2Row, data.scope );
- data.scope.put( "row", data.scope, jsV2Row );
- } else {
- Scriptable jsrow = Context.toObject( row, data.scope );
- data.scope.put( "row", data.scope, jsrow );
- }
-
- // Add the used fields...
- //
- for ( int i = 0; i < data.fields_used.length; i++ ) {
- IValueMeta valueMeta = rowMeta.getValueMeta( data.fields_used[ i ] );
- Object valueData = row[ data.fields_used[ i ] ];
-
- if ( meta.isCompatible() ) {
- data.values_used[ i ] = valueMeta.createOriginalValue( valueData );
-
- Scriptable jsarg = Context.toObject( data.values_used[ i ], data.scope );
- data.scope.put( valueMeta.getName(), data.scope, jsarg );
- } else {
- Object normalStorageValueData = valueMeta.convertToNormalStorageType( valueData );
- Scriptable jsarg;
- if ( normalStorageValueData != null ) {
- jsarg = Context.toObject( normalStorageValueData, data.scope );
- } else {
- jsarg = null;
- }
- data.scope.put( valueMeta.getName(), data.scope, jsarg );
- }
- }
-
- // also add the meta information for the whole row
- //
- Scriptable jsrowMeta = Context.toObject( rowMeta, data.scope );
- data.scope.put( "rowMeta", data.scope, jsrowMeta );
-
- // Modification for Additional Script parsing
- //
- try {
- if ( meta.getAddClasses() != null ) {
- for ( int i = 0; i < meta.getAddClasses().length; i++ ) {
- Object jsOut = Context.javaToJS( meta.getAddClasses()[ i ].getAddObject(), data.scope );
- ScriptableObject.putProperty( data.scope, meta.getAddClasses()[ i ].getJSName(), jsOut );
- }
- }
- } catch ( Exception e ) {
- throw new HopValueException( BaseMessages.getString(
- PKG, "ScriptValuesMod.Log.CouldNotAttachAdditionalScripts" ), e );
- }
-
- // Adding some default JavaScriptFunctions to the System
- try {
- Context.javaToJS( ScriptValuesAddedFunctions.class, data.scope );
- ( (ScriptableObject) data.scope ).defineFunctionProperties(
- ScriptValuesAddedFunctions.jsFunctionList, ScriptValuesAddedFunctions.class,
- ScriptableObject.DONTENUM );
- } catch ( Exception ex ) {
- throw new HopValueException( BaseMessages.getString(
- PKG, "ScriptValuesMod.Log.CouldNotAddDefaultFunctions" ), ex );
- }
-
- // Adding some Constants to the JavaScript
- try {
-
- data.scope.put( "SKIP_PIPELINE", data.scope, Integer.valueOf( SKIP_PIPELINE ) );
- data.scope.put( "ABORT_PIPELINE", data.scope, Integer.valueOf( ABORT_PIPELINE ) );
- data.scope.put( "ERROR_PIPELINE", data.scope, Integer.valueOf( ERROR_PIPELINE ) );
- data.scope.put( "CONTINUE_PIPELINE", data.scope, Integer.valueOf( CONTINUE_PIPELINE ) );
-
- } catch ( Exception ex ) {
- throw new HopValueException( BaseMessages.getString(PKG, "ScriptValuesMod.Log.CouldNotAddDefaultConstants" ), ex );
- }
-
- try {
- // Checking for StartScript
- if ( strStartScript != null && strStartScript.length() > 0 ) {
- Script startScript = data.cx.compileString( strStartScript, "pipeline_Start", 1, null );
- startScript.exec( data.cx, data.scope );
- if ( log.isDetailed() ) {
- logDetailed( ( "Start Script found!" ) );
- }
- } else {
- if ( log.isDetailed() ) {
- logDetailed( ( "No starting Script found!" ) );
- }
- }
- } catch ( Exception es ) {
- throw new HopValueException( BaseMessages.getString( PKG, "ScriptValuesMod.Log.ErrorProcessingStartScript" ), es );
-
- }
- // Now Compile our Script
- data.script = data.cx.compileString( strTransformScript, "script", 1, null );
- } catch ( Exception e ) {
- throw new HopValueException( BaseMessages.getString(
- PKG, "ScriptValuesMod.Log.CouldNotCompileJavascript" ), e );
- }
- }
-
- // Filling the defined TranVars with the Values from the Row
- //
- Object[] outputRow = RowDataUtil.resizeArray( row, data.outputRowMeta.size() );
-
- // Keep an index...
- int outputIndex = rowMeta.size();
-
- // Keep track of the changed values...
- //
- final Map<Integer, Value> usedRowValues;
-
- if ( meta.isCompatible() ) {
- usedRowValues = new Hashtable<Integer, Value>();
- } else {
- usedRowValues = null;
- }
-
- try {
- try {
- if ( meta.isCompatible() ) {
- Row v2Row = RowMeta.createOriginalRow( rowMeta, row );
- Scriptable jsV2Row = Context.toObject( v2Row, data.scope );
- data.scope.put( "row", data.scope, jsV2Row );
- v2Row.getUsedValueListeners().add( new ValueUsedListener() {
- public void valueIsUsed( int index, Value value ) {
- usedRowValues.put( index, value );
- }
- } );
- } else {
- Scriptable jsrow = Context.toObject( row, data.scope );
- data.scope.put( "row", data.scope, jsrow );
- }
-
- for ( int i = 0; i < data.fields_used.length; i++ ) {
- IValueMeta valueMeta = rowMeta.getValueMeta( data.fields_used[ i ] );
- Object valueData = row[ data.fields_used[ i ] ];
-
- if ( meta.isCompatible() ) {
- data.values_used[ i ] = valueMeta.createOriginalValue( valueData );
-
- Scriptable jsarg = Context.toObject( data.values_used[ i ], data.scope );
- data.scope.put( valueMeta.getName(), data.scope, jsarg );
- } else {
- Object normalStorageValueData = valueMeta.convertToNormalStorageType( valueData );
- Scriptable jsarg;
- if ( normalStorageValueData != null ) {
- jsarg = Context.toObject( normalStorageValueData, data.scope );
- } else {
- jsarg = null;
- }
- data.scope.put( valueMeta.getName(), data.scope, jsarg );
- }
- }
-
- // also add the meta information for the hole row
- Scriptable jsrowMeta = Context.toObject( rowMeta, data.scope );
- data.scope.put( "rowMeta", data.scope, jsrowMeta );
- } catch ( Exception e ) {
- throw new HopValueException( BaseMessages.getString( PKG, "ScriptValuesMod.Log.UnexpectedeError" ), e );
- }
-
- // Executing our Script
- data.script.exec( data.cx, data.scope );
-
- if ( bFirstRun ) {
- bFirstRun = false;
- // Check if we had a Pipeline Status
- Object tran_stat = data.scope.get( "pipeline_Status", data.scope );
- if ( tran_stat != ScriptableObject.NOT_FOUND ) {
- bWithPipelineStat = true;
- if ( log.isDetailed() ) {
- logDetailed( ( "tran_Status found. Checking pipeline status while script execution." ) );
- }
- } else {
- if ( log.isDetailed() ) {
- logDetailed( ( "No tran_Status found. Pipeline status checking not available." ) );
- }
- bWithPipelineStat = false;
- }
- }
-
- if ( bWithPipelineStat ) {
- iPipelineStat = (int) Context.toNumber( data.scope.get( "pipeline_Status", data.scope ) );
- } else {
- iPipelineStat = CONTINUE_PIPELINE;
- }
-
- if ( iPipelineStat == CONTINUE_PIPELINE ) {
- bRC = true;
- for ( int i = 0; i < meta.getFieldname().length; i++ ) {
- Object result = data.scope.get( meta.getFieldname()[ i ], data.scope );
- Object valueData = getValueFromJScript( result, i );
- if ( data.replaceIndex[ i ] < 0 ) {
- outputRow[ outputIndex++ ] = valueData;
- } else {
- outputRow[ data.replaceIndex[ i ] ] = valueData;
- }
- }
-
- // Also modify the "in-place" value changes:
- // --> the field.trim() type of changes...
- // As such we overwrite all the used fields again.
- //
- if ( meta.isCompatible() ) {
- for ( int i = 0; i < data.values_used.length; i++ ) {
- IValueMeta valueMeta = rowMeta.getValueMeta( data.fields_used[ i ] );
- outputRow[ data.fields_used[ i ] ] = valueMeta.getValueData( data.values_used[ i ] );
- }
-
- // Grab the variables in the "row" object too.
- //
- for ( Integer index : usedRowValues.keySet() ) {
- Value value = usedRowValues.get( index );
- IValueMeta valueMeta = rowMeta.getValueMeta( index );
- outputRow[ index ] = valueMeta.getValueData( value );
- }
-
- }
- putRow( data.outputRowMeta, outputRow );
- } else {
- switch ( iPipelineStat ) {
- case SKIP_PIPELINE:
- // eat this row.
- bRC = true;
- break;
- case ABORT_PIPELINE:
- if ( data.cx != null ) {
- Context.exit();
- }
- stopAll();
- setOutputDone();
- bRC = false;
- break;
- case ERROR_PIPELINE:
- if ( data.cx != null ) {
- Context.exit();
- }
- setErrors( 1 );
- stopAll();
- bRC = false;
- break;
- default:
- break;
- }
-
- // TODO: kick this "ERROR handling" junk out now that we have solid error handling in place.
- //
- }
- } catch ( Exception e ) {
- throw new HopValueException( BaseMessages.getString( PKG, "ScriptValuesMod.Log.JavascriptError" ), e );
- }
- return bRC;
- }
-
- public Object getValueFromJScript( Object result, int i ) throws HopValueException {
- String fieldName = meta.getFieldname()[ i ];
- if ( !Utils.isEmpty( fieldName ) ) {
- // res.setName(meta.getRename()[i]);
- // res.setType(meta.getType()[i]);
-
- try {
- return ( result == null ) ? null
- : JavaScriptUtils.convertFromJs( result, meta.getType()[ i ], fieldName );
- } catch ( Exception e ) {
- throw new HopValueException( BaseMessages.getString( PKG, "ScriptValuesMod.Log.JavascriptError" ), e );
- }
- } else {
- throw new HopValueException( "No name was specified for result value #" + ( i + 1 ) );
- }
- }
-
- public IRowMeta getOutputRowMeta() {
- return data.outputRowMeta;
- }
-
- public boolean processRow() throws HopException {
-
- meta = (ScriptValuesMetaMod) smi;
- data = (ScriptValuesModData) sdi;
-
- Object[] r = getRow(); // Get row from input rowset & set row busy!
- if ( r == null ) {
- // Modification for Additional End Function
- try {
- if ( data.cx != null ) {
- // Checking for EndScript
- if ( strEndScript != null && strEndScript.length() > 0 ) {
- Script endScript = data.cx.compileString( strEndScript, "pipeline_End", 1, null );
- endScript.exec( data.cx, data.scope );
- if ( log.isDetailed() ) {
- logDetailed( ( "End Script found!" ) );
- }
- } else {
- if ( log.isDetailed() ) {
- logDetailed( ( "No end Script found!" ) );
- }
- }
- }
- } catch ( Exception e ) {
- logError( BaseMessages.getString( PKG, "ScriptValuesMod.Log.UnexpectedeError" ) + " : " + e.toString() );
- logError( BaseMessages.getString( PKG, "ScriptValuesMod.Log.ErrorStackTrace" )
- + Const.CR + Const.getStackTracker( e ) );
- setErrors( 1 );
- stopAll();
- }
-
- try {
- if ( data.cx != null ) {
- Context.exit();
- }
- } catch ( Exception er ) {
- // Eat this error, it's typically : "Calling Context.exit without previous Context.enter"
- // logError(BaseMessages.getString(PKG, "System.Log.UnexpectedError"), er);
- }
-
- setOutputDone();
- return false;
- }
-
- // Getting the Row, with the Pipeline Status
- try {
- addValues( getInputRowMeta(), r );
- } catch ( HopValueException e ) {
- String location = null;
- if ( e.getCause() instanceof EvaluatorException ) {
- EvaluatorException ee = (EvaluatorException) e.getCause();
- location = "--> " + ee.lineNumber() + ":" + ee.columnNumber();
- }
-
- if ( getTransformMeta().isDoingErrorHandling() ) {
- putError( getInputRowMeta(), r, 1, e.getMessage() + Const.CR + location, null, "SCR-001" );
- bRC = true; // continue by all means, even on the first row and out of this ugly design
- } else {
- throw ( e );
- }
- }
-
- if ( checkFeedback( getLinesRead() ) ) {
- logBasic( BaseMessages.getString( PKG, "ScriptValuesMod.Log.LineNumber" ) + getLinesRead() );
- }
- return bRC;
- }
-
- public boolean init() {
- meta = (ScriptValuesMetaMod) smi;
- data = (ScriptValuesModData) sdi;
-
- if ( super.init() ) {
-
- // Add init code here.
- // Get the actual Scripts from our MetaData
- jsScripts = meta.getJSScripts();
- for ( int j = 0; j < jsScripts.length; j++ ) {
- switch ( jsScripts[ j ].getScriptType() ) {
- case ScriptValuesScript.TRANSFORM_SCRIPT:
- strTransformScript = jsScripts[ j ].getScript();
- break;
- case ScriptValuesScript.START_SCRIPT:
- strStartScript = jsScripts[ j ].getScript();
- break;
- case ScriptValuesScript.END_SCRIPT:
- strEndScript = jsScripts[ j ].getScript();
- break;
- default:
- break;
- }
- }
-
- return true;
- }
- return false;
- }
-
- public void.dispose() {
- try {
- if ( data.cx != null ) {
- Context.exit();
- }
- } catch ( Exception er ) {
- // Eat this error, it's typically : "Calling Context.exit without previous Context.enter"
- // logError(BaseMessages.getString(PKG, "System.Log.UnexpectedError"), er);
- }
-
- super.dispose();
- }
-
-}
diff --git a/archive-pipeline-transforms/src/main/java/engine/transforms/scriptvalues_mod/ScriptValuesModData.java b/archive-pipeline-transforms/src/main/java/engine/transforms/scriptvalues_mod/ScriptValuesModData.java
deleted file mode 100644
index 17e34b2..0000000
--- a/archive-pipeline-transforms/src/main/java/engine/transforms/scriptvalues_mod/ScriptValuesModData.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*! ******************************************************************************
- *
- * Hop : The Hop Orchestration Platform
- *
- * http://www.project-hop.org
- *
- *******************************************************************************
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************************/
-
-package org.apache.hop.pipeline.transforms.scriptvalues_mod;
-
-import org.apache.hop.compatibility.Value;
-import org.apache.hop.core.row.IRowMeta;
-import org.apache.hop.pipeline.transform.BaseTransformData;
-import org.apache.hop.pipeline.transform.ITransformData;
-import org.mozilla.javascript.Context;
-import org.mozilla.javascript.Script;
-import org.mozilla.javascript.Scriptable;
-
-/**
- * @author Matt
- * @since 24-jan-2005
- */
-public class ScriptValuesModData extends BaseTransformData implements ITransformData {
- public Context cx;
- public Scriptable scope;
- public Script script;
-
- public int[] fields_used;
- public Value[] values_used;
-
- public IRowMeta outputRowMeta;
- public int[] replaceIndex;
-
- public ScriptValuesModData() {
- super();
- cx = null;
- fields_used = null;
- }
-
- public void check( int i ) {
- System.out.println( i );
- }
-}
diff --git a/archive-pipeline-transforms/src/main/java/engine/transforms/scriptvalues_mod/ScriptValuesModDummy.java b/archive-pipeline-transforms/src/main/java/engine/transforms/scriptvalues_mod/ScriptValuesModDummy.java
deleted file mode 100644
index 17e32ee..0000000
--- a/archive-pipeline-transforms/src/main/java/engine/transforms/scriptvalues_mod/ScriptValuesModDummy.java
+++ /dev/null
@@ -1,441 +0,0 @@
-/*! ******************************************************************************
- *
- * Hop : The Hop Orchestration Platform
- *
- * http://www.project-hop.org
- *
- *******************************************************************************
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************************/
-
-package org.apache.hop.pipeline.transforms.scriptvalues_mod;
-
-import org.apache.hop.core.ResultFile;
-import org.apache.hop.core.RowSet;
-import org.apache.hop.core.exception.HopException;
-import org.apache.hop.core.exception.HopTransformException;
-import org.apache.hop.core.exception.HopValueException;
-import org.apache.hop.core.logging.LogChannelInterface;
-import org.apache.hop.core.row.IRowMeta;
-import org.apache.hop.core.variables.iVariables;
-import org.apache.hop.metastore.api.IMetaStore;
-import org.apache.hop.pipeline.Pipeline;
-import org.apache.hop.pipeline.PipelineMeta;
-import org.apache.hop.pipeline.transform.BaseTransformData.TransformExecutionStatus;
-import org.apache.hop.pipeline.transform.RowListener;
-import org.apache.hop.pipeline.transform.ITransformData;
-import org.apache.hop.pipeline.transform.ITransform;
-import org.apache.hop.pipeline.transform.TransformListener;
-import org.apache.hop.pipeline.transform.TransformMeta;
-import org.apache.hop.pipeline.transform.ITransform;
-
-import java.util.List;
-import java.util.Map;
-
-/**
- * Dummy class used for test().
- */
-public class ScriptValuesModDummy implements ITransform {
- private IRowMeta inputRowMeta;
- private IRowMeta outputRowMeta;
-
- public ScriptValuesModDummy( IRowMeta inputRowMeta, IRowMeta outputRowMeta ) {
- this.inputRowMeta = inputRowMeta;
- this.outputRowMeta = outputRowMeta;
- }
-
- public boolean processRow() throws HopException {
- return false;
- }
-
- public void addRowListener( RowListener rowListener ) {
- }
-
- public void.dispose() {
- }
-
- public long getErrors() {
- return 0;
- }
-
- public List<RowSet> getInputRowSets() {
- return null;
- }
-
- public long getLinesInput() {
- return 0;
- }
-
- public long getLinesOutput() {
- return 0;
- }
-
- public long getLinesRead() {
- return 0;
- }
-
- public long getLinesUpdated() {
- return 0;
- }
-
- public long getLinesWritten() {
- return 0;
- }
-
- public long getLinesRejected() {
- return 0;
- }
-
- public List<RowSet> getOutputRowSets() {
- return null;
- }
-
- public String getPartitionID() {
- return null;
- }
-
- public Object[] getRow() throws HopException {
- return null;
- }
-
- public List<RowListener> getRowListeners() {
- return null;
- }
-
- public String getTransformPluginId() {
- return null;
- }
-
- public String getTransformName() {
- return null;
- }
-
- public boolean init( ITransform transformMetaInterface, ITransformData iTransformData ) {
- return false;
- }
-
- public boolean isAlive() {
- return false;
- }
-
- public boolean isPartitioned() {
- return false;
- }
-
- public boolean isStopped() {
- return false;
- }
-
- public void markStart() {
- }
-
- public void markStop() {
- }
-
- public void putRow( IRowMeta rowMeta, Object[] row ) throws HopException {
- }
-
- public void removeRowListener( RowListener rowListener ) {
- }
-
- public void run() {
- }
-
- public void setErrors( long errors ) {
- }
-
- public void setOutputDone() {
- }
-
- public void setPartitionID( String partitionID ) {
- }
-
- public void start() {
- }
-
- public void stopAll() {
- }
-
- public void stopRunning( ITransform transformMetaInterface, ITransformData iTransformData ) throws HopException {
- }
-
- public void cleanup() {
- }
-
- public void pauseRunning() {
- }
-
- public void resumeRunning() {
- }
-
- public void copyVariablesFrom( iVariables variables ) {
- }
-
- public String environmentSubstitute( String aString ) {
- return null;
- }
-
- public String[] environmentSubstitute( String[] string ) {
- return null;
- }
-
- public String fieldSubstitute( String aString, IRowMeta rowMeta, Object[] rowData ) throws HopValueException {
- return null;
- }
-
- public boolean getBooleanValueOfVariable( String variableName, boolean defaultValue ) {
- return false;
- }
-
- public iVariables getParentVariableSpace() {
- return null;
- }
-
- public void setParentVariableSpace( iVariables parent ) {
- }
-
- public String getVariable( String variableName, String defaultValue ) {
- return defaultValue;
- }
-
- public String getVariable( String variableName ) {
- return null;
- }
-
- public void initializeVariablesFrom( iVariables parent ) {
- }
-
- public void injectVariables( Map<String, String> prop ) {
- }
-
- public String[] listVariables() {
- return null;
- }
-
- public void setVariable( String variableName, String variableValue ) {
- }
-
- public void shareVariablesWith( iVariables variables ) {
- }
-
- public IRowMeta getInputRowMeta() {
- return inputRowMeta;
- }
-
- public IRowMeta getOutputRowMeta() {
- return outputRowMeta;
- }
-
- public void initBeforeStart() throws HopTransformException {
- }
-
- public void setLinesRejected( long linesRejected ) {
- }
-
- public int getCopy() {
- return 0;
- }
-
- public void addTransformListener( TransformListener transformListener ) {
- }
-
- public boolean isMapping() {
- return false;
- }
-
- public TransformMeta getTransformMeta() {
- return null;
- }
-
- public Pipeline getPipeline() {
- return null;
- }
-
- public PipelineMeta getPipelineMeta() {
- return null;
- }
-
- @Override public LogChannelInterface getLogChannel() {
- return null;
- }
-
- @Override public String getLogText() {
- return null;
- }
-
- @Override public String getName() {
- return null;
- }
-
- @Override public int getCopyNr() {
- return 0;
- }
-
- @Override public String getLogChannelId() {
- return null;
- }
-
- @Override public boolean isSelected() {
- return false;
- }
-
- public boolean isRunning() {
- // TODO Auto-generated method stub
- return false;
- }
-
- public boolean isUsingThreadPriorityManagment() {
- // TODO Auto-generated method stub
- return false;
- }
-
- public void setUsingThreadPriorityManagment( boolean usingThreadPriorityManagment ) {
- // TODO Auto-generated method stub
-
- }
-
- public void setRunning( boolean running ) {
- // TODO Auto-generated method stub
-
- }
-
- public void setStopped( boolean stopped ) {
- // TODO Auto-generated method stub
-
- }
-
- @Override public void setSafeStopped( boolean stopped ) {
- // TODO Auto-generated method stub
- }
-
- public int rowsetInputSize() {
- // TODO Auto-generated method stub
- return 0;
- }
-
- public int rowsetOutputSize() {
- // TODO Auto-generated method stub
- return 0;
- }
-
- public long getProcessed() {
- // TODO Auto-generated method stub
- return 0;
- }
-
- public Map<String, ResultFile> getResultFiles() {
- // TODO Auto-generated method stub
- return null;
- }
-
- public long getRuntime() {
- // TODO Auto-generated method stub
- return 0;
- }
-
- public TransformExecutionStatus getStatus() {
- // TODO Auto-generated method stub
- return null;
- }
-
- public boolean isPaused() {
- // TODO Auto-generated method stub
- return false;
- }
-
- public void identifyErrorOutput() {
- // TODO Auto-generated method stub
-
- }
-
- public void setPartitioned( boolean partitioned ) {
- // TODO Auto-generated method stub
-
- }
-
- public void setRepartitioning( int partitioningMethod ) {
- // TODO Auto-generated method stub
-
- }
-
- public boolean canProcessOneRow() {
- // TODO Auto-generated method stub
- return false;
- }
-
- public boolean isWaitingForData() {
- // TODO Auto-generated method stub
- return false;
- }
-
- public void setWaitingForData( boolean waitingForData ) {
- // TODO Auto-generated method stub
- }
-
- public boolean isIdle() {
- // TODO Auto-generated method stub
- return false;
- }
-
- public boolean isPassingData() {
- // TODO Auto-generated method stub
- return false;
- }
-
- public void setPassingData( boolean passingData ) {
- // TODO Auto-generated method stub
-
- }
-
- public void batchComplete() throws HopException {
- // TODO Auto-generated method stub
- }
-
- @Override
- public void setMetaStore( IMetaStore metaStore ) {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public IMetaStore getMetaStore() {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public int getCurrentInputRowSetNr() {
- // TODO Auto-generated method stub
- return 0;
- }
-
- @Override
- public void setCurrentOutputRowSetNr( int index ) {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public int getCurrentOutputRowSetNr() {
- // TODO Auto-generated method stub
- return 0;
- }
-
- @Override
- public void setCurrentInputRowSetNr( int index ) {
- // TODO Auto-generated method stub
-
- }
-}
diff --git a/archive-pipeline-transforms/src/main/java/engine/transforms/scriptvalues_mod/ScriptValuesScript.java b/archive-pipeline-transforms/src/main/java/engine/transforms/scriptvalues_mod/ScriptValuesScript.java
deleted file mode 100644
index 31dce58..0000000
--- a/archive-pipeline-transforms/src/main/java/engine/transforms/scriptvalues_mod/ScriptValuesScript.java
+++ /dev/null
@@ -1,115 +0,0 @@
-/*! ******************************************************************************
- *
- * Hop : The Hop Orchestration Platform
- *
- * http://www.project-hop.org
- *
- *******************************************************************************
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************************/
-
-package org.apache.hop.pipeline.transforms.scriptvalues_mod;
-
-import org.apache.hop.core.injection.Injection;
-
-public class ScriptValuesScript {
-
- public static final int NORMAL_SCRIPT = -1;
- public static final int TRANSFORM_SCRIPT = 0;
- public static final int START_SCRIPT = 1;
- public static final int END_SCRIPT = 2;
-
- private int iScriptType;
- private boolean bScriptActive;
-
- @Injection( name = "SCRIPT_NAME", group = "SCRIPTS" )
- private String sScriptName;
-
- @Injection( name = "SCRIPT", group = "SCRIPTS" )
- private String sScript;
-
- public ScriptValuesScript() {
- }
-
- // private Date dModDate;
- // private Date dFirstDate;
-
- public ScriptValuesScript( int iScriptType, String sScriptName, String sScript ) {
- super();
- this.iScriptType = iScriptType;
- this.sScriptName = sScriptName;
- this.sScript = sScript;
- bScriptActive = true;
- // dModDate = new Date();
- // dFirstDate = new Date();
- }
-
- public int getScriptType() {
- return iScriptType;
- }
-
- public void setScriptType( int iScriptType ) {
- this.iScriptType = iScriptType;
- }
-
- public String getScript() {
- return this.sScript;
- }
-
- public void setScript( String sScript ) {
- this.sScript = sScript;
- }
-
- public String getScriptName() {
- return sScriptName;
- }
-
- public void setScriptName( String sScriptName ) {
- this.sScriptName = sScriptName;
- }
-
- public boolean isTransformScript() {
- if ( this.bScriptActive && this.iScriptType == TRANSFORM_SCRIPT ) {
- return true;
- } else {
- return false;
- }
- }
-
- public boolean isStartScript() {
- if ( this.bScriptActive && this.iScriptType == START_SCRIPT ) {
- return true;
- } else {
- return false;
- }
- }
-
- public boolean isEndScript() {
- if ( this.bScriptActive && this.iScriptType == END_SCRIPT ) {
- return true;
- } else {
- return false;
- }
- }
-
- public boolean isActive() {
- return bScriptActive;
- }
-
- public String toString() {
- return String.format( "ScriptValuesScript: (%d, %s, %s)", iScriptType, sScriptName, sScript );
- }
-
-}
diff --git a/assemblies/plugins/dist/pom.xml b/assemblies/plugins/dist/pom.xml
index 1a6f116..4b27763 100644
--- a/assemblies/plugins/dist/pom.xml
+++ b/assemblies/plugins/dist/pom.xml
@@ -1620,6 +1620,19 @@
<dependency>
<groupId>org.hop</groupId>
+ <artifactId>hop-assemblies-plugins-transforms-syslog</artifactId>
+ <version>${hop-plugins-transforms.version}</version>
+ <type>zip</type>
+ <exclusions>
+ <exclusion>
+ <groupId>*</groupId>
+ <artifactId>*</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+
+ <dependency>
+ <groupId>org.hop</groupId>
<artifactId>hop-assemblies-plugins-transforms-tablecompare</artifactId>
<version>${hop-plugins-transforms.version}</version>
<type>zip</type>
@@ -1735,6 +1748,19 @@
</exclusions>
</dependency>
+ <dependency>
+ <groupId>org.hop</groupId>
+ <artifactId>hop-assemblies-plugins-transforms-writetolog</artifactId>
+ <version>${hop-plugins-transforms.version}</version>
+ <type>zip</type>
+ <exclusions>
+ <exclusion>
+ <groupId>*</groupId>
+ <artifactId>*</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+
<!-- Database plugins -->
diff --git a/assemblies/plugins/transforms/pom.xml b/assemblies/plugins/transforms/pom.xml
index 241109b..0fa2d25 100644
--- a/assemblies/plugins/transforms/pom.xml
+++ b/assemblies/plugins/transforms/pom.xml
@@ -83,6 +83,7 @@
<module>sortedmerge</module>
<module>sql</module>
<module>streamlookup</module>
+ <module>syslog</module>
<module>switchcase</module>
<module>tablecompare</module>
<module>tableexists</module>
@@ -93,6 +94,7 @@
<module>uniquerowsbyhashset</module>
<module>update</module>
<module>valuemapper</module>
+ <module>writetolog</module>
</modules>
</project>
\ No newline at end of file
diff --git a/assemblies/plugins/transforms/syslog/pom.xml b/assemblies/plugins/transforms/syslog/pom.xml
new file mode 100644
index 0000000..3c7b7f2
--- /dev/null
+++ b/assemblies/plugins/transforms/syslog/pom.xml
@@ -0,0 +1,60 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.hop</groupId>
+ <artifactId>hop-assemblies-plugins-transforms</artifactId>
+ <version>0.20-SNAPSHOT</version>
+ </parent>
+
+
+ <artifactId>hop-assemblies-plugins-transforms-syslog</artifactId>
+ <version>0.20-SNAPSHOT</version>
+ <packaging>pom</packaging>
+
+ <name>Hop Assemblies Plugins Transforms Syslog Message</name>
+ <description></description>
+
+ <properties>
+ <syslog4j.version>0.9.46</syslog4j.version>
+ <snmp4j.version>1.9.3d</snmp4j.version>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.hop</groupId>
+ <artifactId>hop-transform-syslog</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.hop</groupId>
+ <artifactId>hop-action-syslog</artifactId>
+ <version>0.20-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.syslog4j</groupId>
+ <artifactId>syslog4j</artifactId>
+ <version>${syslog4j.version}</version>
+ <exclusions>
+ <exclusion>
+ <groupId>*</groupId>
+ <artifactId>*</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.snmp4j</groupId>
+ <artifactId>snmp4j</artifactId>
+ <version>${snmp4j.version}</version>
+ <exclusions>
+ <exclusion>
+ <groupId>*</groupId>
+ <artifactId>*</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ </dependencies>
+</project>
\ No newline at end of file
diff --git a/assemblies/plugins/transforms/syslog/src/assembly/assembly.xml b/assemblies/plugins/transforms/syslog/src/assembly/assembly.xml
new file mode 100644
index 0000000..413eda0
--- /dev/null
+++ b/assemblies/plugins/transforms/syslog/src/assembly/assembly.xml
@@ -0,0 +1,53 @@
+<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd">
+ <id>hop-assemblies-plugins-transforms-syslog</id>
+ <formats>
+ <format>zip</format>
+ </formats>
+ <baseDirectory>transforms/syslog</baseDirectory>
+ <files>
+ <file>
+ <source>${project.basedir}/src/main/resources/version.xml</source>
+ <outputDirectory>.</outputDirectory>
+ <filtered>true</filtered>
+ </file>
+ </files>
+ <fileSets>
+ <fileSet>
+ <outputDirectory>lib</outputDirectory>
+ <excludes>
+ <exclude>**/*</exclude>
+ </excludes>
+ </fileSet>
+ </fileSets>
+ <dependencySets>
+ <dependencySet>
+ <useProjectArtifact>false</useProjectArtifact>
+ <includes>
+ <include>org.hop:hop-transform-syslog:jar</include>
+ </includes>
+ </dependencySet>
+ <dependencySet>
+ <useProjectArtifact>false</useProjectArtifact>
+ <outputDirectory>lib</outputDirectory>
+ <includes>
+ <include>org.hop:hop-action-syslog:jar</include>
+ </includes>
+ </dependencySet>
+ <dependencySet>
+ <useProjectArtifact>false</useProjectArtifact>
+ <outputDirectory>lib</outputDirectory>
+ <includes>
+ <include>org.syslog4j:syslog4j:jar</include>
+ </includes>
+ </dependencySet>
+ <dependencySet>
+ <useProjectArtifact>false</useProjectArtifact>
+ <outputDirectory>lib</outputDirectory>
+ <includes>
+ <include>org.snmp4j:snmp4j:jar</include>
+ </includes>
+ </dependencySet>
+ </dependencySets>
+</assembly>
\ No newline at end of file
diff --git a/assemblies/plugins/transforms/syslog/src/main/resources/version.xml b/assemblies/plugins/transforms/syslog/src/main/resources/version.xml
new file mode 100644
index 0000000..7724ea1
--- /dev/null
+++ b/assemblies/plugins/transforms/syslog/src/main/resources/version.xml
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<version>${project.version}</version>
\ No newline at end of file
diff --git a/assemblies/plugins/transforms/writetolog/pom.xml b/assemblies/plugins/transforms/writetolog/pom.xml
new file mode 100644
index 0000000..220b8b5
--- /dev/null
+++ b/assemblies/plugins/transforms/writetolog/pom.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.hop</groupId>
+ <artifactId>hop-assemblies-plugins-transforms</artifactId>
+ <version>0.20-SNAPSHOT</version>
+ </parent>
+
+
+ <artifactId>hop-assemblies-plugins-transforms-writetolog</artifactId>
+ <version>0.20-SNAPSHOT</version>
+ <packaging>pom</packaging>
+
+ <name>Hop Assemblies Plugins Transforms Write To Log</name>
+ <description></description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.hop</groupId>
+ <artifactId>hop-transform-writetolog</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+</project>
\ No newline at end of file
diff --git a/assemblies/plugins/transforms/writetolog/src/assembly/assembly.xml b/assemblies/plugins/transforms/writetolog/src/assembly/assembly.xml
new file mode 100644
index 0000000..1dee0d5
--- /dev/null
+++ b/assemblies/plugins/transforms/writetolog/src/assembly/assembly.xml
@@ -0,0 +1,32 @@
+<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd">
+ <id>hop-assemblies-plugins-transforms-writetolog</id>
+ <formats>
+ <format>zip</format>
+ </formats>
+ <baseDirectory>transforms/writetolog</baseDirectory>
+ <files>
+ <file>
+ <source>${project.basedir}/src/main/resources/version.xml</source>
+ <outputDirectory>.</outputDirectory>
+ <filtered>true</filtered>
+ </file>
+ </files>
+ <fileSets>
+ <fileSet>
+ <outputDirectory>lib</outputDirectory>
+ <excludes>
+ <exclude>**/*</exclude>
+ </excludes>
+ </fileSet>
+ </fileSets>
+ <dependencySets>
+ <dependencySet>
+ <useProjectArtifact>false</useProjectArtifact>
+ <includes>
+ <include>org.hop:hop-transform-writetolog:jar</include>
+ </includes>
+ </dependencySet>
+ </dependencySets>
+</assembly>
\ No newline at end of file
diff --git a/assemblies/plugins/transforms/writetolog/src/main/resources/version.xml b/assemblies/plugins/transforms/writetolog/src/main/resources/version.xml
new file mode 100644
index 0000000..7724ea1
--- /dev/null
+++ b/assemblies/plugins/transforms/writetolog/src/main/resources/version.xml
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<version>${project.version}</version>
\ No newline at end of file
diff --git a/plugins/transforms/pom.xml b/plugins/transforms/pom.xml
index 291e372..027160d 100644
--- a/plugins/transforms/pom.xml
+++ b/plugins/transforms/pom.xml
@@ -117,6 +117,7 @@
<module>sql</module>
<module>streamlookup</module>
<module>switchcase</module>
+ <module>syslog</module>
<module>tablecompare</module>
<module>tableexists</module>
<module>tableoutput</module>
@@ -126,6 +127,7 @@
<module>uniquerowsbyhashset</module>
<module>update</module>
<module>valuemapper</module>
+ <module>writetolog</module>
</modules>
</profile>
diff --git a/plugins/transforms/syslog/pom.xml b/plugins/transforms/syslog/pom.xml
new file mode 100644
index 0000000..d7fe047
--- /dev/null
+++ b/plugins/transforms/syslog/pom.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0"?>
+<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
+ xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.hop</groupId>
+ <artifactId>hop-plugins-transforms</artifactId>
+ <version>0.20-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>hop-transform-syslog</artifactId>
+ <packaging>jar</packaging>
+
+ <name>Hop Plugins Transforms Syslog</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.hop</groupId>
+ <artifactId>hop-action-syslog</artifactId>
+ <version>0.20-SNAPSHOT</version>
+ <scope>compile</scope>
+ </dependency>
+ </dependencies>
+
+</project>
\ No newline at end of file
diff --git a/archive-pipeline-transforms/src/main/java/engine/transforms/syslog/SyslogMessage.java b/plugins/transforms/syslog/src/main/java/org/apache/hop/pipeline/transforms/syslog/SyslogMessage.java
similarity index 90%
rename from archive-pipeline-transforms/src/main/java/engine/transforms/syslog/SyslogMessage.java
rename to plugins/transforms/syslog/src/main/java/org/apache/hop/pipeline/transforms/syslog/SyslogMessage.java
index a39bed1..1445980 100644
--- a/archive-pipeline-transforms/src/main/java/engine/transforms/syslog/SyslogMessage.java
+++ b/plugins/transforms/syslog/src/main/java/org/apache/hop/pipeline/transforms/syslog/SyslogMessage.java
@@ -30,7 +30,6 @@
import org.apache.hop.pipeline.Pipeline;
import org.apache.hop.pipeline.PipelineMeta;
import org.apache.hop.pipeline.transform.BaseTransform;
-import org.apache.hop.pipeline.transform.ITransformData;
import org.apache.hop.pipeline.transform.TransformMeta;
import org.apache.hop.pipeline.transform.ITransform;
import org.productivity.java.syslog4j.SyslogConstants;
@@ -45,20 +44,15 @@
* @since 03-Juin-2008
*/
-public class SyslogMessage extends BaseTransform implements ITransform {
+public class SyslogMessage extends BaseTransform<SyslogMessageMeta, SyslogMessageData> implements ITransform<SyslogMessageMeta, SyslogMessageData> {
private static Class<?> PKG = SyslogMessageMeta.class; // for i18n purposes, needed by Translator!!
- private SyslogMessageMeta meta;
- private SyslogMessageData data;
-
- public SyslogMessage( TransformMeta transformMeta, ITransformData data, int copyNr, PipelineMeta pipelineMeta,
- Pipeline pipeline ) {
+ public SyslogMessage(TransformMeta transformMeta, SyslogMessageMeta meta, SyslogMessageData data, int copyNr, PipelineMeta pipelineMeta,
+ Pipeline pipeline ) {
super( transformMeta, meta, data, copyNr, pipelineMeta, pipeline );
}
public boolean processRow() throws HopException {
- meta = (SyslogMessageMeta) smi;
- data = (SyslogMessageData) sdi;
Object[] r = getRow(); // Get row from input rowset & set row busy!
if ( r == null ) { // no more input to be expected...
@@ -127,8 +121,6 @@
}
public boolean init() {
- meta = (SyslogMessageMeta) smi;
- data = (SyslogMessageData) sdi;
if ( super.init() ) {
String servername = environmentSubstitute( meta.getServerName() );
@@ -178,9 +170,7 @@
return new UDPNetSyslog();
}
- public void.dispose() {
- meta = (SyslogMessageMeta) smi;
- data = (SyslogMessageData) sdi;
+ public void dispose() {
if ( data.syslog != null ) {
// release resource on syslog
diff --git a/archive-pipeline-transforms/src/main/java/engine/transforms/syslog/SyslogMessageData.java b/plugins/transforms/syslog/src/main/java/org/apache/hop/pipeline/transforms/syslog/SyslogMessageData.java
similarity index 100%
rename from archive-pipeline-transforms/src/main/java/engine/transforms/syslog/SyslogMessageData.java
rename to plugins/transforms/syslog/src/main/java/org/apache/hop/pipeline/transforms/syslog/SyslogMessageData.java
diff --git a/archive-pipeline-transforms/src/main/java/ui/steps/syslog/SyslogMessageDialog.java b/plugins/transforms/syslog/src/main/java/org/apache/hop/pipeline/transforms/syslog/SyslogMessageDialog.java
similarity index 98%
rename from archive-pipeline-transforms/src/main/java/ui/steps/syslog/SyslogMessageDialog.java
rename to plugins/transforms/syslog/src/main/java/org/apache/hop/pipeline/transforms/syslog/SyslogMessageDialog.java
index e1c9edc..9a9292e 100644
--- a/archive-pipeline-transforms/src/main/java/ui/steps/syslog/SyslogMessageDialog.java
+++ b/plugins/transforms/syslog/src/main/java/org/apache/hop/pipeline/transforms/syslog/SyslogMessageDialog.java
@@ -20,9 +20,10 @@
*
******************************************************************************/
-package org.apache.hop.ui.pipeline.transforms.syslog;
+package org.apache.hop.pipeline.transforms.syslog;
import org.apache.hop.core.Const;
+import org.apache.hop.core.annotations.PluginDialog;
import org.apache.hop.core.exception.HopException;
import org.apache.hop.core.row.IRowMeta;
import org.apache.hop.core.util.Utils;
@@ -31,7 +32,6 @@
import org.apache.hop.pipeline.PipelineMeta;
import org.apache.hop.pipeline.transform.BaseTransformMeta;
import org.apache.hop.pipeline.transform.ITransformDialog;
-import org.apache.hop.pipeline.transforms.syslog.SyslogMessageMeta;
import org.apache.hop.ui.core.dialog.ErrorDialog;
import org.apache.hop.ui.core.widget.ComboVar;
import org.apache.hop.ui.core.widget.LabelTextVar;
@@ -62,6 +62,12 @@
import java.net.InetAddress;
+@PluginDialog(
+ id = "SyslogMessage",
+ image = "syslogmessage.svg",
+ pluginType = PluginDialog.PluginType.TRANSFORM,
+ documentationUrl = ""
+)
public class SyslogMessageDialog extends BaseTransformDialog implements ITransformDialog {
private static Class<?> PKG = SyslogMessageMeta.class; // for i18n purposes, needed by Translator!!
diff --git a/archive-pipeline-transforms/src/main/java/engine/transforms/syslog/SyslogMessageMeta.java b/plugins/transforms/syslog/src/main/java/org/apache/hop/pipeline/transforms/syslog/SyslogMessageMeta.java
similarity index 88%
rename from archive-pipeline-transforms/src/main/java/engine/transforms/syslog/SyslogMessageMeta.java
rename to plugins/transforms/syslog/src/main/java/org/apache/hop/pipeline/transforms/syslog/SyslogMessageMeta.java
index ddb9ede..6845b78 100644
--- a/archive-pipeline-transforms/src/main/java/engine/transforms/syslog/SyslogMessageMeta.java
+++ b/plugins/transforms/syslog/src/main/java/org/apache/hop/pipeline/transforms/syslog/SyslogMessageMeta.java
@@ -23,26 +23,30 @@
package org.apache.hop.pipeline.transforms.syslog;
import org.apache.hop.core.CheckResult;
-import org.apache.hop.core.CheckResultInterface;
+import org.apache.hop.core.ICheckResult;
+import org.apache.hop.core.annotations.Transform;
import org.apache.hop.core.exception.HopXmlException;
import org.apache.hop.core.row.IRowMeta;
import org.apache.hop.core.util.Utils;
-import org.apache.hop.core.variables.iVariables;
+import org.apache.hop.core.variables.IVariables;
import org.apache.hop.core.xml.XmlHandler;
import org.apache.hop.i18n.BaseMessages;
+import org.apache.hop.pipeline.transform.*;
import org.apache.hop.workflow.actions.syslog.SyslogDefs;
import org.apache.hop.metastore.api.IMetaStore;
import org.apache.hop.pipeline.Pipeline;
import org.apache.hop.pipeline.PipelineMeta;
-import org.apache.hop.pipeline.transform.BaseTransformMeta;
-import org.apache.hop.pipeline.transform.ITransformData;
-import org.apache.hop.pipeline.transform.ITransform;
-import org.apache.hop.pipeline.transform.TransformMeta;
import org.w3c.dom.Node;
import java.util.List;
-public class SyslogMessageMeta extends BaseTransformMeta implements ITransform {
+@Transform( id = "SyslogMessage",
+ i18nPackageName = "org.apache.hop.pipeline.transforms.syslog",
+ name = "BaseTransform.TypeLongDesc.SyslogMessage",
+ description = "BaseTransform.TypeTooltipDesc.SyslogMessage",
+ categoryDescription = "i18n:org.apache.hop.pipeline.transform:BaseTransform.Category.Utility"
+)
+public class SyslogMessageMeta extends BaseTransformMeta implements ITransformMeta<SyslogMessage, SyslogMessageData> {
private static Class<?> PKG = SyslogMessageMeta.class; // for i18n purposes, needed by Translator!!
/**
@@ -71,6 +75,11 @@
return retval;
}
+ @Override
+ public ITransform createTransform(TransformMeta transformMeta, SyslogMessageData data, int copyNr, PipelineMeta pipelineMeta, Pipeline pipeline) {
+ return new SyslogMessage( transformMeta, this, data, copyNr, pipelineMeta, pipeline );
+ }
+
public void setDefault() {
messagefieldname = null;
port = String.valueOf( SyslogDefs.DEFAULT_PORT );
@@ -238,8 +247,8 @@
}
}
- public void check( List<CheckResultInterface> remarks, PipelineMeta pipelineMeta, TransformMeta transformMeta,
- IRowMeta prev, String[] input, String[] output, IRowMeta info, iVariables variables,
+ public void check( List<ICheckResult> remarks, PipelineMeta pipelineMeta, TransformMeta transformMeta,
+ IRowMeta prev, String[] input, String[] output, IRowMeta info, IVariables variables,
IMetaStore metaStore ) {
CheckResult cr;
String error_message = "";
@@ -270,12 +279,7 @@
}
- public ITransform getTransform( TransformMeta transformMeta, ITransformData data, int cnr,
- PipelineMeta pipelineMeta, Pipeline pipeline ) {
- return new SyslogMessage( transformMeta, this, data, cnr, pipelineMeta, pipeline );
- }
-
- public ITransformData getTransformData() {
+ public SyslogMessageData getTransformData() {
return new SyslogMessageData();
}
diff --git a/archive-pipeline-transforms/src/main/resources/engine/steps/syslog/messages/messages_en_US.properties b/plugins/transforms/syslog/src/main/resources/org/apache/hop/pipeline/transforms/syslog/messages/messages_en_US.properties
similarity index 95%
rename from archive-pipeline-transforms/src/main/resources/engine/steps/syslog/messages/messages_en_US.properties
rename to plugins/transforms/syslog/src/main/resources/org/apache/hop/pipeline/transforms/syslog/messages/messages_en_US.properties
index 8b20dfb..d7bea2d 100644
--- a/archive-pipeline-transforms/src/main/resources/engine/steps/syslog/messages/messages_en_US.properties
+++ b/plugins/transforms/syslog/src/main/resources/org/apache/hop/pipeline/transforms/syslog/messages/messages_en_US.properties
@@ -1,3 +1,6 @@
+BaseTransform.TypeLongDesc.SyslogMessage=Send message to syslog
+BaseTransform.TypeTooltipDesc.SyslogMessage=Send message to syslog server
+
#File generated by Hop Translator for package 'org.apache.hop.pipeline.transforms.syslog' in locale 'en_US'
#
#
diff --git a/archive-pipeline-transforms/src/main/resources/engine/steps/syslog/messages/messages_fr_FR.properties b/plugins/transforms/syslog/src/main/resources/org/apache/hop/pipeline/transforms/syslog/messages/messages_fr_FR.properties
similarity index 95%
rename from archive-pipeline-transforms/src/main/resources/engine/steps/syslog/messages/messages_fr_FR.properties
rename to plugins/transforms/syslog/src/main/resources/org/apache/hop/pipeline/transforms/syslog/messages/messages_fr_FR.properties
index a501754..f0f164e 100644
--- a/archive-pipeline-transforms/src/main/resources/engine/steps/syslog/messages/messages_fr_FR.properties
+++ b/plugins/transforms/syslog/src/main/resources/org/apache/hop/pipeline/transforms/syslog/messages/messages_fr_FR.properties
@@ -1,3 +1,6 @@
+BaseTransform.TypeLongDesc.SyslogMessage=Envoi d''information via syslog
+BaseTransform.TypeTooltipDesc.SyslogMessage=Envoi d''information vers un serveur Syslog
+
#File generated by Hop Translator for package 'org.apache.hop.pipeline.transforms.syslog' in locale 'fr_FR'
diff --git a/archive-pipeline-transforms/src/main/resources/engine/steps/syslog/messages/messages_it_IT.properties b/plugins/transforms/syslog/src/main/resources/org/apache/hop/pipeline/transforms/syslog/messages/messages_it_IT.properties
similarity index 100%
rename from archive-pipeline-transforms/src/main/resources/engine/steps/syslog/messages/messages_it_IT.properties
rename to plugins/transforms/syslog/src/main/resources/org/apache/hop/pipeline/transforms/syslog/messages/messages_it_IT.properties
diff --git a/archive-pipeline-transforms/src/main/resources/engine/steps/syslog/messages/messages_ja_JP.properties b/plugins/transforms/syslog/src/main/resources/org/apache/hop/pipeline/transforms/syslog/messages/messages_ja_JP.properties
similarity index 93%
rename from archive-pipeline-transforms/src/main/resources/engine/steps/syslog/messages/messages_ja_JP.properties
rename to plugins/transforms/syslog/src/main/resources/org/apache/hop/pipeline/transforms/syslog/messages/messages_ja_JP.properties
index 1d469c8..faac428 100644
--- a/archive-pipeline-transforms/src/main/resources/engine/steps/syslog/messages/messages_ja_JP.properties
+++ b/plugins/transforms/syslog/src/main/resources/org/apache/hop/pipeline/transforms/syslog/messages/messages_ja_JP.properties
@@ -1,3 +1,6 @@
+BaseTransform.TypeLongDesc.SyslogMessage=\u30B7\u30B9\u30C6\u30E0\u30ED\u30B0\u60C5\u5831\u9001\u4FE1
+BaseTransform.TypeTooltipDesc.SyslogMessage=Send message to Syslog\n\u30B7\u30B9\u30C6\u30E0\u30ED\u30B0\u30B5\u30FC\u30D0\u30FC\u306B\u30E1\u30C3\u30BB\u30FC\u30B8\u9001\u4FE1
+
#File generated by Hop Translator for package 'org.apache.hop.pipeline.transforms.syslog' in locale 'en_US'
#
#
diff --git a/archive-pipeline-transforms/src/main/resources/engine/steps/syslog/messages/messages_ko_KR.properties b/plugins/transforms/syslog/src/main/resources/org/apache/hop/pipeline/transforms/syslog/messages/messages_ko_KR.properties
similarity index 100%
rename from archive-pipeline-transforms/src/main/resources/engine/steps/syslog/messages/messages_ko_KR.properties
rename to plugins/transforms/syslog/src/main/resources/org/apache/hop/pipeline/transforms/syslog/messages/messages_ko_KR.properties
diff --git a/archive-pipeline-transforms/src/main/resources/engine/steps/syslog/messages/messages_zh_CN.properties b/plugins/transforms/syslog/src/main/resources/org/apache/hop/pipeline/transforms/syslog/messages/messages_zh_CN.properties
similarity index 97%
rename from archive-pipeline-transforms/src/main/resources/engine/steps/syslog/messages/messages_zh_CN.properties
rename to plugins/transforms/syslog/src/main/resources/org/apache/hop/pipeline/transforms/syslog/messages/messages_zh_CN.properties
index 85666d3..7ade07c 100644
--- a/archive-pipeline-transforms/src/main/resources/engine/steps/syslog/messages/messages_zh_CN.properties
+++ b/plugins/transforms/syslog/src/main/resources/org/apache/hop/pipeline/transforms/syslog/messages/messages_zh_CN.properties
@@ -1,3 +1,5 @@
+BaseTransform.TypeLongDesc.SyslogMessage=\u53D1\u9001\u4FE1\u606F\u81F3syslog
+
#File generated by Hop Translator for package 'org.apache.hop.pipeline.transforms.syslog' in locale 'en_US'
#
#
diff --git a/ui/src/main/resources/ui/images/SYL.svg b/plugins/transforms/syslog/src/main/resources/syslogmessage.svg
similarity index 100%
rename from ui/src/main/resources/ui/images/SYL.svg
rename to plugins/transforms/syslog/src/main/resources/syslogmessage.svg
diff --git a/archive-pipeline-transforms/src/test/java/engine/transforms/syslog/SyslogMessageConcurrentTest.java b/plugins/transforms/syslog/src/test/java/org/apache/hop/pipeline/transforms/syslog/SyslogMessageConcurrentTest.java
similarity index 90%
rename from archive-pipeline-transforms/src/test/java/engine/transforms/syslog/SyslogMessageConcurrentTest.java
rename to plugins/transforms/syslog/src/test/java/org/apache/hop/pipeline/transforms/syslog/SyslogMessageConcurrentTest.java
index fe1596b..f4918b8 100644
--- a/archive-pipeline-transforms/src/test/java/engine/transforms/syslog/SyslogMessageConcurrentTest.java
+++ b/plugins/transforms/syslog/src/test/java/org/apache/hop/pipeline/transforms/syslog/SyslogMessageConcurrentTest.java
@@ -24,11 +24,10 @@
import org.apache.hop.core.exception.HopException;
import org.apache.hop.core.exception.HopTransformException;
-import org.apache.hop.core.logging.LoggingObjectInterface;
+import org.apache.hop.core.logging.ILoggingObject;
import org.apache.hop.core.row.IRowMeta;
import org.apache.hop.pipeline.Pipeline;
import org.apache.hop.pipeline.PipelineMeta;
-import org.apache.hop.pipeline.transform.ITransformData;
import org.apache.hop.pipeline.transform.TransformMeta;
import org.apache.hop.pipeline.transforms.mock.TransformMockHelper;
import org.junit.After;
@@ -61,7 +60,7 @@
countDownLatch = new CountDownLatch( 1 );
transformMockHelper = new TransformMockHelper<SyslogMessageMeta, SyslogMessageData>( "SYSLOG_MESSAGE TEST", SyslogMessageMeta.class,
SyslogMessageData.class );
- when( transformMockHelper.logChannelFactory.create( any(), any( LoggingObjectInterface.class ) ) ).thenReturn(
+ when( transformMockHelper.logChannelFactory.create( any(), any( ILoggingObject.class ) ) ).thenReturn(
transformMockHelper.logChannelInterface );
when( transformMockHelper.iTransformMeta.getServerName() ).thenReturn( "localhost" );
when( transformMockHelper.iTransformMeta.getMessageFieldName() ).thenReturn( "message field" );
@@ -93,7 +92,7 @@
SyslogMessageMeta syslogMessageMeta = null;
- public SyslogMessageTask( TransformMeta transformMeta, ITransformData data, int copyNr, PipelineMeta pipelineMeta, Pipeline pipeline, SyslogMessageMeta processRowsITransform ) {
+ public SyslogMessageTask( TransformMeta transformMeta, SyslogMessageMeta meta, SyslogMessageData data, int copyNr, PipelineMeta pipelineMeta, Pipeline pipeline, SyslogMessageMeta processRowsITransform ) {
super( transformMeta, meta, data, copyNr, pipelineMeta, pipeline );
syslogMessageMeta = processRowsITransform;
}
@@ -102,13 +101,13 @@
public void run() {
try {
countDownLatch.await();
- .init();
+ init();
} catch ( Exception e ) {
e.printStackTrace();
numOfErrors.getAndIncrement();
} finally {
try {
- dispose( syslogMessageMeta, getTransformDataInterface() );
+ dispose();
} catch ( Exception e ) {
e.printStackTrace();
numOfErrors.getAndIncrement();
@@ -131,10 +130,11 @@
private SyslogMessageTask createSyslogMessageTask() throws Exception {
SyslogMessageData data = new SyslogMessageData();
+ SyslogMessageMeta meta = new SyslogMessageMeta();
IRowMeta inputRowMeta = mock( IRowMeta.class );
when( inputRowMeta.indexOfValue( any() ) ).thenReturn( 0 );
when( inputRowMeta.getString( any(), eq( 0 ) ) ).thenReturn( testMessage );
- SyslogMessageTask syslogMessage = new SyslogMessageTask( transformMockHelper.transformMeta, data, 0, transformMockHelper.pipelineMeta,
+ SyslogMessageTask syslogMessage = new SyslogMessageTask( transformMockHelper.transformMeta, meta, data, 0, transformMockHelper.pipelineMeta,
transformMockHelper.pipeline, transformMockHelper.iTransformMeta );
syslogMessage.init();
syslogMessage.setInputRowMeta( inputRowMeta );
diff --git a/archive-pipeline-transforms/src/test/java/engine/transforms/syslog/SyslogMessageMetaTest.java b/plugins/transforms/syslog/src/test/java/org/apache/hop/pipeline/transforms/syslog/SyslogMessageMetaTest.java
similarity index 100%
rename from archive-pipeline-transforms/src/test/java/engine/transforms/syslog/SyslogMessageMetaTest.java
rename to plugins/transforms/syslog/src/test/java/org/apache/hop/pipeline/transforms/syslog/SyslogMessageMetaTest.java
diff --git a/archive-pipeline-transforms/src/test/java/engine/transforms/syslog/SyslogMessageTest.java b/plugins/transforms/syslog/src/test/java/org/apache/hop/pipeline/transforms/syslog/SyslogMessageTest.java
similarity index 96%
rename from archive-pipeline-transforms/src/test/java/engine/transforms/syslog/SyslogMessageTest.java
rename to plugins/transforms/syslog/src/test/java/org/apache/hop/pipeline/transforms/syslog/SyslogMessageTest.java
index d11e348..8b5b91a 100644
--- a/archive-pipeline-transforms/src/test/java/engine/transforms/syslog/SyslogMessageTest.java
+++ b/plugins/transforms/syslog/src/test/java/org/apache/hop/pipeline/transforms/syslog/SyslogMessageTest.java
@@ -22,7 +22,7 @@
package org.apache.hop.pipeline.transforms.syslog;
-import org.apache.hop.core.logging.LoggingObjectInterface;
+import org.apache.hop.core.logging.ILoggingObject;
import org.apache.hop.pipeline.transforms.mock.TransformMockHelper;
import org.junit.After;
import org.junit.Before;
@@ -53,7 +53,7 @@
transformMockHelper =
new TransformMockHelper<SyslogMessageMeta, SyslogMessageData>( "SYSLOG_MESSAGE TEST", SyslogMessageMeta.class,
SyslogMessageData.class );
- when( transformMockHelper.logChannelFactory.create( any(), any( LoggingObjectInterface.class ) ) ).thenReturn(
+ when( transformMockHelper.logChannelFactory.create( any(), any( ILoggingObject.class ) ) ).thenReturn(
transformMockHelper.logChannelInterface );
}
diff --git a/plugins/transforms/writetolog/pom.xml b/plugins/transforms/writetolog/pom.xml
new file mode 100644
index 0000000..d48a475
--- /dev/null
+++ b/plugins/transforms/writetolog/pom.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0"?>
+<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
+ xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.hop</groupId>
+ <artifactId>hop-plugins-transforms</artifactId>
+ <version>0.20-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>hop-transform-writetolog</artifactId>
+ <packaging>jar</packaging>
+
+ <name>Hop Plugins Transforms Write To Log</name>
+
+</project>
\ No newline at end of file
diff --git a/archive-pipeline-transforms/src/main/java/engine/transforms/writetolog/WriteToLog.java b/plugins/transforms/writetolog/src/main/java/org/apache/pipeline/transforms/writetolog/WriteToLog.java
similarity index 91%
rename from archive-pipeline-transforms/src/main/java/engine/transforms/writetolog/WriteToLog.java
rename to plugins/transforms/writetolog/src/main/java/org/apache/pipeline/transforms/writetolog/WriteToLog.java
index df12927..0da9f66 100644
--- a/archive-pipeline-transforms/src/main/java/engine/transforms/writetolog/WriteToLog.java
+++ b/plugins/transforms/writetolog/src/main/java/org/apache/pipeline/transforms/writetolog/WriteToLog.java
@@ -20,7 +20,7 @@
*
******************************************************************************/
-package org.apache.hop.pipeline.transforms.writetolog;
+package org.apache.pipeline.transforms.writetolog;
import org.apache.hop.core.Const;
import org.apache.hop.core.exception.HopException;
@@ -35,6 +35,8 @@
import org.apache.hop.pipeline.transform.TransformMeta;
import org.apache.hop.pipeline.transform.ITransform;
+import javax.xml.crypto.Data;
+
/**
* Write data to log.
*
@@ -42,24 +44,19 @@
* @since 30-06-2008
*/
-public class WriteToLog extends BaseTransform implements ITransform {
+public class WriteToLog extends BaseTransform<WriteToLogMeta, WriteToLogData> implements ITransform<WriteToLogMeta, WriteToLogData> {
private static Class<?> PKG = WriteToLogMeta.class; // for i18n purposes, needed by Translator!!
- private WriteToLogMeta meta;
- private WriteToLogData data;
private int rowCounter = 0;
private boolean rowCounterLimitHit = false;
- public WriteToLog( TransformMeta transformMeta, ITransformData data, int copyNr, PipelineMeta pipelineMeta,
- Pipeline pipeline ) {
+ public WriteToLog(TransformMeta transformMeta, WriteToLogMeta meta, WriteToLogData data, int copyNr, PipelineMeta pipelineMeta,
+ Pipeline pipeline ) {
super( transformMeta, meta, data, copyNr, pipelineMeta, pipeline );
}
public boolean processRow() throws HopException {
- meta = (WriteToLogMeta) smi;
- data = (WriteToLogData) sdi;
-
Object[] r = getRow(); // get row, set busy!
if ( r == null ) { // no more input to be expected...
@@ -180,8 +177,6 @@
}
public boolean init() {
- meta = (WriteToLogMeta) smi;
- data = (WriteToLogData) sdi;
if ( super.init() ) {
// Add init code here.
diff --git a/archive-pipeline-transforms/src/main/java/engine/transforms/writetolog/WriteToLogData.java b/plugins/transforms/writetolog/src/main/java/org/apache/pipeline/transforms/writetolog/WriteToLogData.java
similarity index 95%
rename from archive-pipeline-transforms/src/main/java/engine/transforms/writetolog/WriteToLogData.java
rename to plugins/transforms/writetolog/src/main/java/org/apache/pipeline/transforms/writetolog/WriteToLogData.java
index 5e00100..257ae41 100644
--- a/archive-pipeline-transforms/src/main/java/engine/transforms/writetolog/WriteToLogData.java
+++ b/plugins/transforms/writetolog/src/main/java/org/apache/pipeline/transforms/writetolog/WriteToLogData.java
@@ -20,7 +20,7 @@
*
******************************************************************************/
-package org.apache.hop.pipeline.transforms.writetolog;
+package org.apache.pipeline.transforms.writetolog;
import org.apache.hop.core.logging.LogLevel;
import org.apache.hop.pipeline.transform.BaseTransformData;
diff --git a/archive-pipeline-transforms/src/main/java/ui/steps/writetolog/WriteToLogDialog.java b/plugins/transforms/writetolog/src/main/java/org/apache/pipeline/transforms/writetolog/WriteToLogDialog.java
similarity index 97%
rename from archive-pipeline-transforms/src/main/java/ui/steps/writetolog/WriteToLogDialog.java
rename to plugins/transforms/writetolog/src/main/java/org/apache/pipeline/transforms/writetolog/WriteToLogDialog.java
index 717aec3..173accb 100644
--- a/archive-pipeline-transforms/src/main/java/ui/steps/writetolog/WriteToLogDialog.java
+++ b/plugins/transforms/writetolog/src/main/java/org/apache/pipeline/transforms/writetolog/WriteToLogDialog.java
@@ -20,10 +20,11 @@
*
******************************************************************************/
-package org.apache.hop.ui.pipeline.transforms.writetolog;
+package org.apache.pipeline.transforms.writetolog;
import org.apache.hop.core.Const;
import org.apache.hop.core.Props;
+import org.apache.hop.core.annotations.PluginDialog;
import org.apache.hop.core.exception.HopException;
import org.apache.hop.core.logging.LogLevel;
import org.apache.hop.core.row.IRowMeta;
@@ -34,13 +35,12 @@
import org.apache.hop.pipeline.transform.BaseTransformMeta;
import org.apache.hop.pipeline.transform.ITransformDialog;
import org.apache.hop.pipeline.transform.TransformMeta;
-import org.apache.hop.pipeline.transforms.writetolog.WriteToLogMeta;
import org.apache.hop.ui.core.dialog.ErrorDialog;
import org.apache.hop.ui.core.widget.ColumnInfo;
import org.apache.hop.ui.core.widget.StyledTextComp;
import org.apache.hop.ui.core.widget.TableView;
import org.apache.hop.ui.pipeline.transform.BaseTransformDialog;
-import org.apache.hop.ui.pipeline.transform.TableItemInsertListener;
+import org.apache.hop.ui.pipeline.transform.ITableItemInsertListener;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CCombo;
import org.eclipse.swt.events.ModifyEvent;
@@ -68,6 +68,12 @@
import java.util.Map;
import java.util.Set;
+@PluginDialog(
+ id = "WriteToLog",
+ image = "writetolog.svg",
+ pluginType = PluginDialog.PluginType.TRANSFORM,
+ documentationUrl = ""
+)
public class WriteToLogDialog extends BaseTransformDialog implements ITransformDialog {
private static Class<?> PKG = WriteToLogMeta.class; // for i18n purposes, needed by Translator!!
@@ -395,7 +401,7 @@
try {
IRowMeta r = pipelineMeta.getPrevTransformFields( transformName );
if ( r != null ) {
- TableItemInsertListener insertListener = new TableItemInsertListener() {
+ ITableItemInsertListener insertListener = new ITableItemInsertListener() {
public boolean tableItemInserted( TableItem tableItem, IValueMeta v ) {
return true;
}
diff --git a/archive-pipeline-transforms/src/main/java/engine/transforms/writetolog/WriteToLogMeta.java b/plugins/transforms/writetolog/src/main/java/org/apache/pipeline/transforms/writetolog/WriteToLogMeta.java
similarity index 89%
rename from archive-pipeline-transforms/src/main/java/engine/transforms/writetolog/WriteToLogMeta.java
rename to plugins/transforms/writetolog/src/main/java/org/apache/pipeline/transforms/writetolog/WriteToLogMeta.java
index 55369a6..4c9ae20 100644
--- a/archive-pipeline-transforms/src/main/java/engine/transforms/writetolog/WriteToLogMeta.java
+++ b/plugins/transforms/writetolog/src/main/java/org/apache/pipeline/transforms/writetolog/WriteToLogMeta.java
@@ -20,27 +20,26 @@
*
******************************************************************************/
-package org.apache.hop.pipeline.transforms.writetolog;
+package org.apache.pipeline.transforms.writetolog;
import org.apache.hop.core.CheckResult;
-import org.apache.hop.core.CheckResultInterface;
+import org.apache.hop.core.ICheckResult;
import org.apache.hop.core.Const;
+import org.apache.hop.core.annotations.Transform;
import org.apache.hop.core.exception.HopXmlException;
import org.apache.hop.core.logging.LogLevel;
import org.apache.hop.core.row.IRowMeta;
-import org.apache.hop.core.variables.iVariables;
+import org.apache.hop.core.variables.IVariables;
import org.apache.hop.core.xml.XmlHandler;
import org.apache.hop.i18n.BaseMessages;
import org.apache.hop.metastore.api.IMetaStore;
import org.apache.hop.pipeline.Pipeline;
import org.apache.hop.pipeline.PipelineMeta;
-import org.apache.hop.pipeline.transform.BaseTransformMeta;
-import org.apache.hop.pipeline.transform.ITransformData;
-import org.apache.hop.pipeline.transform.ITransform;
-import org.apache.hop.pipeline.transform.TransformMeta;
+import org.apache.hop.pipeline.transform.*;
import org.apache.hop.pipeline.transform.ITransform;
import org.w3c.dom.Node;
+import javax.xml.crypto.Data;
import java.util.Arrays;
import java.util.List;
@@ -49,7 +48,14 @@
*
*/
-public class WriteToLogMeta extends BaseTransformMeta implements ITransform {
+@Transform(
+ id = "WriteToLog",
+ i18nPackageName = "org.apache.hop.pipeline.transforms.writetolog",
+ name = "BaseTransform.TypeLongDesc.WriteToLog",
+ description = "BaseTransform.TypeTooltipDesc.WriteToLog",
+ categoryDescription = "i18n:org.apache.hop.pipeline.transform:BaseTransform.Category.Utility"
+)
+public class WriteToLogMeta extends BaseTransformMeta implements ITransformMeta<WriteToLog, WriteToLogData> {
private static Class<?> PKG = WriteToLogMeta.class; // for i18n purposes, needed by Translator!!
/**
@@ -124,6 +130,11 @@
return retval;
}
+ @Override
+ public ITransform createTransform(TransformMeta transformMeta, WriteToLogData data, int copyNr, PipelineMeta pipelineMeta, Pipeline pipeline) {
+ return new WriteToLog( transformMeta, this, data, copyNr, pipelineMeta, pipeline );
+ }
+
public void allocate( int nrFields ) {
fieldName = new String[ nrFields ];
}
@@ -257,8 +268,8 @@
}
@Override
- public void check( List<CheckResultInterface> remarks, PipelineMeta pipelineMeta, TransformMeta transformMeta,
- IRowMeta prev, String[] input, String[] output, IRowMeta info, iVariables variables,
+ public void check( List<ICheckResult> remarks, PipelineMeta pipelineMeta, TransformMeta transformMeta,
+ IRowMeta prev, String[] input, String[] output, IRowMeta info, IVariables variables,
IMetaStore metaStore ) {
CheckResult cr;
if ( prev == null || prev.size() == 0 ) {
@@ -319,13 +330,7 @@
}
@Override
- public ITransform getTransform( TransformMeta transformMeta, ITransformData data, int cnr, PipelineMeta tr,
- Pipeline pipeline ) {
- return new WriteToLog( transformMeta, this, data, cnr, tr, pipeline );
- }
-
- @Override
- public ITransformData getTransformData() {
+ public WriteToLogData getTransformData() {
return new WriteToLogData();
}
diff --git a/archive-pipeline-transforms/src/main/resources/engine/steps/writetolog/messages/messages_en_US.properties b/plugins/transforms/writetolog/src/main/resources/org/apache/pipeline/transforms/writetolog/messages/messages_en_US.properties
similarity index 94%
rename from archive-pipeline-transforms/src/main/resources/engine/steps/writetolog/messages/messages_en_US.properties
rename to plugins/transforms/writetolog/src/main/resources/org/apache/pipeline/transforms/writetolog/messages/messages_en_US.properties
index ce1f89a..a9c1a85 100644
--- a/archive-pipeline-transforms/src/main/resources/engine/steps/writetolog/messages/messages_en_US.properties
+++ b/plugins/transforms/writetolog/src/main/resources/org/apache/pipeline/transforms/writetolog/messages/messages_en_US.properties
@@ -1,3 +1,6 @@
+BaseTransform.TypeLongDesc.WriteToLog=Write to log
+BaseTransform.TypeTooltipDesc.WriteToLog=Write data to log
+
#####################################################################
##
## WriteToPipelineDialog
diff --git a/archive-pipeline-transforms/src/main/resources/engine/steps/writetolog/messages/messages_fr_FR.properties b/plugins/transforms/writetolog/src/main/resources/org/apache/pipeline/transforms/writetolog/messages/messages_fr_FR.properties
similarity index 94%
rename from archive-pipeline-transforms/src/main/resources/engine/steps/writetolog/messages/messages_fr_FR.properties
rename to plugins/transforms/writetolog/src/main/resources/org/apache/pipeline/transforms/writetolog/messages/messages_fr_FR.properties
index 36ddb5d..b391339 100644
--- a/archive-pipeline-transforms/src/main/resources/engine/steps/writetolog/messages/messages_fr_FR.properties
+++ b/plugins/transforms/writetolog/src/main/resources/org/apache/pipeline/transforms/writetolog/messages/messages_fr_FR.properties
@@ -1,3 +1,6 @@
+BaseTransform.TypeLongDesc.WriteToLog=Ecriture dans trace
+BaseTransform.TypeTooltipDesc.WriteToLog=Ecriture de donn\u00E9es dans la trace
+
#####################################################################
##
## WriteToPipelineDialog
diff --git a/archive-pipeline-transforms/src/main/resources/engine/steps/writetolog/messages/messages_it_IT.properties b/plugins/transforms/writetolog/src/main/resources/org/apache/pipeline/transforms/writetolog/messages/messages_it_IT.properties
similarity index 100%
rename from archive-pipeline-transforms/src/main/resources/engine/steps/writetolog/messages/messages_it_IT.properties
rename to plugins/transforms/writetolog/src/main/resources/org/apache/pipeline/transforms/writetolog/messages/messages_it_IT.properties
diff --git a/archive-pipeline-transforms/src/main/resources/engine/steps/writetolog/messages/messages_ja_JP.properties b/plugins/transforms/writetolog/src/main/resources/org/apache/pipeline/transforms/writetolog/messages/messages_ja_JP.properties
similarity index 91%
rename from archive-pipeline-transforms/src/main/resources/engine/steps/writetolog/messages/messages_ja_JP.properties
rename to plugins/transforms/writetolog/src/main/resources/org/apache/pipeline/transforms/writetolog/messages/messages_ja_JP.properties
index 9b66574..2094a82 100644
--- a/archive-pipeline-transforms/src/main/resources/engine/steps/writetolog/messages/messages_ja_JP.properties
+++ b/plugins/transforms/writetolog/src/main/resources/org/apache/pipeline/transforms/writetolog/messages/messages_ja_JP.properties
@@ -1,3 +1,6 @@
+BaseTransform.TypeLongDesc.WriteToLog=\u30ED\u30B0\u66F8\u304D\u8FBC\u307F
+BaseTransform.TypeTooltipDesc.WriteToLog=Write to log\n\u30ED\u30B0\u306B\u30C7\u30FC\u30BF\u3092\u66F8\u304D\u8FBC\u307F\u307E\u3059\u3002
+
#####################################################################
##
## WriteToPipelineDialog
diff --git a/archive-pipeline-transforms/src/main/resources/engine/steps/writetolog/messages/messages_ko_KR.properties b/plugins/transforms/writetolog/src/main/resources/org/apache/pipeline/transforms/writetolog/messages/messages_ko_KR.properties
similarity index 100%
rename from archive-pipeline-transforms/src/main/resources/engine/steps/writetolog/messages/messages_ko_KR.properties
rename to plugins/transforms/writetolog/src/main/resources/org/apache/pipeline/transforms/writetolog/messages/messages_ko_KR.properties
diff --git a/archive-pipeline-transforms/src/main/resources/engine/steps/writetolog/messages/messages_pt_BR.properties b/plugins/transforms/writetolog/src/main/resources/org/apache/pipeline/transforms/writetolog/messages/messages_pt_BR.properties
similarity index 100%
rename from archive-pipeline-transforms/src/main/resources/engine/steps/writetolog/messages/messages_pt_BR.properties
rename to plugins/transforms/writetolog/src/main/resources/org/apache/pipeline/transforms/writetolog/messages/messages_pt_BR.properties
diff --git a/archive-pipeline-transforms/src/main/resources/engine/steps/writetolog/messages/messages_zh_CN.properties b/plugins/transforms/writetolog/src/main/resources/org/apache/pipeline/transforms/writetolog/messages/messages_zh_CN.properties
similarity index 95%
rename from archive-pipeline-transforms/src/main/resources/engine/steps/writetolog/messages/messages_zh_CN.properties
rename to plugins/transforms/writetolog/src/main/resources/org/apache/pipeline/transforms/writetolog/messages/messages_zh_CN.properties
index 1874ce7..3d8a538 100644
--- a/archive-pipeline-transforms/src/main/resources/engine/steps/writetolog/messages/messages_zh_CN.properties
+++ b/plugins/transforms/writetolog/src/main/resources/org/apache/pipeline/transforms/writetolog/messages/messages_zh_CN.properties
@@ -1,3 +1,5 @@
+BaseTransform.TypeLongDesc.WriteToLog=\u5199\u65E5\u5FD7
+
#File generated by Hop Translator for package 'org.apache.hop.pipeline.transforms.writetolog' in locale 'zh_CN'
#
#
diff --git a/ui/src/main/resources/ui/images/WTL.svg b/plugins/transforms/writetolog/src/main/resources/writetolog.svg
similarity index 100%
rename from ui/src/main/resources/ui/images/WTL.svg
rename to plugins/transforms/writetolog/src/main/resources/writetolog.svg
diff --git a/archive-pipeline-transforms/src/test/java/engine/transforms/writetolog/WriteToLogMetaSymmetric.java b/plugins/transforms/writetolog/src/test/java/org/apache/pipeline/transforms/writetolog/WriteToLogMetaSymmetric.java
similarity index 96%
rename from archive-pipeline-transforms/src/test/java/engine/transforms/writetolog/WriteToLogMetaSymmetric.java
rename to plugins/transforms/writetolog/src/test/java/org/apache/pipeline/transforms/writetolog/WriteToLogMetaSymmetric.java
index e9d7ad3..a000561 100644
--- a/archive-pipeline-transforms/src/test/java/engine/transforms/writetolog/WriteToLogMetaSymmetric.java
+++ b/plugins/transforms/writetolog/src/test/java/org/apache/pipeline/transforms/writetolog/WriteToLogMetaSymmetric.java
@@ -19,7 +19,7 @@
* limitations under the License.
*
******************************************************************************/
-package org.apache.hop.pipeline.transforms.writetolog;
+package org.apache.pipeline.transforms.writetolog;
import org.apache.hop.core.logging.LogLevel;
diff --git a/archive-pipeline-transforms/src/test/java/engine/transforms/writetolog/WriteToLogMetaTest.java b/plugins/transforms/writetolog/src/test/java/org/apache/pipeline/transforms/writetolog/WriteToLogMetaTest.java
similarity index 85%
rename from archive-pipeline-transforms/src/test/java/engine/transforms/writetolog/WriteToLogMetaTest.java
rename to plugins/transforms/writetolog/src/test/java/org/apache/pipeline/transforms/writetolog/WriteToLogMetaTest.java
index 09e7998..00290f3 100644
--- a/archive-pipeline-transforms/src/test/java/engine/transforms/writetolog/WriteToLogMetaTest.java
+++ b/plugins/transforms/writetolog/src/test/java/org/apache/pipeline/transforms/writetolog/WriteToLogMetaTest.java
@@ -19,7 +19,7 @@
* limitations under the License.
*
******************************************************************************/
-package org.apache.hop.pipeline.transforms.writetolog;
+package org.apache.pipeline.transforms.writetolog;
import org.apache.hop.core.HopEnvironment;
@@ -28,9 +28,9 @@
import org.apache.hop.junit.rules.RestoreHopEngineEnvironment;
import org.apache.hop.pipeline.transform.ITransform;
import org.apache.hop.pipeline.transforms.loadsave.LoadSaveTester;
-import org.apache.hop.pipeline.transforms.loadsave.initializer.InitializerInterface;
+import org.apache.hop.pipeline.transforms.loadsave.initializer.IInitializerInterface;
import org.apache.hop.pipeline.transforms.loadsave.validator.ArrayLoadSaveValidator;
-import org.apache.hop.pipeline.transforms.loadsave.validator.FieldLoadSaveValidator;
+import org.apache.hop.pipeline.transforms.loadsave.validator.IFieldLoadSaveValidator;
import org.apache.hop.pipeline.transforms.loadsave.validator.StringLoadSaveValidator;
import org.junit.Before;
import org.junit.ClassRule;
@@ -43,7 +43,7 @@
import java.util.Map;
import java.util.Random;
-public class WriteToLogMetaTest implements InitializerInterface<ITransform> {
+public class WriteToLogMetaTest implements IInitializerInterface<WriteToLogMeta> {
@ClassRule public static RestoreHopEngineEnvironment env = new RestoreHopEngineEnvironment();
LoadSaveTester loadSaveTester;
Class<WriteToLogMetaSymmetric> testMetaClass = WriteToLogMetaSymmetric.class;
@@ -75,14 +75,14 @@
put( "fieldName", "setFieldName" );
}
};
- FieldLoadSaveValidator<String[]> stringArrayLoadSaveValidator =
+ IFieldLoadSaveValidator<String[]> stringArrayLoadSaveValidator =
new ArrayLoadSaveValidator<String>( new StringLoadSaveValidator(), 5 );
- Map<String, FieldLoadSaveValidator<?>> attrValidatorMap = new HashMap<String, FieldLoadSaveValidator<?>>();
+ Map<String, IFieldLoadSaveValidator<?>> attrValidatorMap = new HashMap<String, IFieldLoadSaveValidator<?>>();
attrValidatorMap.put( "fieldName", stringArrayLoadSaveValidator );
attrValidatorMap.put( "loglevel", new LogLevelLoadSaveValidator() );
- Map<String, FieldLoadSaveValidator<?>> typeValidatorMap = new HashMap<String, FieldLoadSaveValidator<?>>();
+ Map<String, IFieldLoadSaveValidator<?>> typeValidatorMap = new HashMap<String, IFieldLoadSaveValidator<?>>();
loadSaveTester =
new LoadSaveTester( testMetaClass, attributes, new ArrayList<>(),
@@ -91,7 +91,7 @@
// Call the allocate method on the LoadSaveTester meta class
@Override
- public void modify( ITransform someMeta ) {
+ public void modify( WriteToLogMeta someMeta ) {
if ( someMeta instanceof WriteToLogMeta ) {
( (WriteToLogMeta) someMeta ).allocate( 5 );
}
@@ -102,7 +102,7 @@
loadSaveTester.testSerialization();
}
- public class LogLevelLoadSaveValidator implements FieldLoadSaveValidator<String> {
+ public class LogLevelLoadSaveValidator implements IFieldLoadSaveValidator<String> {
final Random rand = new Random();
@Override
diff --git a/ui/src/main/resources/ui/images/SYL.png b/ui/src/main/resources/ui/images/SYL.png
deleted file mode 100644
index c166fee..0000000
--- a/ui/src/main/resources/ui/images/SYL.png
+++ /dev/null
Binary files differ
diff --git a/ui/src/main/resources/ui/images/WTL.png b/ui/src/main/resources/ui/images/WTL.png
deleted file mode 100644
index 2fb53b1..0000000
--- a/ui/src/main/resources/ui/images/WTL.png
+++ /dev/null
Binary files differ