public static Calendar createCalendar(CalDavEvent calDavEvent, DateTimeZone timeZone) { TimeZoneRegistry registry = TimeZoneRegistryFactory.getInstance().createRegistry(); TimeZone timezone = registry.getTimeZone(timeZone.getID()); Calendar calendar = new Calendar(); calendar.getProperties().add(Version.VERSION_2_0); calendar.getProperties().add(new ProdId("openHAB")); VEvent vEvent = new VEvent(); vEvent.getProperties().add(new Summary(calDavEvent.getName())); vEvent.getProperties().add(new Description(calDavEvent.getContent())); final DtStart dtStart = new DtStart(new net.fortuna.ical4j.model.DateTime(calDavEvent.getStart().toDate())); dtStart.setTimeZone(timezone); vEvent.getProperties().add(dtStart); final DtEnd dtEnd = new DtEnd(new net.fortuna.ical4j.model.DateTime(calDavEvent.getEnd().toDate())); dtEnd.setTimeZone(timezone); vEvent.getProperties().add(dtEnd); vEvent.getProperties().add(new Uid(calDavEvent.getId())); vEvent.getProperties().add(Clazz.PUBLIC); vEvent .getProperties() .add( new LastModified( new net.fortuna.ical4j.model.DateTime(calDavEvent.getLastChanged().toDate()))); calendar.getComponents().add(vEvent); return calendar; }
@Override public void init() throws ServletException { // TODO Auto-generated method stub super.init(); filePath = getServletContext().getRealPath("") + File.separator + "schedule.ics"; try { ical.getProperties().add(new ProdId("-//Ben Fortuna//iCal4j 1.0//EN")); ical.getProperties().add(Version.VERSION_2_0); ical.getProperties().add(CalScale.GREGORIAN); } catch (Exception e) { System.out.println("iCalendar failed to import"); } registry = TimeZoneRegistryFactory.getInstance().createRegistry(); timezone = registry.getTimeZone("America/New_York"); tz = timezone.getVTimeZone(); try { // Register the driver. Class.forName("org.postgresql.Driver").newInstance(); } catch (Exception e) { e.printStackTrace(); } String url = "jdbc:postgresql://hopper.cs.wlu.edu/corsola"; try { con = DriverManager.getConnection(url, "web", ""); } catch (SQLException e) { e.printStackTrace(); } }
private DtStart getStartDateProperty(Date startDate) { DateTime date = convertRaplaLocaleToUTC(startDate); TimeZoneRegistry registry = TimeZoneRegistryFactory.getInstance().createRegistry(); net.fortuna.ical4j.model.TimeZone tz = registry.getTimeZone(timeZone.getID()); date.setTimeZone(tz); return new DtStart(date); }
@Inject public Export2iCalConverter( TimeZoneConverter timezoneConverter, RaplaLocale raplaLocale, Logger logger, ClientFacade facade) throws RaplaException { this.timezoneConverter = timezoneConverter; this.facade = facade; this.raplaLocale = raplaLocale; this.logger = logger; TimeZone zone = timezoneConverter.getImportExportTimeZone(); calendar = raplaLocale.createCalendar(); DynamicType[] dynamicTypes = facade.getDynamicTypes(DynamicTypeAnnotations.VALUE_CLASSIFICATION_TYPE_RESOURCE); for (DynamicType type : dynamicTypes) { if (type.getAnnotation(DynamicTypeAnnotations.KEY_LOCATION) != null) { hasLocationType = true; } } CompatibilityHints.setHintEnabled(CompatibilityHints.KEY_RELAXED_VALIDATION, true); RaplaConfiguration config = facade .getSystemPreferences() .getEntry(Export2iCalPlugin.ICAL_CONFIG, new RaplaConfiguration()); global_export_attendees = config .getChild(Export2iCalPlugin.EXPORT_ATTENDEES) .getValueAsBoolean(Export2iCalPlugin.DEFAULT_exportAttendees); global_export_attendees_participation_status = config .getChild(Export2iCalPlugin.EXPORT_ATTENDEES_PARTICIPATION_STATUS) .getValue(Export2iCalPlugin.DEFAULT_attendee_participation_status); try { exportAttendeesAttribute = config.getChild(Export2iCalPlugin.EXPORT_ATTENDEES_EMAIL_ATTRIBUTE).getValue(); } catch (ConfigurationException e) { exportAttendeesAttribute = ""; getLogger().info("ExportAttendeesMailAttribute is not set. So do not export as meeting"); } if (zone != null) { final String timezoneId = zone.getID(); try { TimeZoneRegistry registry = TimeZoneRegistryFactory.getInstance().createRegistry(); timeZone = registry.getTimeZone(timezoneId); } catch (Exception rc) { final VTimeZone vTimeZone = new VTimeZone(); timeZone = new net.fortuna.ical4j.model.TimeZone(vTimeZone); final int rawOffset = zone.getRawOffset(); timeZone.setRawOffset(rawOffset); } } }
/** * Build iCalendar-compliant recurrence rule * * @param recurrence * @param recurrenceEnd * @return rrule */ public static String getRecurrenceRule(final String recurrence, final Date recurrenceEnd) { final TimeZone tz = TimeZoneRegistryFactory.getInstance() .createRegistry() .getTimeZone(java.util.Calendar.getInstance().getTimeZone().getID()); if (recurrence != null) { // recurrence available // create recurrence rule final StringBuilder sb = new StringBuilder(); sb.append("FREQ="); if (recurrence.equals(CalendarEntry.WORKDAILY)) { // build rule for monday to friday sb.append(CalendarEntry.DAILY); sb.append(";"); sb.append("BYDAY=MO,TU,WE,TH,FR"); } else if (recurrence.equals(CalendarEntry.BIWEEKLY)) { // build rule for biweekly sb.append(CalendarEntry.WEEKLY); sb.append(";"); sb.append("INTERVAL=2"); } else { // normal supported recurrence sb.append(recurrence); } if (recurrenceEnd != null) { final DateTime recurEndDT = new DateTime(recurrenceEnd.getTime()); recurEndDT.setTimeZone(tz); sb.append(";"); sb.append(CalendarEntry.UNTIL); sb.append("="); sb.append(recurEndDT.toString()); } try { final Recur recur = new Recur(sb.toString()); final RRule rrule = new RRule(recur); return rrule.getValue(); } catch (final ParseException e) { log.error("cannot create recurrence rule: " + recurrence.toString(), e); } } return null; }
/** * Fügt die Wiederholungen des übergebenen Appointment-Objekts dem übergebenen * Event-Objekt hinzu. * * @param appointment Ein Rapla Appointment. */ private void addRepeatings(Appointment appointment, PropertyList properties) { Repeating repeating = appointment.getRepeating(); if (repeating == null) { return; } // This returns the strings DAYLY, WEEKLY, MONTHLY, YEARLY String type = repeating.getType().toString().toUpperCase(); Recur recur; // here is evaluated, if a COUNT is set in Rapla, or an enddate is // specified if (repeating.getNumber() == -1) { recur = new Recur(type, -1); } else if (repeating.isFixedNumber()) { recur = new Recur(type, repeating.getNumber()); } else { net.fortuna.ical4j.model.Date endDate = new net.fortuna.ical4j.model.Date(repeating.getEnd()); // TODO do we need to translate the enddate in utc? recur = new Recur(type, endDate); } if (repeating.isDaily()) { // DAYLY -> settings : intervall recur.setInterval(repeating.getInterval()); } else if (repeating.isWeekly()) { // WEEKLY -> settings : every nTh Weekday recur.setInterval(repeating.getInterval()); calendar.setTime(appointment.getStart()); recur.getDayList().add(WeekDay.getWeekDay(calendar)); } else if (repeating.isMonthly()) { // MONTHLY -> settings : every nTh Weekday recur.setInterval(repeating.getInterval()); calendar.setTime(appointment.getStart()); int weekofmonth = Math.round(calendar.get(java.util.Calendar.DAY_OF_MONTH) / DateTools.DAYS_PER_WEEK) + 1; recur.getDayList().add(new WeekDay(WeekDay.getWeekDay(calendar), weekofmonth)); } else if (repeating.isYearly()) { // YEARLY -> settings : every nTh day mTh Monthname calendar.setTime(appointment.getStart()); calendar.get(java.util.Calendar.DAY_OF_YEAR); } else { getLogger().warn("Invalid data in recurrency rule!"); } properties.add(new RRule(recur)); // bugfix - if rapla has no exceptions, an empty EXDATE: element is // produced. This may bother some iCal tools if (repeating.getExceptions().length == 0) { return; } // Add exception dates // DateList dl = new DateList(Value.DATE); ExDate exDate = new ExDate(); TimeZoneRegistry registry = TimeZoneRegistryFactory.getInstance().createRegistry(); net.fortuna.ical4j.model.TimeZone tz = registry.getTimeZone(timeZone.getID()); // rku: use seperate EXDATE for each exception for (Iterator<Date> itExceptions = Arrays.asList(repeating.getExceptions()).iterator(); itExceptions.hasNext(); ) { // DateList dl = new DateList(Value.DATE); Date date = itExceptions.next(); // dl.add(new net.fortuna.ical4j.model.Date( date)); java.util.Calendar cal = raplaLocale.createCalendar(); cal.setTime(date); int year = cal.get(java.util.Calendar.YEAR); int day_of_year = cal.get(java.util.Calendar.DAY_OF_YEAR); cal.setTime(appointment.getStart()); cal.set(java.util.Calendar.YEAR, year); cal.set(java.util.Calendar.DAY_OF_YEAR, day_of_year); int offset = (int) (tz.getOffset(DateTools.cutDate(date).getTime()) / DateTools.MILLISECONDS_PER_HOUR); cal.add(java.util.Calendar.HOUR, -offset); Date dateToSave = cal.getTime(); net.fortuna.ical4j.model.DateTime dateTime = new net.fortuna.ical4j.model.DateTime(); dateTime.setTime(dateToSave.getTime()); exDate.getDates().add(dateTime); } exDate.setTimeZone(tz); properties.add(exDate); // properties.add(new ExDate(dl)); }
public void setUp() throws Exception { super.setUp(); registry = TimeZoneRegistryFactory.getInstance().createRegistry(); // create timezone property.. tz = registry.getTimeZone("Australia/Melbourne").getVTimeZone(); // create tzid parameter.. tzParam = new TzId(tz.getProperties().getProperty(Property.TZID).getValue()); Calendar weekday9AM = getCalendarInstance(); weekday9AM.set(2005, Calendar.MARCH, 7, 9, 0, 0); weekday9AM.set(Calendar.MILLISECOND, 0); Calendar weekday5PM = getCalendarInstance(); weekday5PM.set(2005, Calendar.MARCH, 7, 17, 0, 0); weekday5PM.set(Calendar.MILLISECOND, 0); // Do the recurrence until December 31st. Calendar untilCal = getCalendarInstance(); untilCal.set(2005, Calendar.DECEMBER, 31); untilCal.set(Calendar.MILLISECOND, 0); Date until = new Date(untilCal.getTime().getTime()); // 9:00AM to 5:00PM Rule using weekly Recur recurWeekly = new Recur(Recur.WEEKLY, until); recurWeekly.getDayList().add(WeekDay.MO); recurWeekly.getDayList().add(WeekDay.TU); recurWeekly.getDayList().add(WeekDay.WE); recurWeekly.getDayList().add(WeekDay.TH); recurWeekly.getDayList().add(WeekDay.FR); recurWeekly.setInterval(1); recurWeekly.setWeekStartDay(WeekDay.MO.getDay()); RRule rruleWeekly = new RRule(recurWeekly); // 9:00AM to 5:00PM Rule using daily frequency Recur recurDaily = new Recur(Recur.DAILY, until); recurDaily.getDayList().add(WeekDay.MO); recurDaily.getDayList().add(WeekDay.TU); recurDaily.getDayList().add(WeekDay.WE); recurDaily.getDayList().add(WeekDay.TH); recurDaily.getDayList().add(WeekDay.FR); recurDaily.setInterval(1); recurDaily.setWeekStartDay(WeekDay.MO.getDay()); RRule rruleDaily = new RRule(recurDaily); // 9:00AM to 5:00PM Rule using monthly frequency Recur recurMonthly = new Recur(Recur.MONTHLY, until); recurMonthly.getDayList().add(WeekDay.MO); recurMonthly.getDayList().add(WeekDay.TU); recurMonthly.getDayList().add(WeekDay.WE); recurMonthly.getDayList().add(WeekDay.TH); recurMonthly.getDayList().add(WeekDay.FR); recurMonthly.setInterval(1); recurMonthly.setWeekStartDay(WeekDay.MO.getDay()); RRule rruleMonthly = new RRule(recurMonthly); Summary summary = new Summary("TEST EVENTS THAT HAPPEN 9-5 MON-FRI DEFINED WEEKLY"); weekdayNineToFiveEvents = new VEvent(); weekdayNineToFiveEvents.getProperties().add(rruleWeekly); weekdayNineToFiveEvents.getProperties().add(summary); DtStart dtStart = new DtStart(new DateTime(weekday9AM.getTime().getTime())); // dtStart.getParameters().add(Value.DATE); weekdayNineToFiveEvents.getProperties().add(dtStart); DtEnd dtEnd = new DtEnd(new DateTime(weekday5PM.getTime().getTime())); // dtEnd.getParameters().add(Value.DATE); weekdayNineToFiveEvents.getProperties().add(dtEnd); // ensure event is valid.. weekdayNineToFiveEvents.validate(); summary = new Summary("TEST EVENTS THAT HAPPEN 9-5 MON-FRI DEFINED DAILY"); dailyWeekdayEvents = new VEvent(); dailyWeekdayEvents.getProperties().add(rruleDaily); dailyWeekdayEvents.getProperties().add(summary); DtStart dtStart2 = new DtStart(new DateTime(weekday9AM.getTime().getTime())); // dtStart2.getParameters().add(Value.DATE); dailyWeekdayEvents.getProperties().add(dtStart2); DtEnd dtEnd2 = new DtEnd(new DateTime(weekday5PM.getTime().getTime())); // dtEnd2.getParameters().add(Value.DATE); dailyWeekdayEvents.getProperties().add(dtEnd2); // ensure event is valid.. dailyWeekdayEvents.validate(); summary = new Summary("TEST EVENTS THAT HAPPEN 9-5 MON-FRI DEFINED MONTHLY"); monthlyWeekdayEvents = new VEvent(); monthlyWeekdayEvents.getProperties().add(rruleMonthly); monthlyWeekdayEvents.getProperties().add(summary); DtStart dtStart3 = new DtStart(new DateTime(weekday9AM.getTime().getTime())); // dtStart3.getParameters().add(Value.DATE); monthlyWeekdayEvents.getProperties().add(dtStart3); DtEnd dtEnd3 = new DtEnd(new DateTime(weekday5PM.getTime().getTime())); // dtEnd3.getParameters().add(Value.DATE); monthlyWeekdayEvents.getProperties().add(dtEnd3); // ensure event is valid.. monthlyWeekdayEvents.validate(); }
/** {@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; }