Package org.pentaho.reporting.libraries.formula

Examples of org.pentaho.reporting.libraries.formula.LocalizationContext


    }
  }

  public static Date now(final FormulaContext context)
  {
    final LocalizationContext localizationContext = context.getLocalizationContext();
    final GregorianCalendar gc =
        new GregorianCalendar(localizationContext.getTimeZone(), localizationContext.getLocale());
    gc.setTime(context.getCurrentDate());
    gc.set(Calendar.MILLISECOND, 0);
    return gc.getTime();
  }
View Full Code Here


      {
        throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE);
      }
    }

    final LocalizationContext localizationContext = context.getLocalizationContext();
    final Date prevweekday = prevweekday(type, localizationContext);

    final Date date = DateUtil.normalizeDate(prevweekday, DateTimeType.DATE_TYPE);
    return new TypeValuePair(DateTimeType.DATE_TYPE, date);
  }
View Full Code Here

    return new TypeValuePair(DateTimeType.DATE_TYPE, date);
  }

  private static Date yesterday(final FormulaContext context)
  {
    final LocalizationContext localizationContext = context.getLocalizationContext();
    final GregorianCalendar gc = new GregorianCalendar(localizationContext.getTimeZone(),
        localizationContext.getLocale());
    gc.setTime(context.getCurrentDate());
    gc.set(Calendar.MILLISECOND, 0);
    gc.add(Calendar.DAY_OF_MONTH, -1);
    return gc.getTime();
  }
View Full Code Here

    if (date1 == null || date2 == null)
    {
      throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE);
    }

    final LocalizationContext localizationContext = context.getLocalizationContext();
    final TimeZone timeZone = localizationContext.getTimeZone();
    final Locale locale = localizationContext.getLocale();
    final GregorianCalendar calandar1 = new GregorianCalendar(timeZone, locale);
    calandar1.setTime(min(date1, date2));

    final GregorianCalendar calandar2 = new GregorianCalendar(timeZone, locale);
    calandar2.setTime(max(date1, date2));
View Full Code Here

   * @throws NumberFormatException if the type cannot be represented as number.
   */
  public Number convertToNumber(final Type sourceType, final Object value)
      throws EvaluationException
  {
    final LocalizationContext localizationContext = context.getLocalizationContext();

    if (value == null)
    {
      // there's no point in digging deeper - there *is* no value ..
      throw TypeConversionException.getInstance();
    }

    final boolean isAnyType = sourceType.isFlagSet(Type.ANY_TYPE);
    if (sourceType.isFlagSet(Type.NUMERIC_TYPE) || isAnyType)
    {
      if (sourceType.isFlagSet(Type.DATETIME_TYPE)
          || sourceType.isFlagSet(Type.TIME_TYPE)
          || sourceType.isFlagSet(Type.DATE_TYPE)
          || isAnyType)
      {
        if (value instanceof Date)
        {
          final BigDecimal serial = HSSFDateUtil.getExcelDate((Date) value);
          return DateUtil.normalizeDate(serial, sourceType);
        }
      }

      if (value instanceof Number)
      {
        return (Number) value;
      }
    }

    if (sourceType.isFlagSet(Type.LOGICAL_TYPE) || isAnyType)
    {
      if (value instanceof Boolean)
      {
        if (Boolean.TRUE.equals(value))
        {
          return NUM_TRUE;
        }
        else
        {
          return NUM_FALSE;
        }
      }
    }

    if (sourceType.isFlagSet(Type.TEXT_TYPE) || isAnyType)
    {
      final String val = computeStringValue(value);

      // first, try to parse the value as a big-decimal.
      try
      {
        return new BigDecimal(val);
      }
      catch (NumberFormatException e)
      {
        // ignore ..
      }

      for (final DateFormat df : localizationContext.getDateFormats(DateTimeType.DATETIME_TYPE))
      {
        final Date date = parse(df, val);
        if (date != null)
        {
          return HSSFDateUtil.getExcelDate(date);
        }
      }

      for (final DateFormat df : localizationContext.getDateFormats(DateTimeType.DATE_TYPE))
      {
        final Date date = parse(df, val);
        if (date != null)
        {
          return HSSFDateUtil.getExcelDate(date);
        }
      }

      for (final DateFormat df : localizationContext.getDateFormats(DateTimeType.TIME_TYPE))
      {
        final Date date = parse(df, val);
        if (date != null)
        {
          return HSSFDateUtil.getExcelDate(date);
        }
      }

      // then checking for numbers
      for (final NumberFormat format : localizationContext.getNumberFormats())
      {
        final Number number = parse(format, val);
        if (number != null)
        {
          return number;
View Full Code Here

    }

    // 2 types of numeric : numbers and dates
    if (type1.isFlagSet(Type.NUMERIC_TYPE))
    {
      final LocalizationContext localizationContext = context.getLocalizationContext();
      if (type1.isFlagSet(Type.DATETIME_TYPE) || type1.isFlagSet(Type.DATE_TYPE) || type1.isFlagSet(Type.TIME_TYPE))
      {
        final Date d = convertToDate(type1, value);
        final List dateFormats = localizationContext.getDateFormats(type1);
        if (dateFormats != null && dateFormats.size() >= 1)
        {
          final DateFormat format = (DateFormat) dateFormats.get(0);
          return format.format(d);
        }
        else
        {
          // fallback
          return DateFormat.getDateTimeInstance
              (DateFormat.FULL, DateFormat.FULL, localizationContext.getLocale()).format(d);
        }
      }
      else
      {
        try
        {
          final Number n = convertToNumber(type1, value);
          final List<NumberFormat> numberFormats = localizationContext.getNumberFormats();
          if (numberFormats.isEmpty())
          {
            // use the canonical format ..
            return NumberFormat.getNumberInstance(localizationContext.getLocale()).format(n);
          }
          else
          {
            numberFormats.get(0).format(n);
          }
View Full Code Here

    if (date1 == null || date2 == null)
    {
      throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE);
    }

    final LocalizationContext localizationContext = context.getLocalizationContext();
    final TimeZone timeZone = localizationContext.getTimeZone();
    final Locale locale = localizationContext.getLocale();
    final GregorianCalendar calandar1 =
        new GregorianCalendar(timeZone, locale);
    calandar1.setTime(date1);

    final GregorianCalendar calandar2 =
View Full Code Here

    {
      throw EvaluationException.getInstance(
          LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE);
    }

    final LocalizationContext localizationContext = context
        .getLocalizationContext();
    final java.sql.Date date = DateUtil.createDate(n1.intValue(),
        n2.intValue(), n3.intValue(), localizationContext);

    return new TypeValuePair(DateTimeType.DATE_TYPE, date);
View Full Code Here

    if (d == null)
    {
      throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE);
    }

    final LocalizationContext localizationContext = context.getLocalizationContext();
    final Date monthend = monthend(d, localizationContext);


    final Date date = DateUtil.normalizeDate(monthend, DateTimeType.DATE_TYPE);
    return new TypeValuePair(DateTimeType.DATE_TYPE, date);
View Full Code Here

    }
    final int hours = n1.intValue();
    final int minutes = n2.intValue();
    final int seconds = n3.intValue();

    final LocalizationContext localizationContext = context.getLocalizationContext();
    final Time time = DateUtil.createTime(hours, minutes, seconds, localizationContext);
    return new TypeValuePair(DateTimeType.TIME_TYPE, time);
  }
View Full Code Here

TOP

Related Classes of org.pentaho.reporting.libraries.formula.LocalizationContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.