iCal4j的一些使用技巧

一些基本的操作在一下这个链接中都有
http://www.ibm.com/developerworks/cn/java/j-lo-ical4j/

做点补充
1.在Google gmail中如果想让邮件接收者直接添加日历到的日程当中需要如下设置:

ParameterList pls = new ParameterList();
pls.add(new Cn(mailInfo.getToEmail()));
pls.add(new Rsvp(true));
Attendee attendee = new Attendee(pls,mailInfo.getToEmail());
attendee.setCalAddress(new URI("mailto:"+mailInfo.getToEmail()));
vevent.getProperties().add(attendee);//参会者

2. 循环提醒,如果需要实现按周或者按每个月的第几天 或者每个月的第几周的第几天则需要构建 recur 具体代码如下:

public static Recur getRecurByCycle(ConfCycle cycle){
if(cycle!=null){
Recur recur = new Recur();
//周期信息
String cycleInfo = cycle.getCycleValue();
String infos[] = cycleInfo.split(";");

int index = 0 ;
List indexs = new ArrayList();
int seq = 0;
if(infos.length == 1){
String indexstr[] = infos[0].split(",");
for (int i = 0; i < indexstr.length; i++) {
indexs.add(Integer.parseInt(indexstr[i]));
}
index = indexs.get(0);

}else if(infos.length == 2){
seq = Integer.parseInt(infos[0]);
index = Integer.parseInt(infos[1]);
}

//周期的类型
int cycleType = cycle.getCycleType().intValue();
switch (cycleType) {
//按间隔多少天循环
case 1:
recur.setFrequency(Recur.DAILY);
recur.setInterval(index);
break;
//按每一周的周几 可以是每一周的一天或者多天
case 2:
recur.setFrequency(Recur.WEEKLY);
for (Integer weekday:indexs) {
switch (weekday) {
case 1:
recur.getDayList().add(WeekDay.SU);
break;
case 2:
recur.getDayList().add(WeekDay.MO);
break;
case 3:
recur.getDayList().add(WeekDay.TU);
break;
case 4:
recur.getDayList().add(WeekDay.WE);
break;
case 5:
recur.getDayList().add(WeekDay.TH);
break;
case 6:
recur.getDayList().add(WeekDay.FR);
break;
case 7:
recur.getDayList().add(WeekDay.SA);
break;
default:
throw new RuntimeException("un support week index!!!");
}
}
break;
//按月循环 可以按每个月的第几天
case 3:
recur.setFrequency(Recur.MONTHLY);
//按每月的第几周的周几
if(seq != 0){
switch (index) {
case 1:
recur.getDayList().add(WeekDay.SU);
break;
case 2:
recur.getDayList().add(WeekDay.MO);
break;
case 3:
recur.getDayList().add(WeekDay.TU);
break;
case 4:
recur.getDayList().add(WeekDay.WE);
break;
case 5:
recur.getDayList().add(WeekDay.TH);
break;
case 6:
recur.getDayList().add(WeekDay.FR);
break;
case 7:
recur.getDayList().add(WeekDay.SA);
break;
default:
throw new RuntimeException("un support week index!!!");
}
recur.getSetPosList().add(seq);

//按每月的第几天
}else{
recur.getMonthDayList().add(index);
}
break;
default:
throw new RuntimeException("un know cycle type! ");

}
boolean unlimited = cycle.getInfiniteFlag().intValue() == 0 ?false:true;
//设置结束周期
if (!unlimited) {
int count = cycle.getRepeatCount();
if(count>0){
recur.setCount(count);
}else{
recur.setUntil(new net.fortuna.ical4j.model.Date(cycle.getEndDate()));
}
}
return recur;
}
return null;
}

你可能感兴趣的:(开源项目使用)