Exemplo n.º 1
0
  /**
   * Imports a calendar object containing a VJOURNAL. Sets the following properties:
   *
   * <ul>
   *   <li>display name: the VJOURNAL's SUMMARY (or the item's name, if the SUMMARY is blank)
   *   <li>icalUid: the VJOURNAL's UID
   *   <li>body: the VJOURNAL's DESCRIPTION
   * </ul>
   */
  public void setCalendar(Calendar cal) throws DavException {
    NoteItem note = (NoteItem) getItem();

    ComponentList vjournals = cal.getComponents(Component.VJOURNAL);
    if (vjournals.isEmpty())
      throw new UnprocessableEntityException("VCALENDAR does not contain any VJOURNALS");

    EntityConverter converter = new EntityConverter(getEntityFactory());
    converter.convertJournalCalendar(note, cal);
  }
Exemplo n.º 2
0
  /**
   * Imports a calendar object containing a VTODO. Sets the following properties:
   *
   * <ul>
   *   <li>display name: the VTODO's SUMMARY (or the item's name, if the SUMMARY is blank)
   *   <li>icalUid: the VTODO's UID
   *   <li>body: the VTODO's DESCRIPTION
   *   <li>reminderTime: if the VTODO has a DISPLAY VALARM the reminderTime will be set to the
   *       trigger time
   * </ul>
   *
   * @param cal The calendar imported.
   * @throws CosmoDavException - if something is wrong this exception is thrown.
   */
  public void setCalendar(Calendar cal) throws CosmoDavException {
    NoteItem note = (NoteItem) getItem();

    ComponentList vtodos = cal.getComponents(Component.VTODO);
    if (vtodos.isEmpty()) {
      throw new UnprocessableEntityException("VCALENDAR does not contain any VTODOS");
    }

    EntityConverter converter = new EntityConverter(getEntityFactory());
    converter.convertTaskCalendar(note, cal);
  }
Exemplo n.º 3
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();
  }