Java Code Examples for org.pentaho.di.core.Const#trim()
The following examples show how to use
org.pentaho.di.core.Const#trim() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JobEntryMysqlBulkFile.java From pentaho-kettle with Apache License 2.0 | 6 votes |
private String MysqlString( String listcolumns ) { /* * handle forbiden char like ' */ String ReturnString = ""; String[] split = listcolumns.split( "," ); for ( int i = 0; i < split.length; i++ ) { if ( ReturnString.equals( "" ) ) { ReturnString = "`" + Const.trim( split[i] ) + "`"; } else { ReturnString = ReturnString + ", `" + Const.trim( split[i] ) + "`"; } } return ReturnString; }
Example 2
Source File: JobEntryMysqlBulkLoad.java From pentaho-kettle with Apache License 2.0 | 6 votes |
private String MysqlString( String listcolumns ) { /* * Handle forbiden char like ' */ String returnString = ""; String[] split = listcolumns.split( "," ); for ( int i = 0; i < split.length; i++ ) { if ( returnString.equals( "" ) ) { returnString = "`" + Const.trim( split[i] ) + "`"; } else { returnString = returnString + ", `" + Const.trim( split[i] ) + "`"; } } return returnString; }
Example 3
Source File: ScriptAddedFunctions.java From pentaho-kettle with Apache License 2.0 | 6 votes |
public static String trim( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList, Object FunctionContext ) { String sRC = ""; if ( ArgList.length == 1 ) { try { if ( isNull( ArgList[0] ) ) { return null; } else if ( isUndefined( ArgList[0] ) ) { return (String) undefinedValue; } sRC = (String) ArgList[0]; sRC = Const.trim( sRC ); } catch ( Exception e ) { throw new RuntimeException( "The function call trim is not valid : " + e.getMessage() ); } } else { throw new RuntimeException( "The function call trim requires 1 argument." ); } return sRC; }
Example 4
Source File: ScriptValuesAddedFunctions.java From pentaho-kettle with Apache License 2.0 | 6 votes |
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; }
Example 5
Source File: BaseFileField.java From pentaho-kettle with Apache License 2.0 | 6 votes |
public void guessTrimType() { boolean spaces_before = false; boolean spaces_after = false; for ( int i = 0; i < samples.length; i++ ) { spaces_before |= Const.nrSpacesBefore( samples[i] ) > 0; spaces_after |= Const.nrSpacesAfter( samples[i] ) > 0; samples[i] = Const.trim( samples[i] ); } trimtype = ValueMetaInterface.TRIM_TYPE_NONE; if ( spaces_before ) { trimtype |= ValueMetaInterface.TRIM_TYPE_LEFT; } if ( spaces_after ) { trimtype |= ValueMetaInterface.TRIM_TYPE_RIGHT; } }
Example 6
Source File: TextFileInputField.java From pentaho-kettle with Apache License 2.0 | 6 votes |
public void guessTrimType() { boolean spaces_before = false; boolean spaces_after = false; for ( int i = 0; i < samples.length; i++ ) { spaces_before |= Const.nrSpacesBefore( samples[i] ) > 0; spaces_after |= Const.nrSpacesAfter( samples[i] ) > 0; samples[i] = Const.trim( samples[i] ); } trimtype = ValueMetaInterface.TRIM_TYPE_NONE; if ( spaces_before ) { trimtype |= ValueMetaInterface.TRIM_TYPE_LEFT; } if ( spaces_after ) { trimtype |= ValueMetaInterface.TRIM_TYPE_RIGHT; } }
Example 7
Source File: ValueMetaBase.java From pentaho-kettle with Apache License 2.0 | 6 votes |
protected String trim( String string ) { switch ( getTrimType() ) { case TRIM_TYPE_NONE: break; case TRIM_TYPE_RIGHT: string = Const.rtrim( string ); break; case TRIM_TYPE_LEFT: string = Const.ltrim( string ); break; case TRIM_TYPE_BOTH: string = Const.trim( string ); break; default: break; } return string; }
Example 8
Source File: XMLInputSaxDataRetriever.java From pentaho-kettle with Apache License 2.0 | 5 votes |
private void setValueToRow( String value, int fieldnr ) throws KettleValueException { XMLInputSaxField xmlInputField = fields.get( fieldnr ); switch ( xmlInputField.getTrimType() ) { case XMLInputSaxField.TYPE_TRIM_LEFT: value = Const.ltrim( value ); break; case XMLInputSaxField.TYPE_TRIM_RIGHT: value = Const.rtrim( value ); break; case XMLInputSaxField.TYPE_TRIM_BOTH: value = Const.trim( value ); break; default: break; } // DO CONVERSIONS... ValueMetaInterface targetValueMeta = data.outputRowMeta.getValueMeta( fieldnr ); ValueMetaInterface sourceValueMeta = data.convertRowMeta.getValueMeta( fieldnr ); row[fieldnr] = targetValueMeta.convertData( sourceValueMeta, value ); // Do we need to repeat this field if it is null? if ( xmlInputField.isRepeated() ) { if ( row[fieldnr] == null && data.previousRow != null ) { Object previous = data.previousRow[fieldnr]; row[fieldnr] = previous; } } }
Example 9
Source File: Value.java From pentaho-kettle with Apache License 2.0 | 5 votes |
/** * 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; }
Example 10
Source File: XMLInputFieldPosition.java From pentaho-kettle with Apache License 2.0 | 4 votes |
/** * Construnct a new XMLFieldPosition based on an a code: E=Elementame, A=Attributename * * @param encoded */ public XMLInputFieldPosition( String encoded ) throws KettleValueException { int equalIndex = encoded.indexOf( '=' ); if ( equalIndex < 0 ) { throw new KettleValueException( BaseMessages.getString( PKG, "XMLInputFieldPosition.Exception.InvalidXMLFieldPosition", encoded ) ); } String positionType = Const.trim( encoded.substring( 0, equalIndex ) ); String nameAndNumber = Const.trim( encoded.substring( equalIndex + 1 ) ); String positionName = nameAndNumber; // Is there an element number? int semiIndex = nameAndNumber.indexOf( NR_MARKER ); if ( semiIndex >= 0 ) { this.elementNr = Const.toInt( nameAndNumber.substring( semiIndex + 1 ), 1 ); // Unreadable: default to 1 positionName = nameAndNumber.substring( 0, semiIndex ); } else { this.elementNr = 1; } if ( positionType.equalsIgnoreCase( "E" ) ) { // Element this.type = XML_ELEMENT; this.name = positionName; } else if ( positionType.equalsIgnoreCase( "A" ) ) { // Attribute this.type = XML_ATTRIBUTE; this.name = positionName; } else if ( positionType.equalsIgnoreCase( "R" ) ) { // Root of the repeating element. There is only one this.type = XML_ROOT; this.name = positionName; } else { throw new KettleValueException( BaseMessages.getString( PKG, "XMLInputFieldPosition.Exception.WrongPositionType", positionType ) ); } // Get the element nr }
Example 11
Source File: Database.java From pentaho-kettle with Apache License 2.0 | 4 votes |
/** * Execute a series of SQL statements, separated by ; * <p/> * We are already connected... * <p/> * Multiple statements have to be split into parts We use the ";" to separate statements... * <p/> * We keep the results in Result object from Jobs * * @param script The SQL script to be execute * @param params Parameters Meta * @param data Parameters value * @return A result with counts of the number or records updates, inserted, deleted or read. * @throws KettleDatabaseException In case an error occurs */ public Result execStatements( String script, RowMetaInterface params, Object[] data ) throws KettleDatabaseException { Result result = new Result(); SqlScriptParser sqlScriptParser = databaseMeta.getDatabaseInterface().createSqlScriptParser(); List<String> statements = sqlScriptParser.split( script ); int nrstats = 0; if ( statements != null ) { for ( String stat : statements ) { // Deleting all the single-line and multi-line comments from the string stat = sqlScriptParser.removeComments( stat ); if ( !Const.onlySpaces( stat ) ) { String sql = Const.trim( stat ); if ( sql.toUpperCase().startsWith( "SELECT" ) ) { // A Query if ( log.isDetailed() ) { log.logDetailed( "launch SELECT statement: " + Const.CR + sql ); } nrstats++; ResultSet rs = null; try { rs = openQuery( sql, params, data ); if ( rs != null ) { Object[] row = getRow( rs ); while ( row != null ) { result.setNrLinesRead( result.getNrLinesRead() + 1 ); if ( log.isDetailed() ) { log.logDetailed( rowMeta.getString( row ) ); } row = getRow( rs ); } } else { if ( log.isDebug() ) { log.logDebug( "Error executing query: " + Const.CR + sql ); } } } catch ( KettleValueException e ) { throw new KettleDatabaseException( e ); // just pass the error // upwards. } finally { try { if ( rs != null ) { rs.close(); } } catch ( SQLException ex ) { if ( log.isDebug() ) { log.logDebug( "Error closing query: " + Const.CR + sql ); } } } } else { // any kind of statement if ( log.isDetailed() ) { log.logDetailed( "launch DDL statement: " + Const.CR + sql ); } // A DDL statement nrstats++; Result res = execStatement( sql, params, data ); result.add( res ); } } } } if ( log.isDetailed() ) { log.logDetailed( nrstats + " statement" + ( nrstats == 1 ? "" : "s" ) + " executed" ); } return result; }
Example 12
Source File: ValueMetaAndData.java From pentaho-kettle with Apache License 2.0 | 4 votes |
/** * Read the data for this Value from an XML Node * * @param valnode * The XML Node to read from * @return true if all went well, false if something went wrong. */ public boolean loadXML( Node valnode ) { valueMeta = null; try { String valname = XMLHandler.getTagValue( valnode, "name" ); int valtype = ValueMetaBase.getType( XMLHandler.getTagValue( valnode, "type" ) ); String text = XMLHandler.getTagValue( valnode, "text" ); boolean isnull = "Y".equalsIgnoreCase( XMLHandler.getTagValue( valnode, "isnull" ) ); int len = Const.toInt( XMLHandler.getTagValue( valnode, "length" ), -1 ); int prec = Const.toInt( XMLHandler.getTagValue( valnode, "precision" ), -1 ); String mask = XMLHandler.getTagValue( valnode, "mask" ); valueMeta = new ValueMeta( valname, valtype ); valueData = text; valueMeta.setLength( len ); valueMeta.setPrecision( prec ); if ( mask != null ) { valueMeta.setConversionMask( mask ); } if ( valtype != ValueMetaInterface.TYPE_STRING ) { ValueMetaInterface originMeta = new ValueMetaString( valname ); if ( valueMeta.isNumeric() ) { originMeta.setDecimalSymbol( "." ); originMeta.setGroupingSymbol( null ); originMeta.setCurrencySymbol( null ); } if ( valtype == ValueMetaInterface.TYPE_DATE ) { originMeta.setConversionMask( ValueMetaBase.COMPATIBLE_DATE_FORMAT_PATTERN ); } valueData = Const.trim( text ); valueData = valueMeta.convertData( originMeta, valueData ); } if ( isnull ) { valueData = null; } } catch ( Exception e ) { valueData = null; return false; } return true; }
Example 13
Source File: EnterValueDialog.java From pentaho-kettle with Apache License 2.0 | 4 votes |
protected void setFormats() { // What is the selected type? // // The index must be set on the combobox after // calling setItems(), otherwise the zeroth element // is displayed, but the selectedIndex will be -1. int formatIndex = wFormat.getSelectionIndex(); String formatString = formatIndex >= 0 ? wFormat.getItem( formatIndex ) : ""; int type = ValueMetaFactory.getIdForValueMeta( wValueType.getText() ); String string = wInputString.getText(); // remove white spaces if not a string field if ( ( type != ValueMetaInterface.TYPE_STRING ) && ( string.startsWith( " " ) || string.endsWith( " " ) ) ) { string = Const.trim( string ); wInputString.setText( string ); } switch ( type ) { case ValueMetaInterface.TYPE_INTEGER: wFormat.setItems( Const.getNumberFormats() ); int index = ( !Utils.isEmpty( formatString ) ) ? wFormat.indexOf( formatString ) : wFormat.indexOf( "#" ); // ... then we have a custom format mask if ( ( !Utils.isEmpty( formatString ) ) && ( index < 0 ) ) { wFormat.add( formatString ); index = wFormat.indexOf( formatString ); } wFormat.select( index ); // default break; case ValueMetaInterface.TYPE_NUMBER: wFormat.setItems( Const.getNumberFormats() ); index = ( !Utils.isEmpty( formatString ) ) ? wFormat.indexOf( formatString ) : wFormat.indexOf( "#.#" ); // ... then we have a custom format mask if ( ( !Utils.isEmpty( formatString ) ) && ( index < 0 ) ) { wFormat.add( formatString ); index = wFormat.indexOf( formatString ); } wFormat.select( index ); // default break; case ValueMetaInterface.TYPE_DATE: wFormat.setItems( Const.getDateFormats() ); index = ( !Utils.isEmpty( formatString ) ) ? wFormat.indexOf( formatString ) : wFormat .indexOf( "yyyy/MM/dd HH:mm:ss" ); // default; // ... then we have a custom format mask if ( ( !Utils.isEmpty( formatString ) ) && ( index < 0 ) ) { wFormat.add( formatString ); index = wFormat.indexOf( formatString ); } wFormat.select( index ); // default break; case ValueMetaInterface.TYPE_BIGNUMBER: wFormat.setItems( new String[] {} ); break; default: wFormat.setItems( new String[] {} ); break; } }
Example 14
Source File: CsvInputAwareStepDialog.java From pentaho-kettle with Apache License 2.0 | 4 votes |
default String[] getFieldNamesImpl( final InputStreamReader reader, final CsvInputAwareMeta meta ) throws KettleException { String[] fieldNames = new String[] {}; if ( reader == null || meta == null ) { logError( BaseMessages.getString( "Dialog.ErrorGettingFields.Message" ) ); return fieldNames; } final String delimiter = getTransMeta().environmentSubstitute( meta.getDelimiter() ); final String enclosure = getTransMeta().environmentSubstitute( meta.getEnclosure() ); final EncodingType encodingType = EncodingType.guessEncodingType( reader.getEncoding() ); // Read a line of data to determine the number of rows... final String line = TextFileInputUtils.getLine( getLogChannel(), reader, encodingType, meta.getFileFormatTypeNr(), new StringBuilder( 1000 ), enclosure ); if ( !StringUtils.isBlank( line ) ) { fieldNames = CsvInput.guessStringsFromLine( getLogChannel(), line, delimiter, enclosure, meta.getEscapeCharacter() ); } if ( Utils.isEmpty( fieldNames ) ) { logError( BaseMessages.getString( "Dialog.ErrorGettingFields.Message" ) ); return fieldNames; } // Massage field names for ( int i = 0; i < fieldNames.length; i++ ) { fieldNames[ i ] = Const.trim( fieldNames[ i ] ); if ( !meta.hasHeader() ) { final DecimalFormat df = new DecimalFormat( "000" ); fieldNames[ i ] = "Field_" + df.format( i ); } else if ( !Utils.isEmpty( meta.getEnclosure() ) && fieldNames[ i ].startsWith( meta.getEnclosure() ) && fieldNames[ i ].endsWith( meta.getEnclosure() ) && fieldNames[ i ].length() > 1 ) { fieldNames[ i ] = fieldNames[ i ].substring( 1, fieldNames[ i ].length() - 1 ); } // trim again, now that the enclosure characters have been removed fieldNames[ i ] = Const.trim( fieldNames[ i ] ); fieldNames[ i ] = massageFieldName( fieldNames[ i ] ); } return fieldNames; }
Example 15
Source File: JobEntryMssqlBulkLoadDialog.java From pentaho-kettle with Apache License 2.0 | 4 votes |
/** * Get a list of columns, comma separated, allow the user to select from it. */ private void getListColumns() { if ( !Utils.isEmpty( wTablename.getText() ) ) { DatabaseMeta databaseMeta = jobMeta.findDatabase( wConnection.getText() ); if ( databaseMeta != null ) { Database database = new Database( loggingObject, databaseMeta ); database.shareVariablesWith( jobMeta ); try { database.connect(); RowMetaInterface row = database.getTableFieldsMeta( wSchemaname.getText(), wTablename.getText() ); String[] available = row.getFieldNames(); String[] source = wOrderBy.getText().split( "," ); for ( int i = 0; i < source.length; i++ ) { source[i] = Const.trim( source[i] ); } int[] idxSource = Const.indexsOfStrings( source, available ); EnterSelectionDialog dialog = new EnterSelectionDialog( shell, available, BaseMessages.getString( PKG, "JobMssqlBulkLoad.SelectColumns.Title" ), BaseMessages.getString( PKG, "JobMssqlBulkLoad.SelectColumns.Message" ) ); dialog.setMulti( true ); dialog.setAvoidQuickSearch(); dialog.setSelectedNrs( idxSource ); if ( dialog.open() != null ) { String columns = ""; int[] idx = dialog.getSelectionIndeces(); for ( int i = 0; i < idx.length; i++ ) { if ( i > 0 ) { columns += ", "; } columns += available[idx[i]]; } wOrderBy.setText( columns ); } } catch ( KettleDatabaseException e ) { new ErrorDialog( shell, BaseMessages.getString( PKG, "System.Dialog.Error.Title" ), BaseMessages .getString( PKG, "JobMssqlBulkLoad.ConnectionError2.DialogMessage" ), e ); } finally { database.disconnect(); } } } }
Example 16
Source File: JobEntryMysqlBulkFileDialog.java From pentaho-kettle with Apache License 2.0 | 4 votes |
/** * Get a list of columns, comma separated, allow the user to select from it. * */ private void getListColumns() { if ( !Utils.isEmpty( wTablename.getText() ) ) { DatabaseMeta databaseMeta = jobMeta.findDatabase( wConnection.getText() ); if ( databaseMeta != null ) { Database database = new Database( loggingObject, databaseMeta ); database.shareVariablesWith( jobMeta ); try { database.connect(); RowMetaInterface row = database.getTableFieldsMeta( wSchemaname.getText(), wTablename.getText() ); String[] available = row.getFieldNames(); String[] source = wListColumn.getText().split( "," ); for ( int i = 0; i < source.length; i++ ) { source[i] = Const.trim( source[i] ); } int[] idxSource = Const.indexsOfStrings( source, available ); EnterSelectionDialog dialog = new EnterSelectionDialog( shell, available, BaseMessages.getString( PKG, "JobMysqlBulkFile.SelectColumns.Title" ), BaseMessages.getString( PKG, "JobMysqlBulkFile.SelectColumns.Message" ) ); dialog.setMulti( true ); dialog.setAvoidQuickSearch(); dialog.setSelectedNrs( idxSource ); if ( dialog.open() != null ) { String columns = ""; int[] idx = dialog.getSelectionIndeces(); for ( int i = 0; i < idx.length; i++ ) { if ( i > 0 ) { columns += ", "; } columns += available[idx[i]]; } wListColumn.setText( columns ); } } catch ( KettleDatabaseException e ) { new ErrorDialog( shell, BaseMessages.getString( PKG, "System.Dialog.Error.Title" ), BaseMessages .getString( PKG, "JobMysqlBulkFile.ConnectionError2.DialogMessage" ), e ); } finally { database.disconnect(); } } } }
Example 17
Source File: JobEntryMysqlBulkLoadDialog.java From pentaho-kettle with Apache License 2.0 | 4 votes |
/** * Get a list of columns, comma separated, allow the user to select from it. */ private void getListColumns() { if ( !Utils.isEmpty( wTablename.getText() ) ) { DatabaseMeta databaseMeta = jobMeta.findDatabase( wConnection.getText() ); if ( databaseMeta != null ) { Database database = new Database( loggingObject, databaseMeta ); database.shareVariablesWith( jobMeta ); try { database.connect(); String schemaTable = databaseMeta.getQuotedSchemaTableCombination( wSchemaname.getText(), wTablename.getText() ); RowMetaInterface row = database.getTableFields( schemaTable ); String[] available = row.getFieldNames(); String[] source = wListattribut.getText().split( "," ); for ( int i = 0; i < source.length; i++ ) { source[i] = Const.trim( source[i] ); } int[] idxSource = Const.indexsOfStrings( source, available ); EnterSelectionDialog dialog = new EnterSelectionDialog( shell, available, BaseMessages.getString( PKG, "JobMysqlBulkLoad.SelectColumns.Title" ), BaseMessages.getString( PKG, "JobMysqlBulkLoad.SelectColumns.Message" ) ); dialog.setMulti( true ); dialog.setAvoidQuickSearch(); dialog.setSelectedNrs( idxSource ); if ( dialog.open() != null ) { String columns = ""; int[] idx = dialog.getSelectionIndeces(); for ( int i = 0; i < idx.length; i++ ) { if ( i > 0 ) { columns += ", "; } columns += available[idx[i]]; } wListattribut.setText( columns ); } } catch ( KettleDatabaseException e ) { new ErrorDialog( shell, BaseMessages.getString( PKG, "System.Dialog.Error.Title" ), BaseMessages .getString( PKG, "JobMysqlBulkLoad.ConnectionError2.DialogMessage" ), e ); } finally { database.disconnect(); } } } }
Example 18
Source File: LDAPInput.java From pentaho-kettle with Apache License 2.0 | 4 votes |
private Object getAttributeValue( LDAPInputField field, Attribute attr, int i, Object outputRowData ) throws Exception { if ( field.getType() == ValueMetaInterface.TYPE_BINARY ) { // It's a binary field // no need to convert, just return the value as it try { return attr.get(); } catch ( java.lang.ClassCastException e ) { return attr.get().toString().getBytes(); } } String retval = null; if ( field.getReturnType() == LDAPInputField.FETCH_ATTRIBUTE_AS_BINARY && field.getType() == ValueMetaInterface.TYPE_STRING ) { // Convert byte[] to string return LDAPConnection.extractBytesAndConvertToString( attr, field.isObjectSid() ); } // extract as string retval = extractString( attr ); // DO Trimming! switch ( field.getTrimType() ) { case LDAPInputField.TYPE_TRIM_LEFT: retval = Const.ltrim( retval ); break; case LDAPInputField.TYPE_TRIM_RIGHT: retval = Const.rtrim( retval ); break; case LDAPInputField.TYPE_TRIM_BOTH: retval = Const.trim( retval ); break; default: break; } // DO CONVERSIONS... // ValueMetaInterface targetValueMeta = data.outputRowMeta.getValueMeta( i ); ValueMetaInterface sourceValueMeta = data.convertRowMeta.getValueMeta( i ); return targetValueMeta.convertData( sourceValueMeta, retval ); }
Example 19
Source File: JobEntryDelay.java From pentaho-kettle with Apache License 2.0 | 4 votes |
public String getRealMaximumTimeout() { return Const.trim( environmentSubstitute( getMaximumTimeout() ) ); }
Example 20
Source File: ValueDataUtil.java From pentaho-kettle with Apache License 2.0 | 2 votes |
/** * Trims a string: removes the leading and trailing spaces of a String. * * @param string * The string to trim * @return The trimmed string. * @deprecated Use {@link Const#trim(String)} instead */ @Deprecated public static final String trim( String string ) { return Const.trim( string ); }