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

The following examples show how to use org.eclipse.birt.core.data.DataTypeUtil#toDate() . 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: BirtDuration.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
protected Object getValue( Object[] args ) throws BirtException
{
	Duration duration;
	Date date;
	try
	{
		duration = DatatypeFactory.newInstance( )
				.newDuration( args[0].toString( ) );
		date = DataTypeUtil.toDate( args[1] );
	}
	catch ( DatatypeConfigurationException e )
	{
		throw new IllegalArgumentException( Messages.getFormattedString( "error.BirtDuration.literal.invalidArgument",
				args ) );
	}
	duration.addTo( date );
	return date;
}
 
Example 2
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 3
Source File: DateGroupCalculator.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 
 * @param intervalStart
 * @param intervalRange
 * @throws BirtException
 */
public DateGroupCalculator(Object intervalStart, double intervalRange, ULocale locale, TimeZone timeZone ) throws BirtException
{
	super( intervalStart, intervalRange );
	range = (int)Math.round( intervalRange );
	range = (range == 0 ? 1 : range);
	if ( intervalStart != null )
		this.intervalStart = DataTypeUtil.toDate( intervalStart );
	this.locale = locale == null ? ULocale.getDefault( ):locale;
	this.timeZone = timeZone == null ? TimeZone.getDefault( ):timeZone;
	Calendar c = Calendar.getInstance( this.locale );
	c.setTimeZone( this.timeZone );
	c.clear( );
	c.set( 1970, 0, 1 );
	defaultStart = c.getTime( );
	
	this.dateTimeUtil = new DateTimeUtil( this.locale, this.timeZone );
}
 
Example 4
Source File: ParameterValidationUtil.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Validates the input value at the given locale. The format is: short date
 * and medium time.
 * 
 * @param value
 *            the value to validate
 * @param locale
 *            the locale information
 * @param timeZone
 *            the time zone information
 * @return the date value if validation is successful
 * @throws ValidationValueException
 *             if the value is invalid
 */

private static final Date doValidateDateTime( String value, ULocale locale,
		TimeZone timeZone ) throws ValidationValueException
{
	try
	{
		return DataTypeUtil.toDate( value, locale, timeZone );
	}
	catch ( BirtException e )
	{
		throw new ValidationValueException( value,
				PropertyValueException.DESIGN_EXCEPTION_INVALID_VALUE,
				DesignChoiceConstants.PARAM_TYPE_DATETIME );
	}
}
 
Example 5
Source File: BirtDateTime.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
protected Object getValue( Object[] args ) throws BirtException
{
	if( existNullValue( args ) )
	{
		return null;
	}
	Date date = DataTypeUtil.toDate(args[0]);
	Calendar cal = getCalendar( date );
	int quarter = quarter( date );

	cal.set( Calendar.MONTH, ( quarter - 1 ) * 3 );
	cal.set( Calendar.DAY_OF_MONTH, 1 );
	return cal.getTime( );
}
 
Example 6
Source File: DateGroupCalculator.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 
 * @param intervalStart
 * @param intervalRange
 * @throws BirtException
 */
public DateGroupCalculator(Object intervalStart, double intervalRange) throws BirtException
{
	super( intervalStart, intervalRange );
	if ( intervalStart != null )
		this.intervalStart = DataTypeUtil.toDate( intervalStart );
}
 
Example 7
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 8
Source File: FormatUtil.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Formats scalar parameter value.
 * 
 * @param handle
 * @param inputStr
 * @return formatted value.
 */

private static String formatScalarParameter( ScalarParameterHandle handle,
		String inputStr ) throws BirtException
{
	String pattern = handle.getPattern( );
	String category = handle.getCategory( );

	if ( pattern == null )
	{
		if ( isCustom( category ) )
		{
			return inputStr;
		}
		pattern = category;
	}

	String dataType = handle.getDataType( );
	if ( DesignChoiceConstants.PARAM_TYPE_DATETIME.equals( dataType ) )
	{
		Date date = DataTypeUtil.toDate( inputStr, ULocale.US );
		DateFormatter formatter = new DateFormatter( pattern );
		inputStr = formatter.format( date );
	}
	else if ( DesignChoiceConstants.PARAM_TYPE_FLOAT.equals( dataType ) )
	{
		inputStr = new NumberFormatter( pattern ).format( DataTypeUtil.toDouble( inputStr )
				.doubleValue( ) );
	}
	else if ( DesignChoiceConstants.PARAM_TYPE_DECIMAL.equals( dataType ) )
	{
		inputStr = new NumberFormatter( pattern ).format( DataTypeUtil.toBigDecimal( inputStr ) );
	}
	else if ( DesignChoiceConstants.PARAM_TYPE_STRING.equals( dataType ) )
	{
		inputStr = new StringFormatter( pattern ).format( inputStr );
	}
	return inputStr;
}
 
Example 9
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 10
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 11
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 12
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 13
Source File: DataUtil.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Convert parameter to Object with locale setting
 * 
 * @param dataType
 * @param format
 * @param value
 * @param locale
 * @return
 * @throws ValidationValueException
 */
public static Object validateWithLocale( String dataType, String format,
		String value, Locale locale, TimeZone timeZone ) throws ValidationValueException
{
	Object obj = null;
	if ( value == null || IBirtConstants.NULL_VALUE.equals(value) )
	{
		return null;
	}		
	
	try
	{
		if ( format == null )
		{
			if ( DesignChoiceConstants.PARAM_TYPE_DATE
					.equalsIgnoreCase( dataType ) )
			{
				format = ParameterValidationUtil.DISPLAY_DATE_FORMAT;
			}
			else if ( DesignChoiceConstants.PARAM_TYPE_TIME
					.equalsIgnoreCase( dataType ) )
			{
				format = ParameterValidationUtil.DISPLAY_TIME_FORMAT;
			}
			else if ( DesignChoiceConstants.PARAM_TYPE_DATETIME
					.equalsIgnoreCase( dataType ) )
			{
				format = DesignChoiceConstants.DATETIEM_FORMAT_TYPE_UNFORMATTED;
			}
		}

		// Convert locale string to object
		obj = ParameterValidationUtil.validate( dataType, format, value,
				locale, BirtUtility.toICUTimeZone( timeZone ) );
	}
	catch ( Exception e )
	{
		// Convert string to object using default format/local
		if ( DesignChoiceConstants.PARAM_TYPE_DATETIME
				.equalsIgnoreCase( dataType ) )
		{
			// Make the consistent with designer
			try
			{
				if ( timeZone != null )
				{
					obj = DataTypeUtil.toDate( value, BirtUtility.toICUTimeZone( timeZone ) );
				}
				else
				{
					obj = DataTypeUtil.toDate( value );
				}
			}
			catch ( BirtException el )
			{
				throw new ValidationValueException(
						value,
						PropertyValueException.DESIGN_EXCEPTION_INVALID_VALUE,
						DesignChoiceConstants.PARAM_TYPE_DATETIME );
			}
		}
		else if (DesignChoiceConstants.PARAM_TYPE_BOOLEAN.equalsIgnoreCase(dataType))
		{
			try
			{
				obj = ParameterValidationUtil.validate( dataType, format, String.valueOf( DataUtil.convert( (Object) value, ParameterDataTypeConverter.convertDataType(dataType) ) ),
						locale, BirtUtility.toICUTimeZone( timeZone ) );
			}
			catch ( Exception e2 )
			{
				throw new ValidationValueException(
						value,
						PropertyValueException.DESIGN_EXCEPTION_INVALID_VALUE,
						DesignChoiceConstants.PARAM_TYPE_BOOLEAN );
			}
		}
		else
		{
			
				obj = ParameterValidationUtil.validate( dataType,
						getDefaultDateFormat( dataType ), value, BirtUtility.toICUTimeZone( timeZone ) );
		}
	}

	return obj;
}
 
Example 14
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 15
Source File: ResultIterator.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
public Date getDate( String name ) throws BirtException
{
	return DataTypeUtil.toDate( getValue( name ) );
}
 
Example 16
Source File: DateGroupCalculator.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
protected Date getDate( Object value ) throws BirtException
{
	return DataTypeUtil.toDate( value );
}
 
Example 17
Source File: CacheResultIterator.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
public Date getDate( String name ) throws BirtException
{
	return DataTypeUtil.toDate( getValue( name ) );
}
 
Example 18
Source File: ResultIterator.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
public Date getDate( String name ) throws BirtException
{
	return DataTypeUtil.toDate( getValue( name ) );
}
 
Example 19
Source File: PreparedDummyQuery.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
public Date getDate( String name ) throws BirtException
{
	return DataTypeUtil.toDate( this.getValue( name ) );
}
 
Example 20
Source File: BaseScriptEvalUtil.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
private static Object[] populateObArray( Object obj, Object[] obArray )
{
	try
	{
		for ( int i = 0; i < obArray.length; i++ )
		{
			if( obArray[i] instanceof Object[] )
				return obArray;
		}
		if ( obj instanceof Number && !( obj instanceof BigDecimal ) )
		{
			for ( int i = 0; i < obArray.length; i++ )
			{
				obArray[i] = DataTypeUtil.toDouble( obArray[i] );
			}
		}
		else if ( obj instanceof java.sql.Date )
		{
			for ( int i = 0; i < obArray.length; i++ )
			{
				obArray[i] = DataTypeUtil.toSqlDate( obArray[i] );
			}
		}
		else if ( obj instanceof java.sql.Time )
		{
			for ( int i = 0; i < obArray.length; i++ )
			{
				obArray[i] = DataTypeUtil.toSqlTime( obArray[i] );
			}
		}
		else if ( obj instanceof Date )
		{
			for ( int i = 0; i < obArray.length; i++ )
			{
				obArray[i] = DataTypeUtil.toDate( obArray[i] );
			}
		}
	}
	catch ( BirtException e )
	{
		// If failed to convert to same date type for comparation,
		// simply convert them to String.
		try
		{
			makeObjectArrayStringArray( obArray );
		}
		catch ( BirtException e1 )
		{
			//should never reach here.
		}
	}
	// obArray will remain the same if obj is String rather than
	// Date,Number or Boolean
	return obArray;
}