Creating ICS Calendar Feeds with XPages

Creating ICS Calendar Feeds with XPages

An ICS Calendar feed can be used to exchange calendar data over the internet. It’s also known as iCalendar feed. ICS Calendar Feeds are supported by a vast amount of calendar clients such as Google Calendar / Android Calendar, Microsoft Outlook.. and of course IBM Notes.

The main benefit is to provide calendar data in an open standard format, so we don’t have to worry about the client in which they will be displayed. Users can retrieve also personalised calendar data through authentication.

Use Cases for subscribing an ICS Calendar feed:

  • displaying events from an application in my calendar.
  • displaying my next events (e.g. which i will attend) in my calendar (done with authentication).
  • displaying events that meet filter or search criteria (e.g. events held my home town).
  • etc.

As mentioned above when you develop an ICS Calendar feed in your XPage Application, users are not limited to IBM Notes to display these data. All clients which are able to consume ICS Calendar feeds can visualise these this feed. In IBM Notes, there is even an option to display the registered ICS Feed on the mobile device, and i’m sure others can do this as well.

icsfeed ot an xpages application

 

Let’s see this in action: When using this ICS Calendar feed: https://app.connect.uzh.ch/apps/id/kurse.nsf/icsfeed.xsp, i get the following results in the Notes client:

calendar-feed-add-notes

Example and Demo

I created a sample application that contains some data with music concerts happening in Switzerland in the near future.  There is an XPage that displays the concerts and you can also filter them by city. There is also a link at the bottom of the view, from which you can access the ICS Calendar feed webcal Link.

Let’s have a look at these components in detail:

Notes – Documents and Views

The concerts are stored in simple Notes Documents with MultiValue Date fields for start and end dates. .The sample database contains some test data of upcoming concerts. There is also a view from which the data is looked up for the XPages Browser UI and also for the ICS Calendar feed creation. The date / time values can be accessed as list from a column of the view. If you want to reuse the example, just copy/paste this view and change the selection and column formulas so they fit into this data model.

Java Managed Beans and biweekly library

biweekly is a neat little library with which you can read and write iCalendar or vCalendar data. It is easy to use and very lightweight. Also it does not require some java.policy changes and it has very low Java requirements (1.5), which can be an advantage when using Java on a Domino Server (nevertheless i think we all hope that the Java Version will be updated in the near future!).

As always in my XPages Applications, i always work with Java Objects rather than with Domino DataSources or ServerSide Javascript. I use the following architecture in order to separate the Presentation/View, Controller/Model (Business Logic) and the data (Notes Documents and Views).

Let’s dig a little deeper in the Controller / Model Layer:
These Classes are either Managed Beans or assoziated classes.

  • ControllerConcert
    This class is the main Java Managed Bean and creates the list of concert objects.
  • ControllerConcertIcsFeed
    Inherits from the ControllerConcert and implements the biweekly library in order to create ICS Feed of the list of concert objects.
  • Concert / TimeRange
    This is the Model: Concert Objects are created and fed with Notes Data by the ControllerConcert. It contains all the data of an event: Name, location, Date/Time (as assoziated TimeRange Object List). A Concert Object inherits of the DataObject Class (id and unid props).
  • DataAccessController
    This class reads from Notes documents or views.
 
	/**
	 * Creates a ICS Feed of all the concerts. The concerts are retrieved by the
	 * parent class ControllerConcerts
	 * 
	 * @return ICS Feed as String
	 */
	public String getConcertsAsIcs() {

		String result = "";
		try {

			// initiate the biweekly ICalendar object
			ICalendar ical = new ICalendar();

			// Setting the product ID / Description of the feed.
			ical.setProductId("Events as ICS Feed, City: "
					+ JSFUtil.getQueryString("city"));

			// Retrieving the concerts and fill the ICS Feed
			for (Concert concert : this.getConcerts()) {
				addIcsFeedElement(ical, concert);
			}

			// return the result as string
			result = ical.write();

		} catch (Exception e) {
			Util.logError(e);
		}

		return result;
	}

	/**
	 * Creates and adds a single VEvent Object to the ICalendar feed
	 * 
	 * @param ical
	 *            ICalendar Object
	 * @param concert
	 *            Single Concert Object
	 */
	private void addIcsFeedElement(ICalendar ical, Concert concert) {
		try {
			// Loops through the time ranges, since an event can have multiple
			// dates
			for (TimeRange tr : concert.getDates()) {
				VEvent event = new VEvent();
				event.setSummary(concert.getName() + "," + concert.getCity());
				event.setLocation(concert.getCity());
				event.setDateStart(tr.getDateTimeStart());
				event.setDateEnd(tr.getDateTimeEnd());
				ical.addEvent(event);
			}
		} catch (Exception e) {
			Util.logError(e);
		}
	}

 

XPage and ICS Feed Link dialog

As you see in the demo, the ICS feed URL can be selected and copied with a DOJO Dialog. It contains also a direct webcal Link, which should open the default Calendar application. Although i defined Notes as default Calendar program on my Windows Laptop, it still wants to open it in Outlook. On my OSX MacBook, the link works just fine.. To be on the save side, the dialog contains the possibility to simply copy the URL for the ICS Feed, which i recommend using ..

Conclusion

ICS Feeds are a powerful way to propagate date/time based data. Once used in an application, the reuse in another is very easy and without much effort. You might use the XPages/Java Managed Bean Layer to access some old, dusty 4.6 based Notes Database which might get second wind through ICS Calendar Feeds 🙂

Download Sample Application

Download Lotus Notes nsf File

Github repository Infos

Link to Github Repository: https://github.com/fdehedin/xpages_concerts

  • SSH URL
  • Clone URL

Leave a Reply

comment-avatar

*