use of net.fortuna.ical4j.model.Dur in project LAMSADE-tools by LAntoine.
the class Conference method generateCalendarFile.
/**
* Generates a vcal file with the conference details with this object's data
*
* @param filename:
* the path including the name of the file to be generated
* @throws IOException
* @throws ValidationException
* @throws ParserException
*
* @author Javier MartÃnez
*/
public void generateCalendarFile(String filename) throws IOException, ValidationException, ParserException {
String calFile = filename;
// start time
java.util.Calendar startCal = java.util.Calendar.getInstance();
startCal.setTime(java.sql.Date.valueOf(getStart_date()));
// end time
java.util.Calendar endCal = java.util.Calendar.getInstance();
endCal.setTime(java.sql.Date.valueOf(getEnd_date()));
String subject = "Conference";
String description = "A conference with a fee of " + getEntry_fee();
String hostEmail = "";
// Creating a new calendar
net.fortuna.ical4j.model.Calendar calendar = new net.fortuna.ical4j.model.Calendar();
calendar.getProperties().add(new ProdId("-//Ben Fortuna//iCal4j 1.0//EN"));
calendar.getProperties().add(Version.VERSION_2_0);
calendar.getProperties().add(CalScale.GREGORIAN);
SimpleDateFormat sdFormat = new SimpleDateFormat("yyyyMMdd'T'hhmmss'Z'");
String strDate = sdFormat.format(startCal.getTime());
net.fortuna.ical4j.model.Date startDt = null;
try {
startDt = new net.fortuna.ical4j.model.Date(strDate);
} catch (ParseException e) {
e.printStackTrace();
}
long diff = endCal.getTimeInMillis() - startCal.getTimeInMillis();
int min = (int) (diff / (1000 * 60));
Dur dur = new Dur(0, 0, min, 0);
// Creating a meeting event
VEvent meeting = new VEvent(startDt, dur, subject);
// This is where you would add a location if there was one
// meeting.getProperties().add(new Location(location));
meeting.getProperties().add(new Description());
try {
meeting.getProperties().getProperty(Property.DESCRIPTION).setValue(description);
} catch (IOException e) {
e.printStackTrace();
} catch (URISyntaxException e) {
e.printStackTrace();
} catch (ParseException e) {
e.printStackTrace();
}
calendar.getComponents().add(meeting);
FileOutputStream fout = null;
try {
fout = new FileOutputStream(calFile);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
CalendarOutputter outputter = new CalendarOutputter();
outputter.setValidating(false);
try {
outputter.output(calendar, fout);
} catch (IOException e) {
e.printStackTrace();
} catch (ValidationException e) {
e.printStackTrace();
}
System.out.println(meeting);
}
Aggregations