init();
}
private void init() {
// Methods
addItem( new ScriptField( METHOD_SAVE, createSaveMethod(), ScriptField.TYPE_SCRIPTABLE, true, true ) );
addItem( new ScriptField( METHOD_REMOVE, createRemoveMethod(), ScriptField.TYPE_SCRIPTABLE, true, true ) );
String location = "";
String summary = "";
String note = "";
String uid = "";
Date start = null;
Date end = null;
ReminderObject reminder = null;
boolean allDay = false;
AttendeeObject[] attendeeObjects = null;
int freeBusy = AppointmentConstructor.CONST_VAL_BUSY.intValue();
RepeatRule repeatRule = null;
if( _event != null ) {
if( _event.countValues( Event.LOCATION ) > 0 ) {
location = _event.getString( Event.LOCATION, Event.ATTR_NONE );
}
if( _event.countValues( Event.SUMMARY ) > 0 ) {
summary = _event.getString( Event.SUMMARY, Event.ATTR_NONE );
}
if( _event.countValues( Event.NOTE ) > 0 ) {
note = _event.getString( Event.NOTE, Event.ATTR_NONE );
}
if( _event.countValues( Event.UID ) > 0 ) {
uid = _event.getString( Event.UID, Event.ATTR_NONE );
}
if( _event.countValues( Event.START ) > 0 ) {
start = new Date( _event.getDate( Event.START, Event.ATTR_NONE ) );
}
if( _event.countValues( Event.END ) > 0 ) {
end = new Date( _event.getDate( Event.END, Event.ATTR_NONE ) );
}
if( _event.countValues( Event.ALARM ) > 0 ) {
int relativeTime = _event.getInt( Event.ALARM, Event.ATTR_NONE );
Double d = new Double( (double) relativeTime / 3600 );
reminder = new ReminderObject();
reminder.getItem( ReminderObject.FIELD_TYPE ).setValue( new Integer( ReminderConstructor.TYPE_RELATIVE ) );
reminder.getItem( ReminderObject.FIELD_RELATIVE_HOURS ).setValue( d );
}
if( _event.countValues( BlackBerryEvent.ALLDAY ) > 0 ) {
allDay = _event.getBoolean( BlackBerryEvent.ALLDAY, Event.ATTR_NONE );
}
int countAttendees = _event.countValues( BlackBerryEvent.ATTENDEES );
attendeeObjects = new AttendeeObject[ countAttendees ];
for( int i = 0; i < countAttendees; i++ ) {
AttendeeObject attendeeObject = new AttendeeObject();
String attendeeAddress = _event.getString( BlackBerryEvent.ATTENDEES, i );
attendeeObject.getItem( AttendeeObject.FIELD_ADDRESS ).setValue( attendeeAddress );
attendeeObjects[ i ] = attendeeObject;
}
if( _event.countValues( BlackBerryEvent.FREE_BUSY ) > 0 ) {
freeBusy = _event.getInt( BlackBerryEvent.FREE_BUSY, BlackBerryEvent.ATTR_NONE );
}
repeatRule = _event.getRepeat();
}
// Properties
addItem( new ScriptField( FIELD_LOCATION, location, ScriptField.TYPE_STRING, false, false ) );
addItem( new ScriptField( FIELD_NOTE, note, ScriptField.TYPE_STRING, false, false ) );
addItem( new ScriptField( FIELD_SUMMARY, summary, ScriptField.TYPE_STRING, false, false ) );
addItem( new ScriptField( FIELD_UID, uid, ScriptField.TYPE_STRING, true, false ) );
addItem( new ScriptField( FIELD_START, start, ScriptField.TYPE_DATE, false, false ) );
addItem( new ScriptField( FIELD_END, end, ScriptField.TYPE_DATE, false, false ) );
addItem( new ScriptField( FIELD_REMINDER, reminder, ScriptField.TYPE_SCRIPTABLE, false, false ) );
addItem( new ScriptField( FIELD_ALLDAY, new Boolean( allDay ), ScriptField.TYPE_BOOLEAN, false, false ) );
addItem( new ScriptField( FIELD_FREEBUSY, new Integer( freeBusy ), ScriptField.TYPE_INT, false, false ) );
addItem( new ScriptField( FIELD_ATTENDEES, attendeeObjects, ScriptField.TYPE_SCRIPTABLE, false, false ) );
if( repeatRule != null ) {
RecurrenceObject recurObject = new RecurrenceObject();
int count = PIMUtils.getRepeatRuleInt( repeatRule, RepeatRule.COUNT );
recurObject.getItem( RecurrenceObject.FIELD_COUNT ).setValue( new Integer( count ) );
int freq = PIMUtils.getRepeatRuleInt( repeatRule, RepeatRule.FREQUENCY );
recurObject.getItem( RecurrenceObject.FIELD_FREQUENCY ).setValue(
new Integer( RecurrenceObject.repeatRuleToFrequency( freq ) ) );
int interval = PIMUtils.getRepeatRuleInt( repeatRule, RepeatRule.INTERVAL );
recurObject.getItem( RecurrenceObject.FIELD_INTERVAL ).setValue( new Integer( interval ) );
long endTime = PIMUtils.getRepeatRuleDate( repeatRule, RepeatRule.END );
recurObject.getItem( RecurrenceObject.FIELD_END ).setValue( new Date( endTime ) );
int monthInYear = PIMUtils.getRepeatRuleInt( repeatRule, RepeatRule.MONTH_IN_YEAR );
recurObject.getItem( RecurrenceObject.FIELD_MONTHINYEAR ).setValue( new Integer( monthInYear ) );
int weekInMonth = PIMUtils.getRepeatRuleInt( repeatRule, RepeatRule.WEEK_IN_MONTH );
recurObject.getItem( RecurrenceObject.FIELD_WEEKINMONTH ).setValue( new Integer( weekInMonth ) );
int dayInWeek = PIMUtils.getRepeatRuleInt( repeatRule, RepeatRule.DAY_IN_WEEK );
recurObject.getItem( RecurrenceObject.FIELD_DAYINWEEK ).setValue( new Integer( dayInWeek ) );
int dayInMonth = PIMUtils.getRepeatRuleInt( repeatRule, RepeatRule.DAY_IN_MONTH );
recurObject.getItem( RecurrenceObject.FIELD_DAYINMONTH ).setValue( new Integer( dayInMonth ) );
int dayInYear = PIMUtils.getRepeatRuleInt( repeatRule, RepeatRule.DAY_IN_YEAR );
recurObject.getItem( RecurrenceObject.FIELD_DAYINYEAR ).setValue( new Integer( dayInYear ) );
addItem( new ScriptField( FIELD_RECURRENCE, recurObject, ScriptField.TYPE_SCRIPTABLE, false, false ) );
} else {
addItem( new ScriptField( FIELD_RECURRENCE, null, ScriptField.TYPE_SCRIPTABLE, false, false ) );
}
}