Example #1
0
  @Override
  protected void validate(
      List<ICalComponent> components, ICalVersion version, List<Warning> warnings) {
    if (dates.isEmpty() && periods.isEmpty()) {
      // no value
      warnings.add(Warning.validate(26));
    }

    if (!dates.isEmpty() && !periods.isEmpty()) {
      // can't mix dates and periods
      warnings.add(Warning.validate(49));
    }

    if (version == ICalVersion.V1_0 && !periods.isEmpty()) {
      // 1.0 doesn't support periods
      warnings.add(Warning.validate(51));
    }

    if (!dates.isEmpty()) {
      // can't mix date and date-time values
      boolean hasTime = dates.get(0).hasTime();
      for (ICalDate date : dates.subList(1, dates.size())) {
        if (date.hasTime() != hasTime) {
          warnings.add(Warning.validate(50));
          break;
        }
      }
    }
  }
  @Override
  protected void _writeXml(ExceptionDates property, XCalElement element, WriteContext context) {
    List<ICalDate> values = property.getValues();
    if (values.isEmpty()) {
      element.append(defaultDataType(context.getVersion()), "");
      return;
    }

    if (isInObservance(context)) {
      for (ICalDate value : values) {
        String valueStr = date(value).observance(true).extended(true).write();
        element.append(DATE_TIME, valueStr);
      }
      return;
    }

    for (ICalDate value : values) {
      ICalDataType dataType = value.hasTime() ? DATE_TIME : DATE;
      String dateStr = date(value, property, context).extended(true).write();
      element.append(dataType, dateStr);
    }
  }