Java Code Examples for org.eclipse.birt.core.data.DataTypeUtil#toLocaleNeutralString()

The following examples show how to use org.eclipse.birt.core.data.DataTypeUtil#toLocaleNeutralString() . 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: TemplateMessageServiceBaseImpl.java    From axelor-open-suite with GNU Affero General Public License v3.0 6 votes vote down vote up
private Object convertValue(String type, String value) throws BirtException {

    if (DesignChoiceConstants.PARAM_TYPE_BOOLEAN.equals(type)) {
      return DataTypeUtil.toBoolean(value);
    } else if (DesignChoiceConstants.PARAM_TYPE_DATETIME.equals(type)) {
      return DataTypeUtil.toDate(value);
    } else if (DesignChoiceConstants.PARAM_TYPE_DATE.equals(type)) {
      return DataTypeUtil.toSqlDate(value);
    } else if (DesignChoiceConstants.PARAM_TYPE_TIME.equals(type)) {
      return DataTypeUtil.toSqlTime(value);
    } else if (DesignChoiceConstants.PARAM_TYPE_DECIMAL.equals(type)) {
      return DataTypeUtil.toBigDecimal(value);
    } else if (DesignChoiceConstants.PARAM_TYPE_FLOAT.equals(type)) {
      return DataTypeUtil.toDouble(value);
    } else if (DesignChoiceConstants.PARAM_TYPE_STRING.equals(type)) {
      return DataTypeUtil.toLocaleNeutralString(value);
    } else if (DesignChoiceConstants.PARAM_TYPE_INTEGER.equals(type)) {
      return DataTypeUtil.toInteger(value);
    }
    return value;
  }
 
Example 2
Source File: ChartUtil.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns the string representation for given object. null for null object.
 * 
 * @param value
 * @return string value
 */
public static String stringValue( Object value )
{
	if ( value == null )
	{
		return null;
	}
	if ( value instanceof Calendar )
	{
		// Convert to use locale neutral format
		value = ( (Calendar) value ).getTime( );
	}
	try
	{
		return DataTypeUtil.toLocaleNeutralString( value );
	}
	catch ( BirtException e )
	{
	}
	return String.valueOf( value );
}
 
Example 3
Source File: DataUtil.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Convert object to be exported as CSV
 * 
 * @param value
 * @return
 * @throws BirtException
 */
public static String getCSVDisplayValue( Object value )
		throws BirtException
{
	if ( value == null )
		return null;

	if ( value instanceof Integer || value instanceof Long
			|| value instanceof Float || value instanceof Double
			|| value instanceof BigDecimal
			|| value instanceof com.ibm.icu.math.BigDecimal )
	{
		return value.toString( );
	}

	return DataTypeUtil.toLocaleNeutralString( value );
}
 
Example 4
Source File: EngineTask.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public static Object convertParameterType( Object value, String type )
		throws BirtException
{
	if ( DesignChoiceConstants.PARAM_TYPE_BOOLEAN.equals( type ) )
	{
		return DataTypeUtil.toBoolean( value );
	}
	else if ( DesignChoiceConstants.PARAM_TYPE_DATETIME.equals( type ) )
	{
		return DataTypeUtil.toDate( value );
	}
	else if ( DesignChoiceConstants.PARAM_TYPE_DATE.equals( type ) )
	{
		return DataTypeUtil.toSqlDate( value );
	}
	else if ( DesignChoiceConstants.PARAM_TYPE_TIME.equals( type ) )
	{
		return DataTypeUtil.toSqlTime( value );
	}
	else if ( DesignChoiceConstants.PARAM_TYPE_DECIMAL.equals( type ) )
	{
		return DataTypeUtil.toBigDecimal( value );
	}
	else if ( DesignChoiceConstants.PARAM_TYPE_FLOAT.equals( type ) )
	{
		return DataTypeUtil.toDouble( value );
	}
	else if ( DesignChoiceConstants.PARAM_TYPE_STRING.equals( type ) )
	{
		return DataTypeUtil.toLocaleNeutralString( value );
	}
	else if ( DesignChoiceConstants.PARAM_TYPE_INTEGER.equals( type ) )
	{
		return DataTypeUtil.toInteger( value );
	}
	return value;
}
 
Example 5
Source File: SelectValueDialog.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
private String getDataText( Object element )
{
	if ( element != null )
	{
		try
		{
			return DataTypeUtil.toLocaleNeutralString( element );
		}
		catch ( BirtException e )
		{
			ExceptionHandler.handle( e );
		}
	}
	return null;
}
 
Example 6
Source File: BirtComp.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * @param obj1
 * @param obj2
 * @return true x matches SQL pattern y
 * @throws BirtException
 * @throws DataException
 */
private static boolean like( Object source, Object pattern, boolean ignorecase ) throws BirtException
{
	String sourceStr = null;
	sourceStr = (source == null)? "": DataTypeUtil.toLocaleNeutralString( source );
	String patternStr;
	patternStr = ( pattern == null )? "" : DataTypeUtil.toLocaleNeutralString( pattern );
	
	// As per Bugzilla 115940, LIKE operator's pattern syntax is SQL-like: it
	// recognizes '_' and '%'. Backslash '\' escapes the next character.
	
	// Construct a Java RegExp pattern based on input. We need to translate 
	// unescaped '%' to '.*', and '_' to '.'
	// Also need to escape any RegExp metacharacter in the source pattern.
	
	final String reservedChars = "([{^$|)?*+.";
	int patternLen = patternStr.length();
	StringBuffer buffer = new StringBuffer( patternLen * 2 );
	
	for ( int i = 0; i < patternLen; i++)
	{
		char c = patternStr.charAt(i);
		if ( c == '\\' )
		{
			// Escape char; copy next character to new pattern if 
			// it is '\', '%' or '_'
			++i;
			if ( i < patternLen )
			{
				c = patternStr.charAt( i );
				if ( c == '%' || c == '_' )
					buffer.append( c );
				else if ( c == '\\' )
					buffer.append( "\\\\");		// Need to escape \
			}
			else
			{
				buffer.append( "\\\\" );  	// Leave last \ and escape it
			}
		}
		else if ( c == '%')
		{
			buffer.append(".*");
		}
		else if ( c == '_')
		{
			buffer.append(".");
		}
		else
		{
			// Copy this char to target, escape if it is a metacharacter
			if ( reservedChars.indexOf(c) >= 0 )
			{
				buffer.append('\\');
			}
			buffer.append(c);
		}
	}
	
	try
	{
		String newPatternStr = buffer.toString( );
		Pattern p = null;
		// Support search in multiple lines
		if ( !ignorecase )
		{
			p = Pattern.compile( newPatternStr, Pattern.DOTALL );
		}
		else
		{
			p = Pattern.compile( newPatternStr,
					Pattern.DOTALL | Pattern.CASE_INSENSITIVE );
		}
		Matcher m = p.matcher( sourceStr.toString( ) );
		return m.matches( );
	}
	catch ( PatternSyntaxException e )
	{
		throw new BirtException( e.getMessage( ) );
	}
}
 
Example 7
Source File: LocaleNeutralFormatter.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
public String formatValue( Object value ) throws BirtException
{
	return DataTypeUtil.toLocaleNeutralString( value );
}