use of net.fortuna.ical4j.model.PropertyList in project zm-mailbox by Zimbra.
the class ZoneInfo2iCalendar method toVTimeZonePropertyList.
private static PropertyList toVTimeZonePropertyList(ZoneLine zline, LastModified lastModified, Set<String> tzAliases, boolean isPrimary, Integer matchScore) {
PropertyList vtzProps = new PropertyList();
vtzProps.add(new TzId(zline.getName()));
vtzProps.add(lastModified);
if (isPrimary) {
vtzProps.add(new XProperty(TZIDMapper.X_ZIMBRA_TZ_PRIMARY, "TRUE"));
}
if (matchScore != null) {
vtzProps.add(new XProperty(TZIDMapper.X_ZIMBRA_TZ_MATCH_SCORE, matchScore.toString()));
}
if (tzAliases != null) {
for (String alias : tzAliases) {
vtzProps.add(new XProperty(TZIDMapper.X_ZIMBRA_TZ_ALIAS, alias));
}
}
return vtzProps;
}
use of net.fortuna.ical4j.model.PropertyList in project zm-mailbox by Zimbra.
the class ZoneInfo2iCalendar method toStandardComp.
private static Standard toStandardComp(Time gmtOffset, String tznameFormat) {
PropertyList props = new PropertyList();
if (tznameFormat != null && tznameFormat.length() > 0 && !tznameFormat.contains("%")) {
props.add(new TzName(iCalEscape(tznameFormat)));
}
props.add(getMsOutlookStyleDtstart());
String offset = getUtcOffset(gmtOffset);
UtcOffset utcOffset = new UtcOffset(offset);
props.add(new TzOffsetTo(utcOffset));
props.add(new TzOffsetFrom(utcOffset));
return new Standard(props);
}
use of net.fortuna.ical4j.model.PropertyList in project zm-mailbox by Zimbra.
the class ZoneInfo2iCalendar method toVTimeZoneComp.
/**
* @param referenceDate
* @param zline1 ZoneLine for 1st rule applicable after referenceDate
* @param zline2 ZoneLine for 2nd rule applicable after referenceDate
* @param obs1 Observances corresponding to zline1
* @param vtzProps Properties to associate with the VTIMEZONE component
* @param inDaylightTime true if referenceDate falls within daylight time by the rules in zline1
* @return best timezone or null if unable to determine one.
*/
private static VTimeZone toVTimeZoneComp(Calendar referenceDate, ZoneLine zline1, ZoneLine zline2, Observances obs1, PropertyList vtzProps, boolean inDaylightTime) {
int hintYear = referenceDate.get(Calendar.YEAR);
Observance obs4zl2;
Time daylightOffset;
Time standardOffset = zline2.getGmtOff();
String tznameFormat = zline2.getAbbrevFormat();
if (zline2.hasRule()) {
RuleInfo rl2 = getRuleInfo(hintYear, zline2);
daylightOffset = (null == rl2.daylight) ? standardOffset : addTimes(standardOffset, rl2.daylight.getSave());
if (inDaylightTime) {
obs4zl2 = toObservanceComp(hintYear, rl2.standard, true, /* isStandard */
standardOffset, daylightOffset, tznameFormat);
return toVTimeZoneComp(hintYear, new Observances(obs4zl2, obs1.daylight), vtzProps);
} else {
if (null == rl2.daylight) {
return null;
}
obs4zl2 = toObservanceComp(hintYear, rl2.daylight, false, /* isStandard */
standardOffset, daylightOffset, tznameFormat);
return toVTimeZoneComp(hintYear, new Observances(obs1.std, obs4zl2), vtzProps);
}
} else if (zline2.hasSave()) {
List<String> tokens = Lists.newArrayList();
Until prevRuleEnd = zline1.getUntil();
if (zline2.hasUntil()) {
Until currRuleEnd = zline2.getUntil();
if (null == currRuleEnd) {
// Don't think this can happen
return null;
}
String fromYear;
if (prevRuleEnd != null) {
fromYear = String.format("%d", prevRuleEnd.getYear());
} else {
fromYear = String.format("%d", hintYear);
}
String toYear = String.format("%d", currRuleEnd.getYear());
// NAME
tokens.add(getObservanceName(tznameFormat, null));
// FROM
tokens.add(fromYear);
// TO
tokens.add(toYear);
// TYPE
tokens.add("-");
// IN
tokens.add(ZoneInfoParser.Month.toString(currRuleEnd.getMonth()));
// ON
tokens.add(String.format("%s", currRuleEnd.getDay().toString()));
// AT
tokens.add(String.format("%s", currRuleEnd.getTime().toString()));
// SAVE
tokens.add(zline2.getSave().toString());
// LETTER/S
tokens.add("-");
RuleLine newRule = pseudoZoneLineTokensToRuleLine(tokens, zline2);
if (null == newRule) {
return null;
}
daylightOffset = addTimes(standardOffset, zline2.getSave());
obs4zl2 = toObservanceComp(hintYear, newRule, inDaylightTime, /* need the opposite */
standardOffset, daylightOffset, tznameFormat);
if (inDaylightTime) {
return toVTimeZoneComp(hintYear, new Observances(obs4zl2, obs1.daylight), vtzProps);
} else {
return toVTimeZoneComp(hintYear, new Observances(obs1.std, obs4zl2), vtzProps);
}
} else {
if (!inDaylightTime) {
// Only reason for having a save but no until is if changing to standard time only?
return null;
}
if (prevRuleEnd == null) {
return null;
}
String fromYear = String.format("%d", prevRuleEnd.getYear());
String toYear = "max";
// NAME
tokens.add(getObservanceName(tznameFormat, null));
// FROM
tokens.add(fromYear);
// TO
tokens.add(toYear);
// TYPE
tokens.add("-");
// IN
tokens.add(ZoneInfoParser.Month.toString(prevRuleEnd.getMonth()));
// ON
tokens.add(String.format("%s", prevRuleEnd.getDay().toString()));
// AT
tokens.add(String.format("%s", prevRuleEnd.getTime().toString()));
// SAVE
tokens.add(zline2.getSave().toString());
// LETTER/S
tokens.add("-");
RuleLine newRule = pseudoZoneLineTokensToRuleLine(tokens, zline2);
if (null == newRule) {
return null;
}
daylightOffset = standardOffset;
/* random value - fix later */
;
obs4zl2 = toObservanceComp(hintYear, newRule, true, standardOffset, daylightOffset, tznameFormat);
TzOffsetFrom stdOffsetFrom = (TzOffsetFrom) obs4zl2.getProperties().getProperty(Property.TZOFFSETFROM);
TzOffsetTo stdOffsetTo = (TzOffsetTo) obs4zl2.getProperties().getProperty(Property.TZOFFSETTO);
TzOffsetTo dlOffsetTo = (TzOffsetTo) obs1.daylight.getProperties().getProperty(Property.TZOFFSETTO);
if (stdOffsetTo.equals(dlOffsetTo)) {
// New standard time is same as current daylight time - just use observance.
obs4zl2 = toStandardComp(zline2.getGmtOff(), tznameFormat);
return toVTimeZoneComp(hintYear, new Observances(obs4zl2, null), vtzProps);
}
// Make sure that the zones are consistent with each other
stdOffsetFrom.setOffset(dlOffsetTo.getOffset());
TzOffsetFrom dlOffsetFrom = (TzOffsetFrom) obs1.daylight.getProperties().getProperty(Property.TZOFFSETFROM);
dlOffsetFrom.setOffset(stdOffsetTo.getOffset());
return toVTimeZoneComp(hintYear, new Observances(obs4zl2, obs1.daylight), vtzProps);
}
}
return null;
}
use of net.fortuna.ical4j.model.PropertyList in project zm-mailbox by Zimbra.
the class TimeZoneDefinition method getTimeZone.
/**
* @return the appropriate iCal4j TimeZone for this TimeZoneDefinition
*/
public TimeZone getTimeZone() {
if (theZone != null) {
return theZone;
}
if (effectiveRule == null) {
theZone = new TimeZone(0, TimeZones.UTC_ID);
return theZone;
}
if (!effectiveRule.hasDaylightSaving()) {
theZone = new TimeZone(effectiveRule.getStandardUtcOffsetMillis(), getTimezoneName());
return theZone;
}
UtcOffset stdOffset = effectiveRule.getStandardUtcOffset();
UtcOffset dlOffset = effectiveRule.getDaylightUtcOffset();
PropertyList vtzProps = new PropertyList();
TzId myTzid = new TzId(getTimezoneName());
vtzProps.add(myTzid);
VTimeZone vtz = new VTimeZone(vtzProps);
Standard stdComp = new Standard();
stdComp.getProperties().add(effectiveRule.getStandardDtStart());
stdComp.getProperties().add(effectiveRule.icalStandardRRule());
TzOffsetFrom offsetFrom = new TzOffsetFrom(dlOffset);
TzOffsetTo offsetTo = new TzOffsetTo(stdOffset);
stdComp.getProperties().add(offsetFrom);
stdComp.getProperties().add(offsetTo);
Daylight dayComp = new Daylight();
dayComp.getProperties().add(effectiveRule.getDaylightDtStart());
dayComp.getProperties().add(effectiveRule.icalDaylightRRule());
offsetFrom = new TzOffsetFrom(stdOffset);
offsetTo = new TzOffsetTo(dlOffset);
dayComp.getProperties().add(offsetFrom);
dayComp.getProperties().add(offsetTo);
vtz.getObservances().add(stdComp);
vtz.getObservances().add(dayComp);
try {
vtz.validate(true);
theZone = new TimeZone(vtz);
} catch (ValidationException e) {
if (sLog.isDebugEnabled()) {
sLog.debug("Problem with property %s - will default to UTC" + this.mpi.toString(), e);
}
theZone = new TimeZone(0, TimeZones.UTC_ID);
}
theZone = new TimeZone(vtz);
return theZone;
}
use of net.fortuna.ical4j.model.PropertyList in project android by nextcloud.
the class SaveCalendar method convertFromDb.
private VEvent convertFromDb(Cursor cur, Calendar cal, DtStamp timestamp) {
Log_OC.d(TAG, "cursor: " + DatabaseUtils.dumpCurrentRowToString(cur));
if (hasStringValue(cur, Events.ORIGINAL_ID)) {
// FIXME: Support these edited instances
Log_OC.w(TAG, "Ignoring edited instance of a recurring event");
return null;
}
PropertyList l = new PropertyList();
l.add(timestamp);
copyProperty(l, Property.UID, cur, Events.UID_2445);
String summary = copyProperty(l, Property.SUMMARY, cur, Events.TITLE);
String description = copyProperty(l, Property.DESCRIPTION, cur, Events.DESCRIPTION);
String organizer = getString(cur, Events.ORGANIZER);
if (!TextUtils.isEmpty(organizer)) {
// incorrectly left it in the organizer column.
if (!organizer.startsWith("mailto:")) {
organizer = "mailto:" + organizer;
}
try {
l.add(new Organizer(organizer));
} catch (URISyntaxException ignored) {
if (!mFailedOrganisers.contains(organizer)) {
Log_OC.e(TAG, "Failed to create mailTo for organizer " + organizer);
mFailedOrganisers.add(organizer);
}
}
}
copyProperty(l, Property.LOCATION, cur, Events.EVENT_LOCATION);
copyEnumProperty(l, Property.STATUS, cur, Events.STATUS, STATUS_ENUM);
boolean allDay = TextUtils.equals(getString(cur, Events.ALL_DAY), "1");
boolean isTransparent;
DtEnd dtEnd = null;
if (allDay) {
// All day event
isTransparent = true;
Date start = getDateTime(cur, Events.DTSTART, null, null);
Date end = getDateTime(cur, Events.DTEND, null, null);
l.add(new DtStart(new Date(start)));
if (end != null) {
dtEnd = new DtEnd(new Date(end));
} else {
dtEnd = new DtEnd(utcDateFromMs(start.getTime() + DateUtils.DAY_IN_MILLIS));
}
l.add(dtEnd);
} else {
// Regular or zero-time event. Start date must be a date-time
Date startDate = getDateTime(cur, Events.DTSTART, Events.EVENT_TIMEZONE, cal);
l.add(new DtStart(startDate));
// Use duration if we have one, otherwise end date
if (hasStringValue(cur, Events.DURATION)) {
isTransparent = getString(cur, Events.DURATION).equals("PT0S");
if (!isTransparent) {
copyProperty(l, Property.DURATION, cur, Events.DURATION);
}
} else {
String endTz = Events.EVENT_END_TIMEZONE;
if (endTz == null) {
endTz = Events.EVENT_TIMEZONE;
}
Date end = getDateTime(cur, Events.DTEND, endTz, cal);
dtEnd = new DtEnd(end);
isTransparent = startDate.getTime() == end.getTime();
if (!isTransparent) {
l.add(dtEnd);
}
}
}
copyEnumProperty(l, Property.CLASS, cur, Events.ACCESS_LEVEL, CLASS_ENUM);
int availability = getInt(cur, Events.AVAILABILITY);
if (availability > Events.AVAILABILITY_TENTATIVE) {
// Unknown/Invalid
availability = -1;
}
if (isTransparent) {
// not free, then mark it opaque.
if (availability >= 0 && availability != Events.AVAILABILITY_FREE) {
l.add(Transp.OPAQUE);
}
} else if (availability > Events.AVAILABILITY_BUSY) {
// This event is ordinarily busy but differs, so output a FREEBUSY
// period covering the time of the event
FreeBusy fb = new FreeBusy();
fb.getParameters().add(new FbType(AVAIL_ENUM.get(availability)));
DateTime start = new DateTime(((DtStart) l.getProperty(Property.DTSTART)).getDate());
if (dtEnd != null) {
fb.getPeriods().add(new Period(start, new DateTime(dtEnd.getDate())));
} else {
Duration d = (Duration) l.getProperty(Property.DURATION);
fb.getPeriods().add(new Period(start, d.getDuration()));
}
l.add(fb);
}
copyProperty(l, Property.RRULE, cur, Events.RRULE);
copyProperty(l, Property.RDATE, cur, Events.RDATE);
copyProperty(l, Property.EXRULE, cur, Events.EXRULE);
copyProperty(l, Property.EXDATE, cur, Events.EXDATE);
if (TextUtils.isEmpty(getString(cur, Events.CUSTOM_APP_PACKAGE))) {
// Only copy URL if there is no app i.e. we probably imported it.
copyProperty(l, Property.URL, cur, Events.CUSTOM_APP_URI);
}
VEvent e = new VEvent(l);
if (getInt(cur, Events.HAS_ALARM) == 1) {
// Add alarms
String s = summary == null ? (description == null ? "" : description) : summary;
Description desc = new Description(s);
ContentResolver resolver = activity.getContentResolver();
long eventId = getLong(cur, Events._ID);
Cursor alarmCur;
alarmCur = Reminders.query(resolver, eventId, mAllCols ? null : REMINDER_COLS);
while (alarmCur.moveToNext()) {
int mins = getInt(alarmCur, Reminders.MINUTES);
if (mins == -1) {
// FIXME: Get the real default
mins = 60;
}
// FIXME: We should support other types if possible
int method = getInt(alarmCur, Reminders.METHOD);
if (method == Reminders.METHOD_DEFAULT || method == Reminders.METHOD_ALERT) {
VAlarm alarm = new VAlarm(new Dur(0, 0, -mins, 0));
alarm.getProperties().add(Action.DISPLAY);
alarm.getProperties().add(desc);
e.getAlarms().add(alarm);
}
}
alarmCur.close();
}
return e;
}
Aggregations