Search in sources :

Example 1 with Property

use of net.fortuna.ical4j.model.Property 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 Property

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

the class ZoneInfo2iCalendar method makeOldTimeZonesMap.

private static Map<String, VTimeZone> makeOldTimeZonesMap(Params params) {
    Map<String, VTimeZone> oldTimeZones = Maps.newHashMap();
    if (null != params.oldTimezonesFileName) {
        try (FileInputStream fin = new FileInputStream(params.oldTimezonesFileName)) {
            CalendarBuilder builder = new CalendarBuilder();
            net.fortuna.ical4j.model.Calendar calendar = builder.build(fin, "UTF-8");
            for (Iterator i = calendar.getComponents().iterator(); i.hasNext(); ) {
                Component component = (Component) i.next();
                if (Component.VTIMEZONE.equals(component.getName())) {
                    VTimeZone vtz = (VTimeZone) component;
                    Property tzprop = vtz.getProperties().getProperty(Property.TZID);
                    if (null != tzprop) {
                        oldTimeZones.put(tzprop.getValue(), vtz);
                    }
                }
            }
        } catch (IOException | ParserException e) {
            System.err.println("Problem loading old timezones.ics - ignoring it.  " + e.getMessage());
        }
    }
    return oldTimeZones;
}
Also used : ParserException(net.fortuna.ical4j.data.ParserException) CalendarBuilder(net.fortuna.ical4j.data.CalendarBuilder) VTimeZone(net.fortuna.ical4j.model.component.VTimeZone) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) Iterator(java.util.Iterator) Component(net.fortuna.ical4j.model.Component) XProperty(net.fortuna.ical4j.model.property.XProperty) Property(net.fortuna.ical4j.model.Property)

Example 3 with Property

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

the class DefaultTnefToICalendar method addRecurrenceRelatedProps.

private void addRecurrenceRelatedProps(ContentHandler icalOutput, RecurrenceDefinition recurDef, TimeZoneDefinition tzDef, boolean isAllDayEvent) throws ServiceException, ParserException, URISyntaxException, IOException, ParseException {
    // returning at this point for those 3 methods.
    if (recurDef != null) {
        Property recurrenceProp = recurDef.icalRecurrenceProperty(isAllDayEvent, false);
        IcalUtil.addProperty(icalOutput, recurrenceProp);
        for (DateTime exDate : recurDef.getExdates()) {
            IcalUtil.addPropertyFromUtcTimeAndZone(icalOutput, Property.EXDATE, exDate, tzDef, isAllDayEvent);
        }
        for (DateTime rDate : recurDef.getRdates()) {
            IcalUtil.addPropertyFromUtcTimeAndZone(icalOutput, Property.RDATE, rDate, tzDef, isAllDayEvent);
        }
    }
}
Also used : XProperty(net.fortuna.ical4j.model.property.XProperty) Property(net.fortuna.ical4j.model.Property) DateTime(net.fortuna.ical4j.model.DateTime)

Example 4 with Property

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

the class TimeZoneDefinition method addVtimezone.

public void addVtimezone(ContentHandler icalOutput) throws ParserException, URISyntaxException, IOException, ParseException {
    if (getTimezoneName() == null) {
        return;
    }
    if (effectiveRule == null) {
        return;
    }
    getTimeZone();
    if (theZone == null) {
        return;
    }
    VTimeZone vtz = theZone.getVTimeZone();
    icalOutput.startComponent(Component.VTIMEZONE);
    for (Object obj : vtz.getProperties()) {
        if (obj instanceof Property) {
            Property currProp = (Property) obj;
            IcalUtil.addProperty(icalOutput, currProp);
        }
    }
    for (Object obj : vtz.getObservances()) {
        if (obj instanceof Component) {
            Component currComp = (Component) obj;
            icalOutput.startComponent(currComp.getName());
            for (Object propObj : currComp.getProperties()) {
                if (propObj instanceof Property) {
                    Property obsProp = (Property) propObj;
                    IcalUtil.addProperty(icalOutput, obsProp);
                }
            }
            icalOutput.endComponent(currComp.getName());
        }
    }
    icalOutput.endComponent(Component.VTIMEZONE);
    if (true) {
        return;
    }
}
Also used : VTimeZone(net.fortuna.ical4j.model.component.VTimeZone) Component(net.fortuna.ical4j.model.Component) Property(net.fortuna.ical4j.model.Property)

Example 5 with Property

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

the class EventReloaderJob method readCategory.

/**
     * Returns a list of categories or an empty list if none found.
     *
     * @param vEvent
     * @return
     */
private List<String> readCategory(VEvent vEvent) {
    PropertyList propertyCategoryList = vEvent.getProperties(Property.CATEGORIES);
    ArrayList<String> splittedCategoriesToReturn = new ArrayList<String>();
    if (propertyCategoryList != null) {
        for (int categoriesLineNum = 0; categoriesLineNum < propertyCategoryList.size(); categoriesLineNum++) {
            Property propertyCategory = propertyCategoryList.get(categoriesLineNum);
            String categories = propertyCategory.getValue();
            if (categories != null) {
                String[] categoriesSplit = StringUtils.split(categories, ",");
                for (String category : categoriesSplit) {
                    if (!splittedCategoriesToReturn.contains(category)) {
                        splittedCategoriesToReturn.add(category);
                    }
                }
            }
        }
    }
    return splittedCategoriesToReturn;
}
Also used : PropertyList(net.fortuna.ical4j.model.PropertyList) ArrayList(java.util.ArrayList) Property(net.fortuna.ical4j.model.Property)

Aggregations

Property (net.fortuna.ical4j.model.Property)5 VTimeZone (net.fortuna.ical4j.model.component.VTimeZone)3 XProperty (net.fortuna.ical4j.model.property.XProperty)3 Component (net.fortuna.ical4j.model.Component)2 TZDataParseException (com.zimbra.common.calendar.ZoneInfoParser.TZDataParseException)1 ZoneLine (com.zimbra.common.calendar.ZoneInfoParser.ZoneLine)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 ParseException (java.text.ParseException)1 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 CalendarBuilder (net.fortuna.ical4j.data.CalendarBuilder)1 ParserException (net.fortuna.ical4j.data.ParserException)1 DateTime (net.fortuna.ical4j.model.DateTime)1 PropertyList (net.fortuna.ical4j.model.PropertyList)1 LastModified (net.fortuna.ical4j.model.property.LastModified)1