19 package org.turro.ical;
21 import java.io.IOException;
22 import java.io.OutputStream;
23 import java.net.SocketException;
25 import java.util.Date;
26 import java.util.logging.Level;
27 import java.util.logging.Logger;
28 import net.fortuna.ical4j.data.CalendarOutputter;
29 import net.fortuna.ical4j.model.DateTime;
30 import net.fortuna.ical4j.model.component.VEvent;
31 import net.fortuna.ical4j.model.parameter.Cn;
32 import net.fortuna.ical4j.model.parameter.Role;
33 import net.fortuna.ical4j.model.property.Attendee;
34 import net.fortuna.ical4j.model.property.CalScale;
35 import net.fortuna.ical4j.model.property.Completed;
36 import net.fortuna.ical4j.model.property.Description;
37 import net.fortuna.ical4j.model.property.Location;
38 import net.fortuna.ical4j.model.property.Organizer;
39 import net.fortuna.ical4j.model.property.ProdId;
40 import net.fortuna.ical4j.model.property.Status;
41 import net.fortuna.ical4j.model.property.Uid;
42 import net.fortuna.ical4j.model.property.Version;
43 import net.fortuna.ical4j.util.FixedUidGenerator;
44 import net.fortuna.ical4j.util.UidGenerator;
45 import org.turro.string.Strings;
46 import org.turro.action.Contacts;
47 import org.turro.elephant.context.ElephantContext;
55 private net.fortuna.ical4j.model.
Calendar icsCalendar;
56 private VEvent currentEvent;
60 icsCalendar =
new net.fortuna.ical4j.model.
Calendar();
61 icsCalendar.getProperties().add(
new ProdId(name));
62 icsCalendar.getProperties().add(Version.VERSION_2_0);
63 icsCalendar.getProperties().add(CalScale.GREGORIAN);
66 public void addEvent(Date start, Date end, String name, String description) {
68 currentEvent =
new VEvent(
new DateTime(start),
new DateTime(end ==
null ? start : end), name);
69 currentEvent.getProperties().add(
new Description(description));
73 UidGenerator ug =
new FixedUidGenerator(
"uidGen");
74 Uid uid = ug.generateUid();
75 currentEvent.getProperties().add(uid);
77 icsCalendar.getComponents().add(currentEvent);
78 }
catch (SocketException ex) {
86 umail = URI.create(
"mailto:" + email);
87 }
catch(Exception ex) {
90 Organizer organizer =
new Organizer(umail);
91 organizer.getParameters().add(
new Cn(name));
92 currentEvent.getProperties().add(organizer);
96 currentEvent.getProperties().add(
new Completed(
new DateTime(endDate)));
100 currentEvent.getProperties().add(
new Status(
"CANCELLED"));
106 umail = URI.create(
"mailto:" + email);
107 }
catch(Exception ex) {
110 Attendee attendee =
new Attendee(umail);
111 attendee.getParameters().add(Role.REQ_PARTICIPANT);
112 attendee.getParameters().add(
new Cn(name));
113 currentEvent.getProperties().add(attendee);
117 if(!Strings.isBlank(address)) {
118 Location location =
new Location(address);
119 currentEvent.getProperties().add(location);
125 CalendarOutputter outputter =
new CalendarOutputter();
126 outputter.output(icsCalendar, out);
127 }
catch (IOException ex) {
static String logMsg(String msg)
void addEvent(Date start, Date end, String name, String description)
void addLocation(String address)
void output(OutputStream out)
void addAttendee(String name, String email)
void setOrganizer(String name, String email)