public Value upper() { if ( isNull() ) { setType( VALUE_TYPE_STRING ); return this; } setValue( getString().toUpperCase() ); return this; }
public Value lower() { if ( isNull() ) { setType( VALUE_TYPE_STRING ); } else { setValue( getString().toLowerCase() ); } return this; }
/** * Change a string into its hexadecimal representation. E.g. if Value contains string "a" afterwards it would contain * value "0061". * * Note that transformations happen in groups of 4 hex characters, so the value of a characters is always in the range * 0-65535. * * @return Value itself * @throws KettleValueException */ public Value charToHexEncode() { final char[] hexDigits = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; setType( VALUE_TYPE_STRING ); if ( isNull() ) { return this; } String hex = getString(); char[] s = hex.toCharArray(); StringBuilder hexString = new StringBuilder( 2 * s.length ); for ( int i = 0; i < s.length; i++ ) { hexString.append( hexDigits[( s[i] & 0xF000 ) >> 12] ); // hex 1 hexString.append( hexDigits[( s[i] & 0x0F00 ) >> 8] ); // hex 2 hexString.append( hexDigits[( s[i] & 0x00F0 ) >> 4] ); // hex 3 hexString.append( hexDigits[s[i] & 0x000F] ); // hex 4 } setValue( hexString ); return this; }
public Value str2dat( String arg0, String arg1 ) throws KettleValueException { if ( isNull() ) { setType( VALUE_TYPE_DATE ); } else { // System.out.println("Convert string ["+string+"] to date using pattern '"+arg0+"'"); SimpleDateFormat df = new SimpleDateFormat(); DateFormatSymbols dfs = new DateFormatSymbols(); if ( arg1 != null ) { dfs.setLocalPatternChars( arg1 ); } if ( arg0 != null ) { df.applyPattern( arg0 ); } try { value.setDate( df.parse( getString() ) ); setType( VALUE_TYPE_DATE ); setLength( -1, -1 ); } catch ( Exception e ) { setType( VALUE_TYPE_DATE ); setNull(); throw new KettleValueException( "TO_DATE Couldn't convert String to Date" + e.toString() ); } } return this; }
/** * Change a string into its hexadecimal representation. E.g. if Value contains string "a" afterwards it would contain * value "61". * * Note that transformations happen in groups of 2 hex characters, so the value of a characters is always in the range * 0-255. * * @return Value itself * @throws KettleValueException */ public Value byteToHexEncode() { final char[] hexDigits = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; setType( VALUE_TYPE_STRING ); if ( isNull() ) { return this; } String hex = getString(); // depending on the use case, this code might deliver the wrong values due to extra conversion with toCharArray // see Checksum step and PDI-5190 // "Add Checksum step gives incorrect results (MD5, CRC32, ADLER32, SHA-1 are affected)" char[] s = hex.toCharArray(); StringBuilder hexString = new StringBuilder( 2 * s.length ); for ( int i = 0; i < s.length; i++ ) { hexString.append( hexDigits[( s[i] & 0x00F0 ) >> 4] ); // hi nibble hexString.append( hexDigits[s[i] & 0x000F] ); // lo nibble } setValue( hexString ); return this; }
public Value num2str( String format, String decimalSymbol, String groupingSymbol, String currencySymbol ) throws KettleValueException { if ( isNull() ) { setType( VALUE_TYPE_STRING ); } else { setValue( nf.format( getNumber() ) ); } catch ( Exception e ) { setType( VALUE_TYPE_STRING ); setNull(); throw new KettleValueException( "Couldn't convert Number to String " + e.toString() );
public Value dat2str( String arg0, String arg1 ) throws KettleValueException { if ( isNull() ) { setType( VALUE_TYPE_STRING ); } else { if ( getType() == VALUE_TYPE_DATE ) { SimpleDateFormat df = new SimpleDateFormat(); DateFormatSymbols dfs = new DateFormatSymbols(); if ( arg1 != null ) { dfs.setLocalPatternChars( arg1 ); } if ( arg0 != null ) { df.applyPattern( arg0 ); } try { setValue( df.format( getDate() ) ); } catch ( Exception e ) { setType( VALUE_TYPE_STRING ); setNull(); throw new KettleValueException( "TO_CHAR Couldn't convert Date to String " + e.toString() ); } } else { throw new KettleValueException( "Function DAT2STR only works on a date" ); } } return this; }
public Value startsWith( String string ) { if ( isNull() ) { setType( VALUE_TYPE_BOOLEAN ); return this; } if ( string == null ) { setValue( false ); setNull(); return this; } setValue( getString().startsWith( string ) ); return this; }
public Value length() throws KettleValueException { if ( isNull() ) { setType( VALUE_TYPE_INTEGER ); setValue( 0L ); return this; } if ( getType() == VALUE_TYPE_STRING ) { setValue( (double) getString().length() ); } else { throw new KettleValueException( "Function LENGTH only works with a string" ); } return this; }
/** * Performs a right and left trim of spaces in the string. If the value is not a string a conversion to String is * performed first. * * @return The trimmed string value. */ public Value trim() { if ( isNull() ) { setType( VALUE_TYPE_STRING ); return this; } String str = Const.trim( getString() ); setValue( str ); return this; }
public Value rightstr( int len ) { if ( isNull() ) { setType( VALUE_TYPE_STRING ); return this; } setValue( getString() ); int tot_len = getString() != null ? getString().length() : 0; if ( tot_len > 0 ) { int totlen = getString().length(); int f = totlen - len; if ( f < 0 ) { f = 0; } setValue( getString().substring( f ) ); } else { setNull(); } if ( !isString() ) { setType( VALUE_TYPE_STRING ); } return this; }
public Value lpad( int len, String padstr ) { if ( isNull() ) { setType( VALUE_TYPE_STRING ); } else { if ( getType() != VALUE_TYPE_STRING ) { // also lpad other types! setValue( getString() ); } if ( getString() != null ) { StringBuilder result = new StringBuilder( getString() ); int pad = len; int l = ( pad - result.length() ) / padstr.length() + 1; int i; for ( i = 0; i < l; i++ ) { result.insert( 0, padstr ); } // Maybe we added one or two too many! i = result.length(); while ( i > pad && pad > 0 ) { result.deleteCharAt( 0 ); i--; } setValue( result.toString() ); } else { setNull(); } } setLength( len ); return this; }
public Value rpad( int len, String padstr ) { if ( isNull() ) { setType( VALUE_TYPE_STRING ); } else { if ( getType() != VALUE_TYPE_STRING ) { // also rpad other types! setValue( getString() ); } if ( getString() != null ) { StringBuilder result = new StringBuilder( getString() ); int pad = len; int l = ( pad - result.length() ) / padstr.length() + 1; int i; for ( i = 0; i < l; i++ ) { result.append( padstr ); } // Maybe we added one or two too many! i = result.length(); while ( i > pad && pad > 0 ) { result.deleteCharAt( i - 1 ); i--; } setValue( result.toString() ); } else { setNull(); } } setLength( len ); return this; }
public Value leftstr( int len ) { if ( isNull() ) { setType( VALUE_TYPE_STRING ); return this; } setValue( getString() ); int tot_len = getString() != null ? getString().length() : 0; if ( tot_len > 0 ) { int totlen = getString().length(); int f = totlen - len; if ( f > 0 ) { setValue( getString().substring( 0, len ) ); } } else { setNull(); } if ( !isString() ) { setType( VALUE_TYPE_STRING ); } return this; }
public Value num2dat() throws KettleValueException { if ( isNull() ) { setType( VALUE_TYPE_DATE ); } else { if ( isNumeric() ) { setValue( new Date( getInteger() ) ); setLength( -1, -1 ); } else { throw new KettleValueException( "Function NUM2DAT only works on a number" ); } } return this; }
public Value substr( int from, int to ) { if ( isNull() ) { setType( VALUE_TYPE_STRING ); return this; } setValue( getString() ); if ( getString() != null ) { if ( to < 0 && from >= 0 ) { setValue( getString().substring( from ) ); } else if ( to >= 0 && from >= 0 ) { setValue( getString().substring( from, to ) ); } } else { setNull(); } if ( !isString() ) { setType( VALUE_TYPE_STRING ); } return this; }
setType( VALUE_TYPE_STRING ); } else { if ( getType() == VALUE_TYPE_STRING ) {
public Value rtrim() { if ( isNull() ) { setType( VALUE_TYPE_STRING ); } else { String s; if ( getType() == VALUE_TYPE_STRING ) { s = Const.rtrim( getString() ); } else { s = Const.rtrim( toString() ); } setValue( s ); } return this; }
public Value dat2num() throws KettleValueException { if ( isNull() ) { setType( VALUE_TYPE_INTEGER ); return this; } if ( getType() == VALUE_TYPE_DATE ) { if ( getString() == null ) { setNull(); setValue( 0L ); } else { setValue( getInteger() ); } } else { throw new KettleValueException( "Function DAT2NUM works only on dates" ); } return this; }
public Value ltrim() { if ( isNull() ) { setType( VALUE_TYPE_STRING ); } else { if ( getString() != null ) { String s; if ( getType() == VALUE_TYPE_STRING ) { s = Const.ltrim( getString() ); } else { s = Const.ltrim( toString() ); } setValue( s ); } else { setNull(); } } return this; }