Search in sources :

Example 1 with LastModified

use of net.fortuna.ical4j.model.property.LastModified in project zm-mailbox by Zimbra.

the class ZoneInfo2iCalendar method getTimeZoneForZoneLines.

/**
     * @param zoneLines - Only the zoneLines related to a time zone that might be relevant from the reference date.
     */
private static String getTimeZoneForZoneLines(String tzid, Set<String> aliases, List<ZoneLine> zoneLines, Params params, Set<String> zoneIDs, Map<String, VTimeZone> oldTimeZones) {
    if ((zoneLines == null) || (zoneLines.isEmpty())) {
        return "";
    }
    boolean isPrimary = sPrimaryTZIDs.contains(tzid);
    Integer matchScore = sMatchScores.get(tzid);
    if (matchScore == null) {
        if (isPrimary) {
            matchScore = Integer.valueOf(TZIDMapper.DEFAULT_MATCH_SCORE_PRIMARY);
        } else {
            matchScore = Integer.valueOf(TZIDMapper.DEFAULT_MATCH_SCORE_NON_PRIMARY);
        }
    }
    Iterator<String> aliasesIter = aliases.iterator();
    while (aliasesIter.hasNext()) {
        String curr = aliasesIter.next();
        if (zoneIDs.contains(curr)) {
            aliasesIter.remove();
        }
    }
    ZoneLine zline = zoneLines.get(0);
    VTimeZone oldVtz = oldTimeZones.get(zline.getName());
    Property oldLastModProp = null;
    if (null != oldVtz) {
        oldLastModProp = oldVtz.getProperties().getProperty(Property.LAST_MODIFIED);
    }
    LastModified newLastModified = getLastModified(params.lastModified);
    LastModified trialLastModified;
    if (null != oldLastModProp && oldLastModProp instanceof LastModified) {
        trialLastModified = (LastModified) oldLastModProp;
    } else {
        trialLastModified = newLastModified;
    }
    VTimeZone vtz = toVTimeZoneComp(params.referenceDate, zoneLines, trialLastModified, aliases, isPrimary, matchScore);
    String asText = vtz.toString();
    if ((null != oldVtz) && (trialLastModified != newLastModified)) {
        String oldText = oldVtz.toString();
        if (!asText.equals(oldText)) {
            /* Work around non-round tripped entries where the original source has:
                 *     X-ZIMBRA-TZ-ALIAS:(GMT+12.00) Anadyr\, Petropavlovsk-Kamchatsky (RTZ 11)
                 * but in this we have:
                 *     X-ZIMBRA-TZ-ALIAS:(GMT+12.00) Anadyr\\\, Petropavlovsk-Kamchatsky (RTZ 11)
                 * suspect that is a bug in libical which may be fixed in a later revision
                 */
            String oldText2 = oldText.replace("\\\\\\,", "\\,");
            if (!asText.equals(oldText2)) {
                LastModified lastModProp = (LastModified) vtz.getProperties().getProperty(Property.LAST_MODIFIED);
                try {
                    lastModProp.setValue(newLastModified.getValue());
                    asText = vtz.toString();
                } catch (ParseException e) {
                    System.err.println("Problem assigning LAST-MODIFIED - " + e.getMessage());
                }
            }
        }
    }
    return asText;
}
Also used : LastModified(net.fortuna.ical4j.model.property.LastModified) ZoneLine(com.zimbra.common.calendar.ZoneInfoParser.ZoneLine) VTimeZone(net.fortuna.ical4j.model.component.VTimeZone) ParseException(java.text.ParseException) TZDataParseException(com.zimbra.common.calendar.ZoneInfoParser.TZDataParseException) XProperty(net.fortuna.ical4j.model.property.XProperty) Property(net.fortuna.ical4j.model.Property)

Example 2 with LastModified

use of net.fortuna.ical4j.model.property.LastModified in project zm-mailbox by Zimbra.

the class ZoneInfo2iCalendar method getLastModified.

private static LastModified getLastModified(String lastModified) {
    LastModified lMod = null;
    DateTime dt;
    try {
        dt = new DateTime(lastModified);
        lMod = new LastModified(dt);
    } catch (ParseException e) {
        System.err.println(e.getMessage());
        System.err.println("String turning into LAST-MODIFIED: " + lastModified);
        e.printStackTrace();
        System.exit(1);
    }
    return lMod;
}
Also used : LastModified(net.fortuna.ical4j.model.property.LastModified) ParseException(java.text.ParseException) TZDataParseException(com.zimbra.common.calendar.ZoneInfoParser.TZDataParseException) DateTime(net.fortuna.ical4j.model.DateTime)

Example 3 with LastModified

use of net.fortuna.ical4j.model.property.LastModified in project openhab1-addons by openhab.

the class Util method createCalendar.

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;
}
Also used : VEvent(net.fortuna.ical4j.model.component.VEvent) Description(net.fortuna.ical4j.model.property.Description) Calendar(net.fortuna.ical4j.model.Calendar) TimeZoneRegistry(net.fortuna.ical4j.model.TimeZoneRegistry) ProdId(net.fortuna.ical4j.model.property.ProdId) LastModified(net.fortuna.ical4j.model.property.LastModified) Uid(net.fortuna.ical4j.model.property.Uid) DateTimeZone(org.joda.time.DateTimeZone) TimeZone(net.fortuna.ical4j.model.TimeZone) DtStart(net.fortuna.ical4j.model.property.DtStart) Summary(net.fortuna.ical4j.model.property.Summary) DtEnd(net.fortuna.ical4j.model.property.DtEnd)

Aggregations

LastModified (net.fortuna.ical4j.model.property.LastModified)3 TZDataParseException (com.zimbra.common.calendar.ZoneInfoParser.TZDataParseException)2 ParseException (java.text.ParseException)2 ZoneLine (com.zimbra.common.calendar.ZoneInfoParser.ZoneLine)1 Calendar (net.fortuna.ical4j.model.Calendar)1 DateTime (net.fortuna.ical4j.model.DateTime)1 Property (net.fortuna.ical4j.model.Property)1 TimeZone (net.fortuna.ical4j.model.TimeZone)1 TimeZoneRegistry (net.fortuna.ical4j.model.TimeZoneRegistry)1 VEvent (net.fortuna.ical4j.model.component.VEvent)1 VTimeZone (net.fortuna.ical4j.model.component.VTimeZone)1 Description (net.fortuna.ical4j.model.property.Description)1 DtEnd (net.fortuna.ical4j.model.property.DtEnd)1 DtStart (net.fortuna.ical4j.model.property.DtStart)1 ProdId (net.fortuna.ical4j.model.property.ProdId)1 Summary (net.fortuna.ical4j.model.property.Summary)1 Uid (net.fortuna.ical4j.model.property.Uid)1 XProperty (net.fortuna.ical4j.model.property.XProperty)1 DateTimeZone (org.joda.time.DateTimeZone)1