コード例 #1
0
ファイル: Event.java プロジェクト: neonobjclash/davdroid
 public static String TimezoneDefToTzId(String timezoneDef) {
   try {
     CalendarBuilder builder = new CalendarBuilder();
     net.fortuna.ical4j.model.Calendar cal = builder.build(new StringReader(timezoneDef));
     VTimeZone timezone = (VTimeZone) cal.getComponent(VTimeZone.VTIMEZONE);
     return timezone.getTimeZoneId().getValue();
   } catch (Exception ex) {
     Log.w(TAG, "Can't understand time zone definition", ex);
   }
   return null;
 }
コード例 #2
0
  /** {@inheritDoc} */
  public VEvent createEvent(CalendarEvent event, List<User> attendees) {

    if (!isIcsEnabled()) {
      log.debug(
          "ExternalCalendaringService is disabled. Enable via calendar.ics.generation.enabled=true in sakai.properties");
      return null;
    }

    // timezone. All dates are in GMT so we need to explicitly set that
    TimeZoneRegistry registry = TimeZoneRegistryFactory.getInstance().createRegistry();
    TimeZone timezone = registry.getTimeZone("GMT");
    VTimeZone tz = timezone.getVTimeZone();

    // start and end date
    DateTime start = new DateTime(getStartDate(event.getRange()).getTime());
    DateTime end = new DateTime(getEndDate(event.getRange()).getTime());

    // create event incl title/summary
    VEvent vevent = new VEvent(start, end, event.getDisplayName());

    // add timezone
    vevent.getProperties().add(tz.getTimeZoneId());

    // add uid to event
    // could come from the vevent_uuid field in the calendar event, otherwise from event ID.
    String uuid = null;
    if (StringUtils.isNotBlank(event.getField("vevent_uuid"))) {
      uuid = event.getField("vevent_uuid");
    } else {
      uuid = event.getId();
    }
    vevent.getProperties().add(new Uid(uuid));

    // add sequence to event
    // will come from the vevent_sequnece field in the calendar event, otherwise skip it
    String sequence = null;
    if (StringUtils.isNotBlank(event.getField("vevent_sequence"))) {
      sequence = event.getField("vevent_sequence");
      vevent.getProperties().add(new Sequence(sequence));
    }

    // add description to event
    vevent.getProperties().add(new Description(event.getDescription()));

    // add location to event
    vevent.getProperties().add(new Location(event.getLocation()));

    // add organiser to event
    if (StringUtils.isNotBlank(event.getCreator())) {

      String creatorEmail = sakaiProxy.getUserEmail(event.getCreator());

      URI mailURI = createMailURI(creatorEmail);
      Cn commonName = new Cn(sakaiProxy.getUserDisplayName(event.getCreator()));

      Organizer organizer = new Organizer(mailURI);
      organizer.getParameters().add(commonName);
      vevent.getProperties().add(organizer);
    }

    // add attendees to event with 'required participant' role
    vevent = addAttendeesToEvent(vevent, attendees);

    // add URL to event, if present
    String url = null;
    if (StringUtils.isNotBlank(event.getField("vevent_url"))) {
      url = event.getField("vevent_url");
      Url u = new Url();
      try {
        u.setValue(url);
        vevent.getProperties().add(u);
      } catch (URISyntaxException e) {
        // it doesnt matter, ignore it
      }
    }

    if (log.isDebugEnabled()) {
      log.debug("VEvent:" + vevent);
    }

    return vevent;
  }