How to create a calendar view using data from an ics file?

I am creating a PC program based on iCalendar format. I need to be able to get data from the current ics file and display it as a calendar or at least something similar to a calendar. I know how to get data from an ics file, I just don't know how easy it is to use this data for display purposes.

Here is my starting code:

public void getCalendarData(File f) throws FileNotFoundException, IOException, ParserException
{
    FileInputStream fin = new FileInputStream(f);
    builder = new CalendarBuilder();
    calendar = builder.build(fin);
}
+3
source share
2 answers

One thing is ical4j, which is basically a utility that wraps the ICS format.

Another thing is the calendar / schedule interface :-)

But we are lucky there is a nice JSF component with Primefaces that you can use if the web interface is right for you.

http://www.primefaces.org/showcase/ui/data/schedule.xhtml

, ICS primfaces ( JSF, bean )

, -

private static final SimpleDateFormat SDF = new SimpleDateFormat("yyyyMMdd");

@PostConstruct
private void loadIcs() {
    eventModel = new DefaultScheduleModel();
    CalendarBuilder builder = new CalendarBuilder();

    try {
        net.fortuna.ical4j.model.Calendar calendar = builder.build(this.getClass().getResourceAsStream("canada.ics"));

        for (Iterator i = calendar.getComponents().iterator(); i.hasNext();) {
            Component component = (Component) i.next();
            //new event
            Date start = SDF.parse(component.getProperty("DTSTART").getValue());
            Date end = SDF.parse(component.getProperty("DTEND").getValue());
            String summary = component.getProperty("SUMMARY").getValue();

            eventModel.addEvent(new DefaultScheduleEvent(summary,
            start, end));

            System.out.println("added "+start+end+summary);

        }
    } catch (IOException e) {
        e.printStackTrace();
    } catch (ParserException e) {
        e.printStackTrace();
    } catch (ParseException e) {
        e.printStackTrace();
    }

}
+4

, GUI icalendar, RRULE. (HTML,...) , :

// Reading the file and creating the calendar
CalendarBuilder builder = new CalendarBuilder();
Calendar cal = null;
try {
    cal = builder.build(new FileInputStream("my.ics"));
} catch (IOException e) {
    e.printStackTrace();
} catch (ParserException e) {
    e.printStackTrace();
}


// Create the date range which is desired.
DateTime from = new DateTime("20100101T070000Z");
DateTime to = new DateTime("20100201T070000Z");;
Period period = new Period(from, to);


// For each VEVENT in the ICS
for (Object o : cal.getComponents("VEVENT")) {
    Component c = (Component)o;
    PeriodList list = c.calculateRecurrenceSet(period);

    for (Object po : list) {
        System.out.println((Period)po);
    }
}
0

All Articles