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

The following examples show how to use org.eclipse.birt.core.data.DataTypeUtil#toString() . 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: ReportRunner.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @param p
 *            the scalar parameter
 * @param expr
 *            the default value expression
 */
protected Object stringToObject( int type, String value )
		throws BirtException
{
	if ( value == null )
	{
		return null;
	}
	switch ( type )
	{
		case IScalarParameterDefn.TYPE_BOOLEAN :
			return DataTypeUtil.toBoolean( value );

		case IScalarParameterDefn.TYPE_DATE :
			return DataTypeUtil.toSqlDate( value );

		case IScalarParameterDefn.TYPE_TIME :
			return DataTypeUtil.toSqlTime( value );
			
		case IScalarParameterDefn.TYPE_DATE_TIME :
			return DataTypeUtil.toDate( value );
		case IScalarParameterDefn.TYPE_DECIMAL :
			return DataTypeUtil.toBigDecimal( value );

		case IScalarParameterDefn.TYPE_FLOAT :
			return DataTypeUtil.toDouble( value );

		case IScalarParameterDefn.TYPE_STRING :
			return DataTypeUtil.toString( value );
		
		case IScalarParameterDefn.TYPE_INTEGER :
			return DataTypeUtil.toInteger( value );
	}
	return null;

}
 
Example 2
Source File: DataUtil.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Try convert an object to given type Types supported:
 * <p>
 * <ul>
 * <li>IScalarParameterDefn.TYPE_INTEGER</li>
 * <li>IScalarParameterDefn.TYPE_DECIMAL</li>
 * <li>IScalarParameterDefn.TYPE_BOOLEAN</li>
 * <li>IScalarParameterDefn.TYPE_DATE_TIME</li>
 * <li>IScalarParameterDefn.TYPE_FLOAT</li>
 * <li>IScalarParameterDefn.TYPE_STRING</li>
 * <li>IScalarParameterDefn.TYPE_DATE</li>
 * <li>IScalarParameterDefn.TYPE_TIME</li>
 * <ul>
 * </p>
 * 
 * @param source
 * @param toType
 * @return
 * @throws BirtException
 */
public static Object convert( Object source, int toType )
		throws BirtException
{
	if ( source == null )
		return null;

	// if any type, return directly.
	if ( toType == IScalarParameterDefn.TYPE_ANY )
		return source;

	switch ( toType )
	{
		case IScalarParameterDefn.TYPE_INTEGER :
			return DataTypeUtil.toInteger( source );
		case IScalarParameterDefn.TYPE_DECIMAL :
			return DataTypeUtil.toBigDecimal( source );
		case IScalarParameterDefn.TYPE_BOOLEAN :
			return DataTypeUtil.toBoolean( source );
		case IScalarParameterDefn.TYPE_DATE_TIME :
			return DataTypeUtil.toDate( source );
		case IScalarParameterDefn.TYPE_FLOAT :
			return DataTypeUtil.toDouble( source );
		case IScalarParameterDefn.TYPE_STRING :
			return DataTypeUtil.toString( source );
		case IScalarParameterDefn.TYPE_DATE :
			return DataTypeUtil.toSqlDate( source );
		case IScalarParameterDefn.TYPE_TIME :
			return DataTypeUtil.toSqlTime( source );
		default :
			throw new CoreException( "Invalid type." ); //$NON-NLS-1$
	}
}
 
Example 3
Source File: InputParameterDialog.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
private String getTextDefaultValue( )
{
	String result = EMPTY_VALUE_STR;
	try
	{
		result = DataTypeUtil.toString( defaultValue );
	}
	catch ( BirtException e )
	{
	}
	return formatString( result, parameter );
}
 
Example 4
Source File: InputParameterDialog.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
private String formatDate2String( Object value )
{
	String result = value.toString( );
	try
	{
		result = DataTypeUtil.toString( value );
	}
	catch ( BirtException e )
	{
	}
	return result;
}
 
Example 5
Source File: ParameterUtil.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public static Object convert( Object value, String dataType )
		throws BirtException
{
	if ( DesignChoiceConstants.PARAM_TYPE_BOOLEAN.equals( dataType ) )
	{
		return DataTypeUtil.toBoolean( value );
	}
	else if ( DesignChoiceConstants.PARAM_TYPE_DATETIME.equals( dataType ) )
	{
		return DataTypeUtil.toDate( value );
	}
	else if ( DesignChoiceConstants.PARAM_TYPE_DATE.equals( dataType ) )
	{
		return DataTypeUtil.toSqlDate( value );
	}
	else if ( DesignChoiceConstants.PARAM_TYPE_TIME.equals( dataType ) )
	{
		return DataTypeUtil.toSqlTime( value );
	}
	else if ( DesignChoiceConstants.PARAM_TYPE_DECIMAL.equals( dataType ) )
	{
		return DataTypeUtil.toBigDecimal( value );
	}
	else if ( DesignChoiceConstants.PARAM_TYPE_FLOAT.equals( dataType ) )
	{
		return DataTypeUtil.toDouble( value );
	}
	else if ( DesignChoiceConstants.PARAM_TYPE_STRING.equals( dataType ) )
	{
		return DataTypeUtil.toString( value );
	}
	else if ( DesignChoiceConstants.PARAM_TYPE_INTEGER.equals( dataType ) )
	{
		return DataTypeUtil.toInteger( value );
	}
	return value;
}
 
Example 6
Source File: DataTypeConvertUtil.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public static Object convert( 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_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.toString( value );
	}
	else if ( DesignChoiceConstants.PARAM_TYPE_INTEGER.equals( type ) )
	{
		return DataTypeUtil.toInteger( value );
	}
	return value;
}
 
Example 7
Source File: ReportItemExecutor.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
protected String evaluateString( Expression expr )
{
	try
	{
		Object value = context.evaluate( expr );
		return DataTypeUtil.toString( value );
	}
	catch ( BirtException ex )
	{
		context.addException( ex );
	}
	return null;
}
 
Example 8
Source File: ParameterSelectionChoice.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * set parameter choice value. The string value is in English locale, and needs to be parsed
 * back into object value based on the data type. 
 * 
 * @param value the string value for the object
 * @param type the parameter data type
 */
public void setValue(String value, int type) {
	try {
		switch (type) {
			case IScalarParameterDefn.TYPE_BOOLEAN:
				this.value = DataTypeUtil.toBoolean(value);
				break;
			case IScalarParameterDefn.TYPE_DATE_TIME:
				this.value = DataTypeUtil.toDate(value);
				break;
			case IScalarParameterDefn.TYPE_DECIMAL:
				this.value = DataTypeUtil.toBigDecimal(value);
				break;
			case IScalarParameterDefn.TYPE_FLOAT:
				this.value = DataTypeUtil.toDouble(value);
				break;
			case IScalarParameterDefn.TYPE_INTEGER:
				this.value = DataTypeUtil.toInteger( value );
				break;
			case IScalarParameterDefn.TYPE_DATE:
				this.value = DataTypeUtil.toSqlDate( value );
				break;
			case IScalarParameterDefn.TYPE_TIME:
				this.value = DataTypeUtil.toSqlTime( value );
				break;
			case IScalarParameterDefn.TYPE_STRING:
			default:
				this.value = DataTypeUtil.toString(value);
				break;
		}
	} 
	catch (BirtException e) {
		log.log(Level.SEVERE, e.getLocalizedMessage(), e);
		this.value = null;
	}
}
 
Example 9
Source File: ReportDataServiceProvider.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @param source
 * @return
 * @throws NumberFormatException
 * @throws BirtException
 */
private String valueAsString( Object source ) throws NumberFormatException,
		BirtException
{
	if ( source == null )
		return null;
	if ( source instanceof Number )
	{
		ULocale locale = ULocale.getDefault( );
		String value = source.toString( );
		int index = value.indexOf( 'E' );
		// It means the value is very larger, using E marked.
		if ( index >= 0 )
		{
			String returnValue = DataTypeUtil.toString( Double.valueOf( value.substring( 0,
					index ) ),
					locale )
					+ "E"; //$NON-NLS-1$
			String exponent = value.substring( index + 1 );
			if ( exponent.matches( "[\\+-]+[1-9]{1}[0-9]*" ) ) //$NON-NLS-1$
			{
				returnValue += exponent.substring( 0, 1 )
						+ DataTypeUtil.toString( Integer.valueOf( exponent.substring( 1 ) ),
								locale );
			}
			else
			{
				returnValue += DataTypeUtil.toString( Integer.valueOf( exponent ),
						locale );
			}
			return returnValue;
		}
	}
	return DataTypeUtil.toString( source );
}
 
Example 10
Source File: MetaWriter.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public void writeMeta( String creator, String title, String description, String subject ) throws BirtException
{		
	Date now = new Date();
	String nowString = DataTypeUtil.toString( now );
	writeTag( "dc:title", title );
	writeTag( "dc:description", description );
	writeTag( "dc:subject", subject );
	writeTag( "dc:date", nowString );
	writeTag( "meta:creation-date", nowString );
	writeTag( "meta:generator", "BIRT/2.6" ); // TODO: get version from engine?
}
 
Example 11
Source File: TotalConcatenate.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Set the separator of the concatenated string
 * 
 * @param source
 * @throws BirtException
 */
private void setSeparator( Object source ) throws BirtException
{
	String value = DataTypeUtil.toString( source );
	if ( value != null )
	{
		// should not trim the separator string
		separator = value;
	}
}
 
Example 12
Source File: BaseScriptEvalUtil.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 
 * @param obArray
 * @throws BirtException 
 */
private static void makeObjectArrayStringArray( Object[] obArray ) throws BirtException
{
	for ( int i = 0; i < obArray.length; i++ )
	{
		if ( obArray[i] != null )
			obArray[i] = DataTypeUtil.toString( obArray[i] );
	}
}
 
Example 13
Source File: ResultIterator.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
public String getString( String name ) throws BirtException
{
	return DataTypeUtil.toString( getValue( name ) );
}
 
Example 14
Source File: CacheResultIterator.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
public String getString( String name ) throws BirtException
{
	return DataTypeUtil.toString( getValue( name ) );
}
 
Example 15
Source File: ReportLauncher.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
public static Object convert( Object value, String dataType )
		throws BirtException
{
	if (value == null)
	{
		return value;
	}
	if ( DesignChoiceConstants.PARAM_TYPE_BOOLEAN.equals( dataType ) )
	{
		return DataTypeUtil.toBoolean( value );
	}
	else if ( DesignChoiceConstants.PARAM_TYPE_DATETIME.equals( dataType ) )
	{
		return DataTypeUtil.toDate( value );
	}
	else if ( DesignChoiceConstants.PARAM_TYPE_DATE.equals( dataType ) )
	{
		return DataTypeUtil.toSqlDate( value );
	}
	else if ( DesignChoiceConstants.PARAM_TYPE_TIME.equals( dataType ) )
	{
		return DataTypeUtil.toSqlTime( value );
	}
	else if ( DesignChoiceConstants.PARAM_TYPE_DECIMAL.equals( dataType ) )
	{
		return DataTypeUtil.toBigDecimal( value );
	}
	else if ( DesignChoiceConstants.PARAM_TYPE_FLOAT.equals( dataType ) )
	{
		return DataTypeUtil.toDouble( value );
	}
	else if ( DesignChoiceConstants.PARAM_TYPE_STRING.equals( dataType ) )
	{
		return DataTypeUtil.toString( value );
	}
	else if ( DesignChoiceConstants.PARAM_TYPE_INTEGER.equals( dataType ) )
	{
		return DataTypeUtil.toInteger( value );
	}
	return value;
}
 
Example 16
Source File: ResultIterator.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
public String getString( String name ) throws BirtException
{
	return DataTypeUtil.toString( getValue( name ) );
}
 
Example 17
Source File: PreparedDummyQuery.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
public String getString( String name ) throws BirtException
{
	return DataTypeUtil.toString( this.getValue( name ) );
}
 
Example 18
Source File: ScalarParameter.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Gets default value.
 * 
 * @return default value
 */

public String getDefaultValue( )
{
	IGetParameterDefinitionTask task = createParameterDefinitionTask( );
	try
	{
		Object obj = task.getDefaultValue( handle.getName( ) );
		if (obj == null)
		{
			return null;
		}
		if (obj instanceof Object[] )
		{
			Object[] objs = (Object[])obj;
			if (objs.length > 0)
			{
				oriDefaultValue = objs[0];
				return objs[0] != null ? objs[0].toString( ) : null;
			}
			else
			{
				return null;
			}
		}
		oriDefaultValue = obj;
		if (obj instanceof Date)
		{
			try
			{
				return DataTypeUtil.toString( obj );
			}
			catch ( BirtException e )
			{
				//return toString
			}
		}
		return obj.toString( );
	}
	finally
	{
		if ( task != null )
			task.close();
	}
}
 
Example 19
Source File: IFormatter.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
public String formatValue( Object value ) throws BirtException
{
	return DataTypeUtil.toString( value, locale );
}
 
Example 20
Source File: BirtComp.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * @param obj1
 * @param obj2
 * @return -1,0 and 1 standing for <,= and > respectively
 * @throws BirtException
 * @throws DataException
 */
private static int compare( Object obj1, Object obj2, Collator collator) throws BirtException
{
	if ( obj1 == null || obj2 == null )
	{
		// all non-null values are greater than null value
		if ( obj1 == null && obj2 != null )
			return -1;
		else if ( obj1 != null && obj2 == null )
			return 1;
		else
			return 0;
	}

	if ( isSameType( obj1, obj2 ) )
	{
		if ( obj1 instanceof Boolean )
		{
			if ( obj1.equals( obj2 ) )
				return 0;

			Boolean bool = (Boolean) obj1;
			if ( bool.equals( Boolean.TRUE ) )
				return 1;
			else
				return -1;
		}
		else if ( obj1 instanceof Comparable )
		{
			if ( obj1 instanceof String )
			{
				if ( collator == null )
                       return ( (String)obj1 ).compareTo( (String)obj2 );
				return compareAsString( obj1, obj2, collator );				
			}				
			else
			{
				return ( (Comparable) obj1 ).compareTo( obj2 );
			}
		}
		// most judgements should end here
		else
		{
			return compareAsString( obj1, obj2, collator );
		}
	}
	else if ( obj1 instanceof BigDecimal || obj2 instanceof BigDecimal )
	{
		BigDecimal a = DataTypeUtil.toBigDecimal( obj1 );
		BigDecimal b = DataTypeUtil.toBigDecimal( obj2 );
		return a.compareTo( b );
	}
	else if ( isNumericOrString( obj1 ) && isNumericOrString( obj2 ) )
	{
		return DataTypeUtil.toDouble( obj1 )
				.compareTo( DataTypeUtil.toDouble( obj2 ) );
	}
	else if ( isTimeOrString( obj1 ) && isTimeOrString( obj2) )
	{
		return DataTypeUtil.toSqlTime( obj1 )
				.compareTo( DataTypeUtil.toSqlTime( obj2 ) );
	}
	else if ( isSQLDateOrString( obj1 ) && isSQLDateOrString( obj2 ))
	{
		return DataTypeUtil.toSqlDate( obj1 )
				.compareTo( DataTypeUtil.toSqlDate( obj2 ) );
	}
	else if ( isDateOrString( obj1 ) && isDateOrString( obj2 ) )
	{
		return DataTypeUtil.toDate( obj1 )
				.compareTo( DataTypeUtil.toDate( obj2 ) );
	}
	else 
	{
		String object1 = null;
		String object2 = null;
		if (obj1 instanceof ScriptableObject)
			object1 = DataTypeUtil.toString(((ScriptableObject) obj1)
					.getDefaultValue(null));
		else
			object1 = DataTypeUtil.toString(obj1);

		if (obj2 instanceof ScriptableObject)
			object2 = DataTypeUtil.toString(((ScriptableObject) obj2)
					.getDefaultValue(null));
		else
			object2 = DataTypeUtil.toString(obj2);
		
		return compare( object1, object2,collator );
	}

}