Search in sources :

Example 1 with CalendarException

use of net.fortuna.ical4j.model.CalendarException in project bw-calendar-engine by Bedework.

the class CalendarBuilder method resolveTimezones.

private void resolveTimezones() throws IOException {
    // Go through each property and try to resolve the TZID.
    for (final Iterator it = datesMissingTimezones.iterator(); it.hasNext(); ) {
        final Property property = (Property) it.next();
        final Parameter tzParam = property.getParameter(Parameter.TZID);
        // tzParam might be null:
        if (tzParam == null) {
            continue;
        }
        // lookup timezone
        final TimeZone timezone = tzRegistry.getTimeZone(tzParam.getValue());
        // If timezone found, then update date property
        if (timezone != null) {
            // Get the String representation of date(s) as
            // we will need this after changing the timezone
            final String strDate = property.getValue();
            // Change the timezone
            if (property instanceof DateProperty) {
                ((DateProperty) property).setTimeZone(timezone);
            } else if (property instanceof DateListProperty) {
                ((DateListProperty) property).setTimeZone(timezone);
            }
            // Reset value
            try {
                property.setValue(strDate);
            } catch (ParseException e) {
                // shouldn't happen as its already been parsed
                throw new CalendarException(e);
            } catch (URISyntaxException e) {
                // shouldn't happen as its already been parsed
                throw new CalendarException(e);
            }
        }
    }
}
Also used : TimeZone(net.fortuna.ical4j.model.TimeZone) VTimeZone(net.fortuna.ical4j.model.component.VTimeZone) DateListProperty(net.fortuna.ical4j.model.property.DateListProperty) DateProperty(net.fortuna.ical4j.model.property.DateProperty) Iterator(java.util.Iterator) Parameter(net.fortuna.ical4j.model.Parameter) ParseException(java.text.ParseException) CalendarException(net.fortuna.ical4j.model.CalendarException) URISyntaxException(java.net.URISyntaxException) DateListProperty(net.fortuna.ical4j.model.property.DateListProperty) XProperty(net.fortuna.ical4j.model.property.XProperty) Property(net.fortuna.ical4j.model.Property) DateProperty(net.fortuna.ical4j.model.property.DateProperty)

Aggregations

URISyntaxException (java.net.URISyntaxException)1 ParseException (java.text.ParseException)1 Iterator (java.util.Iterator)1 CalendarException (net.fortuna.ical4j.model.CalendarException)1 Parameter (net.fortuna.ical4j.model.Parameter)1 Property (net.fortuna.ical4j.model.Property)1 TimeZone (net.fortuna.ical4j.model.TimeZone)1 VTimeZone (net.fortuna.ical4j.model.component.VTimeZone)1 DateListProperty (net.fortuna.ical4j.model.property.DateListProperty)1 DateProperty (net.fortuna.ical4j.model.property.DateProperty)1 XProperty (net.fortuna.ical4j.model.property.XProperty)1