private void appendRecurrenceInformation(StringBuffer eventBuffer) {
int noEnd = 1;//so 'true' is <NoEndDate>1</NoEndDate>
int r = 0;//value for the <IsRecurring> SIF-E element
RepeatRule rule = event.getRepeat();
if (rule == null) {
/*
* if there isn't any RepeatRule object
* no recurrence is set:
* <IsRecurring>0</IsRecurring>
*/
r = 0;
eventBuffer.append("<" + IS_RECURRING + ">" +
r +
"</" + IS_RECURRING + ">");
} else {
/*
* if a RepeatRule object exists,
* then we have to build the appropriate
* SIF-E element (<IsRecurring>1</IsRecurring>)
* and to extract all available recurrence
* information from that object
*/
r = 1;//appointment is recurring
eventBuffer.append("<" + IS_RECURRING + ">" +
r +
"</" + IS_RECURRING + ">");
int[] fieldsArray = rule.getFields();
//DEBUG
StaticDataHelper.log("[DEBUG]Fields in RepeatRule object:");
for (int i = 0; i < fieldsArray.length; i++) {
StaticDataHelper.log(i + " -> " + fieldsArray[i]);
}
for (int i = 0; i < fieldsArray.length; i++) {
StaticDataHelper.log("[DEBUG]" + i + " --> " + fieldsArray[i]);
switch (fieldsArray[i]) {
//<RecurrenceType>
case RepeatRule.FREQUENCY://0
StaticDataHelper.log("[DEBUG]Found FREQUENCY (" + fieldsArray[i] + ")");
int type = 0;
//OlRecurrenceType
switch (rule.getInt(RepeatRule.FREQUENCY)) {
case RepeatRule.DAILY:
type = 0;//olRecursDaily
break;
case RepeatRule.WEEKLY:
type = 1;//olRecursWeekly
break;
case RepeatRule.MONTHLY:
try {
rule.getInt(RepeatRule.WEEK_IN_MONTH);
} catch (FieldEmptyException f) {
type = 2;//olRecursMonthly
break;
}
type = 3;//olRecursMonthlyNth
break;
case RepeatRule.YEARLY:
try {
rule.getInt(RepeatRule.WEEK_IN_MONTH);
} catch (FieldEmptyException f) {
type = 5;//olRecursYearly
break;
}
type = 6;//olRecursYearlyNth
break;
}
eventBuffer.append("<" + RECURRENCE_TYPE + ">" +
type +
"</" + RECURRENCE_TYPE + ">");
break;
//<Interval>
case RepeatRule.INTERVAL://128
StaticDataHelper.log("[DEBUG]Found INTERVAL (" + fieldsArray[i] + ")");
int interval = rule.getInt(RepeatRule.INTERVAL);
eventBuffer.append("<" + INTERVAL + ">" +
interval +
"</" + INTERVAL + ">");
break;
//<PatternEndDate>
case RepeatRule.END://64
StaticDataHelper.log("[DEBUG]Found END (" + fieldsArray[i] + ")");
long endDate = rule.getDate(RepeatRule.END);
SimpleDateFormat formatter = new SimpleDateFormat(DATETIME_FORMAT_UTC);
String formattedDate = formatter.formatLocal(endDate);
//e.g. <PatternEndDate>20080504T150000Z</PatternEndDate>
eventBuffer.append("<" + PATTERN_END_DATE + ">" +
formattedDate +
"</" + PATTERN_END_DATE + ">");
//<NoEndDate>0</NoEndDate>
noEnd = 0;
break;
/*
* Something like <PatternStartDate>
* isn't supported by the RIM's API
*/
//<DayOfWeekMask>
case RepeatRule.DAY_IN_WEEK://2
StaticDataHelper.log("[DEBUG]Found DAY_IN_WEEK (" + fieldsArray[i] + ")");
//OlDaysOfWeek
int valueFromDevice = rule.getInt(RepeatRule.DAY_IN_WEEK);
int mask = 0;
//olSunday 1
if ((valueFromDevice & RepeatRule.SUNDAY) == RepeatRule.SUNDAY) {
mask = mask + 1;
}
//olMonday 2
if ((valueFromDevice & RepeatRule.MONDAY) == RepeatRule.MONDAY) {
mask = mask + 2;
}
//olTuesday 4
if ((valueFromDevice & RepeatRule.TUESDAY) == RepeatRule.TUESDAY) {
mask = mask + 4;
}
//olWednesday 8
if ((valueFromDevice & RepeatRule.WEDNESDAY) == RepeatRule.WEDNESDAY) {
mask = mask + 8;
}
//olThursday 16
if ((valueFromDevice & RepeatRule.THURSDAY) == RepeatRule.THURSDAY) {
mask = mask + 16;
}
//olFriday 32
if ((valueFromDevice & RepeatRule.FRIDAY) == RepeatRule.FRIDAY) {
mask = mask + 32;
}
//olSaturday 64
if ((valueFromDevice & RepeatRule.SATURDAY) == RepeatRule.SATURDAY) {
mask = mask + 64;
}
/*
* the Outlook plug-in doesn't accept
* an appointment in SIF-E format where
* the <DayOfWeekMask> element is given
* for events different from 'daily',
* 'weekly' or 'yearly'
*/
if (rule.getInt(RepeatRule.FREQUENCY) == RepeatRule.DAILY ||
rule.getInt(RepeatRule.FREQUENCY) == RepeatRule.WEEKLY ||
rule.getInt(RepeatRule.FREQUENCY) == RepeatRule.YEARLY) {
eventBuffer.append("<" + DAY_OF_WEEK_MASK + ">" +
mask +
"</" + DAY_OF_WEEK_MASK + ">");
} else {
/*
* in case of a monthly event,
* Outlook seems to require that
* the element is present but with
* value set to '0'
*/
eventBuffer.append("<" + DAY_OF_WEEK_MASK + ">" +
0 +
"</" + DAY_OF_WEEK_MASK + ">");
}
break;
//<Occurrences>
case RepeatRule.COUNT://32
StaticDataHelper.log("[DEBUG]Found COUNT (" + fieldsArray[i] + ")");
int count = rule.getInt(RepeatRule.COUNT);
eventBuffer.append("<" + OCCURRENCES + ">" +
count +
"</" + OCCURRENCES + ">");
break;
//<DayOfMonth>
case RepeatRule.DAY_IN_MONTH://1
StaticDataHelper.log("[DEBUG]Found DAY_IN_MONTH (" + fieldsArray[i] + ")");
//1-31
int dayInMonth = rule.getInt(RepeatRule.DAY_IN_MONTH);
eventBuffer.append("<" + DAY_OF_MONTH + ">" +
dayInMonth +
"</" + DAY_OF_MONTH + ">");
break;
//<Instance> (limited to 1-5 due to SIF-E limitations)
case RepeatRule.WEEK_IN_MONTH:
StaticDataHelper.log("[DEBUG]Found WEEK_IN_MONTH (" + fieldsArray[i] + ")");
int week = 0;
switch (rule.getInt(RepeatRule.WEEK_IN_MONTH)) {
case RepeatRule.FIRST://1
week = 1;
break;
case RepeatRule.SECOND://2
week = 2;
break;
case RepeatRule.THIRD://4
week = 3;
break;
case RepeatRule.FOURTH://8
week = 4;
break;
/*
* in Outlook 2003: 'last'
* in the BlackBerry: 'last'
*/
case RepeatRule.FIFTH://16
week = 5;
break;
/*
* these values of the Sun Java API
* are not supported by the BlackBerry
* and the Outlook plug-ins
*
case RepeatRule.LAST://32
week = 32;
break;
case RepeatRule.SECONDLAST://64
week = 64;
break;
case RepeatRule.THIRDLAST://128
week = 128;
break;
case RepeatRule.FOURTHLAST://256
week = 256;
break;
case RepeatRule.FIFTHLAST://512
week = 512;
break;
*/
}
eventBuffer.append("<" + INSTANCE + ">" +
week +
"</" + INSTANCE + ">");
break;
//<MonthOfYear> 1-12
case RepeatRule.MONTH_IN_YEAR:
StaticDataHelper.log("[DEBUG]Found MONTH_IN_YEAR (" + fieldsArray[i] + ")");
int month = 0;
int monthOfYear = rule.getInt(RepeatRule.MONTH_IN_YEAR);
switch (monthOfYear) {
case RepeatRule.JANUARY:
month = 1;
break;