Java Code Examples for org.pentaho.di.core.Const#ltrim()

The following examples show how to use org.pentaho.di.core.Const#ltrim() . 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: Value.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 2
Source File: ValueMetaBase.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
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 3
Source File: XMLInputSaxDataRetriever.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
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 4
Source File: LDAPInput.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
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 5
Source File: ValueDataUtil.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
/**
 * @deprecated Use {@link Const#ltrim(String)} instead
 */
@Deprecated
public static final String leftTrim( String string ) {
  return Const.ltrim( string );
}