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;
}
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;
}
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);
}
}
}
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;
}
}
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;
}
Aggregations