try {
// don't worry about NullPointerExceptions.
// we'll catch exceptions if any operation fails.
MultipartParser mpp = new MultipartParser(ureq.getHttpReq(), (int) fileUploadLimit * 1024);
mpp.setEncoding("UTF-8");
Part part;
boolean fileWritten = false;
while ((part = mpp.readNextPart()) != null) {
if (part.isFile() && !fileWritten) {
FilePart fPart = (FilePart) part;
String type = fPart.getContentType();
// get file contents
Tracing.logWarn(type + fPart.getFileName(), this.getClass());
if (fPart != null && fPart.getFileName() != null && type.startsWith("text") && (type.toLowerCase().endsWith("calendar"))) {
// store the uploaded file by a temporary name
CalendarManager calManager = CalendarManagerFactory.getInstance().getCalendarManager();
String calID = ImportCalendarManager.getTempCalendarIDForUpload(ureq);
File tmpFile = calManager.getCalendarFile(CalendarManager.TYPE_USER, calID);
fPart.writeTo(tmpFile);
// try to parse the tmp file
Object calendar = calManager.readCalendar(CalendarManager.TYPE_USER, calID);
if (calendar != null) {
fileWritten = true;
}
//the uploaded calendar file is ok.
fireEvent(ureq, Event.DONE_EVENT);
}
} else if (part.isParam()) {
ParamPart pPart = (ParamPart) part;
if (pPart.getName().equals("cancel")) {
// action cancelled
fireEvent(ureq, Event.CANCELLED_EVENT);
}