Java生成ics文件

java生成ICS文件,这玩意好象是个什么日程表类的东西。可以导入到outlook里面用。

public void exportActivityDates(HttpServletRequest request, HttpServletResponse response)
throws Exception {
MenuBean menuBean = (MenuBean) request.getSession().getAttribute(SystemConstants.JE_MENU_BEAN);
Vector atyBeans = (Vector) menuBean.getLearningActivities();

StringBuffer strActivityDates = new StringBuffer();
strActivityDates.append("BEGIN:VCALENDAR\n");
strActivityDates.append("PRODID:-//Microsoft Corporation//Outlook 11.0 MIMEDIR//EN\n");
strActivityDates.append("VERSION:2.0\n");
strActivityDates.append("METHOD:PUBLISH\n");
ActivityBean atyBean = null;
for (int i = 0; i < atyBeans.size(); i++) {
atyBean = atyBeans.get(i);
if (atyBean.isIsShow()) {
strActivityDates.append("BEGIN:VEVENT\n");
String strDateTime = atyBean.getStartDateTime().replaceAll("-", "");
strActivityDates.append("DTSTART:").append(strDateTime).append("\n");
String endDateTime = atyBean.getEndDateTime().replaceAll("-", "");
strActivityDates.append("DTEND:").append(endDateTime).append("\n");
strActivityDates.append("LOCATION:").append(atyBean.getAtyName()).append("\n");
strActivityDates.append("TRANSP:OPAQUE\n");
strActivityDates.append("SEQUENCE:1\n");
strActivityDates.append("UID:8BB34ECC-1363-497B-B7CB-A268FD46CC7D\n");
String strNow = ISO8601Date.dateToString(new Date()).replaceAll("-", "");
strActivityDates.append("DTSTAMP:").append(strNow).append("\n");
strActivityDates.append("DESCRIPTION:").append(atyBean.getAtyName()).append("\n");
strActivityDates.append("SUMMARY:").append(atyBean.getAtyName()).append("\n");
strActivityDates.append("END:VEVENT\n");
}
}
strActivityDates.append("END:VCALENDAR");
OutputStream outputstream = response.getOutputStream();

response.reset();
response.setHeader("content-disposition", "attachment;filename=activityDates.ics");
response.setContentType("text/calendar");

byte[] bytes = strActivityDates.toString().getBytes("UTF-8");
for (int i = 0; i < bytes.length; i++)
outputstream.write(bytes[i]);
outputstream.close();
response.flushBuffer();
response.getWriter();
}

你可能感兴趣的:(Java编程)