Example #1
0
  /** Prints the properties of the class for debugging purpose. */
  @Override
  public String toString() {
    String result = "";
    result += "recurFrequency: " + String.format("%#02x", this.recurFrequency) + "\n";
    result += "patternType: " + String.format("%#02x", this.patternType.getValue()) + "\n";
    result += "calendarType: " + String.format("%#02x", this.calendarType) + "\n";
    result += "endType: " + String.format("%#04x", this.endType) + "\n";

    result += "period: " + this.period + "\n";
    result += "occurenceCount: " + String.format("%#04x", this.occurenceCount) + "\n";
    result += "patternSpecific1: " + String.format("%#04x", this.patternSpecific1) + "\n";
    result += "patternSpecific2: " + String.format("%#04x", this.patternSpecific2) + "\n";
    result += "startDate hex: " + String.format("%#04x", this.startDate) + "\n";
    result += "endDate hex: " + String.format("%#04x", this.endDate) + "\n";

    result +=
        "startDate: "
            + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
                .format(windowsTimeToDateObject(this.startDate))
            + "\n";
    result +=
        "endDate: "
            + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
                .format(windowsTimeToDateObject(this.endDate))
            + "\n";

    for (int i = 0; i < modifiedInstanceCount; i++) {
      result +=
          "modified Instance date hex: " + String.format("%#04x", this.modifiedInstances[i]) + "\n";

      result +=
          "modified Instance date: "
              + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z")
                  .format(windowsTimeToDateObject(this.modifiedInstances[i]))
              + "\n";
    }

    for (int i = 0; i < deletedInstanceCount; i++) {
      result +=
          "deleted Instance date: "
              + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z").format(deletedInstances.get(i))
              + "\n";
    }
    result += "patternSpecific2: " + String.format("%#04x", this.patternSpecific2) + "\n";

    result += "\n\n =====================Exeptions====================\n\n";

    for (ExceptionInfo info : exceptionInfo) {
      result += info.toString() + "\n\n";
    }
    return result;
  }
Example #2
0
  /**
   * Parses the binary data that describes the recurrent pattern.
   *
   * @param data the binary data.
   * @param sourceTask the calendar item.
   */
  public RecurringPattern(byte[] data, CalendarItemTimerTask sourceTask) {
    this.sourceTask = sourceTask;
    dataBuffer = ByteBuffer.wrap(data).order(ByteOrder.LITTLE_ENDIAN);

    int offset = 4;
    recurFrequency = dataBuffer.getShort(offset);
    offset += 2;

    patternType = PatternType.getFromShort(dataBuffer.getShort(offset));
    offset += 2;

    calendarType = dataBuffer.getShort(offset);
    offset += 2;

    firstDateTime = dataBuffer.getInt(offset);
    offset += 4;

    period = dataBuffer.getInt(offset);
    offset += 4;

    slidingFlag = dataBuffer.getInt(offset);
    offset += 4;

    switch (patternType) {
      case Week:
      case Month:
      case MonthEnd:
      case HjMonth:
      case HjMonthEnd:
        patternSpecific1 = dataBuffer.getInt(offset);
        patternSpecific2 = 0;
        offset += 4;
        if (patternType == PatternType.Week) {
          for (int day = firstDow; day < firstDow + 7; day++) {
            if ((patternSpecific1 & (weekOfDayMask[day % 7])) != 0) {
              allowedDaysOfWeek.add((day % 7) + 1);
            }
          }
        }
        break;
      case MonthNth:
      case HjMonthNth:
        patternSpecific1 = dataBuffer.getInt(offset);
        patternSpecific2 = dataBuffer.getInt(offset + 4);
        if (patternSpecific1 == 0x7f && patternSpecific2 != 0x5) {
          patternType = PatternType.Month;
        }
        for (int day = 0; day < 7; day++) {
          if ((patternSpecific1 & (weekOfDayMask[day])) != 0) {
            allowedDaysOfWeek.add((day) + 1);
          }
        }
        offset += 8;
        break;
      default:
        break;
    }

    // endType
    endType = dataBuffer.getInt(offset);
    offset += 4;

    occurenceCount = dataBuffer.getInt(offset);
    offset += 4;

    firstDow = dataBuffer.getInt(offset);
    offset += 4;

    deletedInstanceCount = dataBuffer.getInt(offset);
    offset += 4;

    // deleted instances
    for (int i = 0; i < deletedInstanceCount; i++) {
      deletedInstances.add(windowsTimeToDateObject(dataBuffer.getInt(offset)));
      offset += 4;
    }

    modifiedInstanceCount = dataBuffer.getInt(offset);
    offset += 4;

    // modified instances
    modifiedInstances = new int[modifiedInstanceCount];

    for (int i = 0; i < modifiedInstanceCount; i++) {
      modifiedInstances[i] = dataBuffer.getInt(offset);
      offset += 4;
    }

    startDate = dataBuffer.getInt(offset);
    offset += 4;

    endDate = dataBuffer.getInt(offset);
    offset += 4;

    offset += 16;

    short exceptionCount = dataBuffer.getShort(offset);
    offset += 2;
    exceptionInfo = new ArrayList<ExceptionInfo>(exceptionCount);
    for (int i = 0; i < exceptionCount; i++) {
      ExceptionInfo tmpExceptionInfo = new ExceptionInfo(offset);
      exceptionInfo.add(tmpExceptionInfo);
      offset += tmpExceptionInfo.sizeInBytes();

      CalendarService.BusyStatusEnum status = tmpExceptionInfo.getBusyStatus();
      Date startTime = tmpExceptionInfo.getStartDate();
      Date endTime = tmpExceptionInfo.getEndDate();
      if (status == CalendarService.BusyStatusEnum.FREE || startTime == null || endTime == null)
        continue;
      Date currentTime = new Date();

      if (endTime.before(currentTime) || endTime.equals(currentTime)) return;

      boolean executeNow = false;

      if (startTime.before(currentTime) || startTime.equals(currentTime)) executeNow = true;

      CalendarItemTimerTask task =
          new CalendarItemTimerTask(
              status, startTime, endTime, sourceTask.getId(), executeNow, this);

      task.scheduleTasks();
    }
  }