Пример #1
0
  private void applyEvent(NoteItem item, VEvent event) throws ValidationException {
    if (event.getSummary() == null) throw new ValidationException("Event summary is required");
    if (event.getStartDate() == null) throw new ValidationException("Event start date is required");

    if (event.getEndDate() == null && event.getDuration() == null)
      ICalendarUtils.setDuration(event, new Dur(0, 0, 0, 0));

    item.setDisplayName(event.getSummary().getValue());

    if (item.getIcalUid() == null) {
      if (event.getUid() != null) item.setIcalUid(event.getUid().getValue());
      else item.setIcalUid(item.getUid());
    }

    if (event.getDescription() != null) item.setBody(event.getDescription().getValue());

    java.util.Calendar now = java.util.Calendar.getInstance();
    if (event.getStartDate().getDate().before(now.getTime()))
      item.getTriageStatus().setCode(TriageStatus.CODE_DONE);
    else {
      java.util.Calendar later = java.util.Calendar.getInstance();
      later.add(java.util.Calendar.DAY_OF_MONTH, 2);
      if (event.getStartDate().getDate().after(later.getTime()))
        item.getTriageStatus().setCode(TriageStatus.CODE_LATER);
    }

    EventStamp es = StampUtils.getEventStamp(item);
    if (es == null) {
      es = entityFactory.createEventStamp(item);
      item.addStamp(es);
    }

    es.setEventCalendar(ICalendarUtils.createBaseCalendar(event));
  }
Пример #2
0
  @Override
  @SuppressWarnings("unchecked")
  public void parseEntity(@NonNull InputStream entity)
      throws IOException, InvalidResourceException {
    net.fortuna.ical4j.model.Calendar ical;
    try {
      CalendarBuilder builder = new CalendarBuilder();
      ical = builder.build(entity);

      if (ical == null) throw new InvalidResourceException("No iCalendar found");
    } catch (ParserException e) {
      throw new InvalidResourceException(e);
    }

    // event
    ComponentList events = ical.getComponents(Component.VEVENT);
    if (events == null || events.isEmpty()) throw new InvalidResourceException("No VEVENT found");
    VEvent event = (VEvent) events.get(0);

    if (event.getUid() != null) uid = event.getUid().getValue();
    else {
      Log.w(TAG, "Received VEVENT without UID, generating new one");
      generateUID();
    }

    if ((dtStart = event.getStartDate()) == null || (dtEnd = event.getEndDate()) == null)
      throw new InvalidResourceException("Invalid start time/end time/duration");

    if (hasTime(dtStart)) {
      validateTimeZone(dtStart);
      validateTimeZone(dtEnd);
    }

    // all-day events and "events on that day":
    // * related UNIX times must be in UTC
    // * must have a duration (set to one day if missing)
    if (!hasTime(dtStart) && !dtEnd.getDate().after(dtStart.getDate())) {
      Log.i(TAG, "Repairing iCal: DTEND := DTSTART+1");
      Calendar c = Calendar.getInstance(TimeZone.getTimeZone(Time.TIMEZONE_UTC));
      c.setTime(dtStart.getDate());
      c.add(Calendar.DATE, 1);
      dtEnd.setDate(new Date(c.getTimeInMillis()));
    }

    rrule = (RRule) event.getProperty(Property.RRULE);
    rdate = (RDate) event.getProperty(Property.RDATE);
    exrule = (ExRule) event.getProperty(Property.EXRULE);
    exdate = (ExDate) event.getProperty(Property.EXDATE);

    if (event.getSummary() != null) summary = event.getSummary().getValue();
    if (event.getLocation() != null) location = event.getLocation().getValue();
    if (event.getDescription() != null) description = event.getDescription().getValue();

    status = event.getStatus();

    opaque = true;
    if (event.getTransparency() == Transp.TRANSPARENT) opaque = false;

    organizer = event.getOrganizer();
    for (Object o : event.getProperties(Property.ATTENDEE)) attendees.add((Attendee) o);

    Clazz classification = event.getClassification();
    if (classification != null) {
      if (classification == Clazz.PUBLIC) forPublic = true;
      else if (classification == Clazz.CONFIDENTIAL || classification == Clazz.PRIVATE)
        forPublic = false;
    }

    this.alarms = event.getAlarms();
  }