Search in sources :

Example 1 with Dur

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);
}
Also used : Dur(net.fortuna.ical4j.model.Dur) VEvent(net.fortuna.ical4j.model.component.VEvent) Description(net.fortuna.ical4j.model.property.Description) ValidationException(net.fortuna.ical4j.model.ValidationException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) ProdId(net.fortuna.ical4j.model.property.ProdId) FileOutputStream(java.io.FileOutputStream) ParseException(java.text.ParseException) CalendarOutputter(net.fortuna.ical4j.data.CalendarOutputter) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

FileNotFoundException (java.io.FileNotFoundException)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1 ParseException (java.text.ParseException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 CalendarOutputter (net.fortuna.ical4j.data.CalendarOutputter)1 Dur (net.fortuna.ical4j.model.Dur)1 ValidationException (net.fortuna.ical4j.model.ValidationException)1 VEvent (net.fortuna.ical4j.model.component.VEvent)1 Description (net.fortuna.ical4j.model.property.Description)1 ProdId (net.fortuna.ical4j.model.property.ProdId)1