use of net.fortuna.ical4j.model.property.Description in project openolat by klemens.
the class ICalFileCalendarManager method getVEvent.
private VEvent getVEvent(KalendarEvent kEvent) {
VEvent vEvent = new VEvent();
if (!kEvent.isAllDayEvent()) {
// regular VEvent
DateTime dtBegin = new DateTime(kEvent.getBegin());
if (tz != null) {
dtBegin.setTimeZone(tz);
}
Date kEventEnd = kEvent.getEnd();
if (kEventEnd == null) {
vEvent = new VEvent(dtBegin, kEvent.getSubject());
} else {
DateTime dtEnd = new DateTime(kEventEnd);
if (tz != null) {
dtEnd.setTimeZone(tz);
}
vEvent = new VEvent(dtBegin, dtEnd, kEvent.getSubject());
}
} else {
// AllDay VEvent
net.fortuna.ical4j.model.Date dtBegin = CalendarUtils.createDate(kEvent.getBegin());
// adjust end date: ICal end dates for all day events are on the next day
Date adjustedEndDate = new Date(kEvent.getEnd().getTime() + (1000 * 60 * 60 * 24));
net.fortuna.ical4j.model.Date dtEnd = CalendarUtils.createDate(adjustedEndDate);
vEvent = new VEvent(dtBegin, dtEnd, kEvent.getSubject());
}
if (kEvent.getCreated() > 0) {
Created created = new Created(new DateTime(kEvent.getCreated()));
vEvent.getProperties().add(created);
}
if ((kEvent.getCreatedBy() != null) && !kEvent.getCreatedBy().trim().isEmpty()) {
Contact contact = new Contact();
contact.setValue(kEvent.getCreatedBy());
vEvent.getProperties().add(contact);
}
if (kEvent.getLastModified() > 0) {
LastModified lastMod = new LastModified(new DateTime(kEvent.getLastModified()));
vEvent.getProperties().add(lastMod);
}
// Uid
PropertyList vEventProperties = vEvent.getProperties();
vEventProperties.add(new Uid(kEvent.getID()));
// clazz
switch(kEvent.getClassification()) {
case KalendarEvent.CLASS_PRIVATE:
vEventProperties.add(ICAL_CLASS_PRIVATE);
break;
case KalendarEvent.CLASS_PUBLIC:
vEventProperties.add(ICAL_CLASS_PUBLIC);
break;
case KalendarEvent.CLASS_X_FREEBUSY:
vEventProperties.add(ICAL_CLASS_X_FREEBUSY);
break;
default:
vEventProperties.add(ICAL_CLASS_PRIVATE);
break;
}
// location
if (kEvent.getLocation() != null) {
vEventProperties.add(new Location(kEvent.getLocation()));
}
if (kEvent.getDescription() != null) {
vEventProperties.add(new Description(kEvent.getDescription()));
}
// event links
Url urlOnce = null;
List<KalendarEventLink> kalendarEventLinks = kEvent.getKalendarEventLinks();
if ((kalendarEventLinks != null) && !kalendarEventLinks.isEmpty()) {
for (Iterator<KalendarEventLink> iter = kalendarEventLinks.iterator(); iter.hasNext(); ) {
KalendarEventLink link = iter.next();
StringBuilder linkEncoded = new StringBuilder(200);
linkEncoded.append(link.getProvider());
linkEncoded.append("§");
linkEncoded.append(link.getId());
linkEncoded.append("§");
linkEncoded.append(link.getDisplayName());
linkEncoded.append("§");
linkEncoded.append(link.getURI());
linkEncoded.append("§");
linkEncoded.append(link.getIconCssClass());
XProperty linkProperty = new XProperty(ICAL_X_OLAT_LINK, linkEncoded.toString());
vEventProperties.add(linkProperty);
if (urlOnce == null) {
try {
Url url = new Url();
url.setValue(link.getURI());
urlOnce = url;
} catch (URISyntaxException e) {
log.error("Invalid URL:" + link.getURI());
}
}
}
}
if (urlOnce != null) {
vEventProperties.add(urlOnce);
}
if (kEvent.getComment() != null) {
vEventProperties.add(new XProperty(ICAL_X_OLAT_COMMENT, kEvent.getComment()));
}
if (kEvent.getNumParticipants() != null) {
vEventProperties.add(new XProperty(ICAL_X_OLAT_NUMPARTICIPANTS, Integer.toString(kEvent.getNumParticipants())));
}
if (kEvent.getParticipants() != null) {
StringBuilder strBuf = new StringBuilder();
String[] participants = kEvent.getParticipants();
for (String participant : participants) {
strBuf.append(participant);
strBuf.append("§");
}
vEventProperties.add(new XProperty(ICAL_X_OLAT_PARTICIPANTS, strBuf.toString()));
}
if (kEvent.getSourceNodeId() != null) {
vEventProperties.add(new XProperty(ICAL_X_OLAT_SOURCENODEID, kEvent.getSourceNodeId()));
}
if (kEvent.getManagedFlags() != null) {
String val = CalendarManagedFlag.toString(kEvent.getManagedFlags());
vEventProperties.add(new XProperty(ICAL_X_OLAT_MANAGED, val));
}
if (StringHelper.containsNonWhitespace(kEvent.getExternalId())) {
vEventProperties.add(new XProperty(ICAL_X_OLAT_EXTERNAL_ID, kEvent.getExternalId()));
}
if (StringHelper.containsNonWhitespace(kEvent.getExternalSource())) {
vEventProperties.add(new XProperty(ICAL_X_OLAT_EXTERNAL_SOURCE, kEvent.getExternalSource()));
}
String recurenceId = kEvent.getRecurrenceID();
if (StringHelper.containsNonWhitespace(recurenceId)) {
try {
RecurrenceId recurId = new RecurrenceId(tz);
// VALUE=DATE recurrence id need to be specially saved
if (recurenceId.length() < 9) {
recurId = new RecurrenceId(tz);
recurId.setDate(CalendarUtils.createDate(new net.fortuna.ical4j.model.Date(recurenceId)));
} else {
recurId = new RecurrenceId(recurenceId, tz);
}
vEventProperties.add(recurId);
} catch (ParseException e) {
log.error("cannot create recurrence ID: " + recurenceId, e);
}
}
// recurrence
String recurrence = kEvent.getRecurrenceRule();
if (recurrence != null && !recurrence.equals("")) {
try {
Recur recur = new Recur(recurrence);
RRule rrule = new RRule(recur);
vEventProperties.add(rrule);
} catch (ParseException e) {
log.error("cannot create recurrence rule: " + recurrence.toString(), e);
}
}
// recurrence exclusions
String recurrenceExc = kEvent.getRecurrenceExc();
if (recurrenceExc != null && !recurrenceExc.equals("")) {
ExDate exdate = new ExDate();
try {
exdate.setValue(recurrenceExc);
vEventProperties.add(exdate);
} catch (ParseException e) {
log.error("", e);
}
}
return vEvent;
}
use of net.fortuna.ical4j.model.property.Description in project OpenOLAT by OpenOLAT.
the class ICalFileCalendarManager method getVEvent.
private VEvent getVEvent(KalendarEvent kEvent) {
VEvent vEvent = new VEvent();
if (!kEvent.isAllDayEvent()) {
// regular VEvent
DateTime dtBegin = new DateTime(kEvent.getBegin());
if (tz != null) {
dtBegin.setTimeZone(tz);
}
Date kEventEnd = kEvent.getEnd();
if (kEventEnd == null) {
vEvent = new VEvent(dtBegin, kEvent.getSubject());
} else {
DateTime dtEnd = new DateTime(kEventEnd);
if (tz != null) {
dtEnd.setTimeZone(tz);
}
vEvent = new VEvent(dtBegin, dtEnd, kEvent.getSubject());
}
} else {
// AllDay VEvent
net.fortuna.ical4j.model.Date dtBegin = CalendarUtils.createDate(kEvent.getBegin());
// adjust end date: ICal end dates for all day events are on the next day
Date adjustedEndDate = new Date(kEvent.getEnd().getTime() + (1000 * 60 * 60 * 24));
net.fortuna.ical4j.model.Date dtEnd = CalendarUtils.createDate(adjustedEndDate);
vEvent = new VEvent(dtBegin, dtEnd, kEvent.getSubject());
}
if (kEvent.getCreated() > 0) {
Created created = new Created(new DateTime(kEvent.getCreated()));
vEvent.getProperties().add(created);
}
if ((kEvent.getCreatedBy() != null) && !kEvent.getCreatedBy().trim().isEmpty()) {
Contact contact = new Contact();
contact.setValue(kEvent.getCreatedBy());
vEvent.getProperties().add(contact);
}
if (kEvent.getLastModified() > 0) {
LastModified lastMod = new LastModified(new DateTime(kEvent.getLastModified()));
vEvent.getProperties().add(lastMod);
}
// Uid
PropertyList vEventProperties = vEvent.getProperties();
vEventProperties.add(new Uid(kEvent.getID()));
// clazz
switch(kEvent.getClassification()) {
case KalendarEvent.CLASS_PRIVATE:
vEventProperties.add(ICAL_CLASS_PRIVATE);
break;
case KalendarEvent.CLASS_PUBLIC:
vEventProperties.add(ICAL_CLASS_PUBLIC);
break;
case KalendarEvent.CLASS_X_FREEBUSY:
vEventProperties.add(ICAL_CLASS_X_FREEBUSY);
break;
default:
vEventProperties.add(ICAL_CLASS_PRIVATE);
break;
}
// location
if (kEvent.getLocation() != null) {
vEventProperties.add(new Location(kEvent.getLocation()));
}
if (kEvent.getDescription() != null) {
vEventProperties.add(new Description(kEvent.getDescription()));
}
// event links
Url urlOnce = null;
List<KalendarEventLink> kalendarEventLinks = kEvent.getKalendarEventLinks();
if ((kalendarEventLinks != null) && !kalendarEventLinks.isEmpty()) {
for (Iterator<KalendarEventLink> iter = kalendarEventLinks.iterator(); iter.hasNext(); ) {
KalendarEventLink link = iter.next();
StringBuilder linkEncoded = new StringBuilder(200);
linkEncoded.append(link.getProvider());
linkEncoded.append("§");
linkEncoded.append(link.getId());
linkEncoded.append("§");
linkEncoded.append(link.getDisplayName());
linkEncoded.append("§");
linkEncoded.append(link.getURI());
linkEncoded.append("§");
linkEncoded.append(link.getIconCssClass());
XProperty linkProperty = new XProperty(ICAL_X_OLAT_LINK, linkEncoded.toString());
vEventProperties.add(linkProperty);
if (urlOnce == null) {
try {
Url url = new Url();
url.setValue(link.getURI());
urlOnce = url;
} catch (URISyntaxException e) {
log.error("Invalid URL:" + link.getURI());
}
}
}
}
if (urlOnce != null) {
vEventProperties.add(urlOnce);
}
if (kEvent.getComment() != null) {
vEventProperties.add(new XProperty(ICAL_X_OLAT_COMMENT, kEvent.getComment()));
}
if (kEvent.getNumParticipants() != null) {
vEventProperties.add(new XProperty(ICAL_X_OLAT_NUMPARTICIPANTS, Integer.toString(kEvent.getNumParticipants())));
}
if (kEvent.getParticipants() != null) {
StringBuilder strBuf = new StringBuilder();
String[] participants = kEvent.getParticipants();
for (String participant : participants) {
strBuf.append(participant);
strBuf.append("§");
}
vEventProperties.add(new XProperty(ICAL_X_OLAT_PARTICIPANTS, strBuf.toString()));
}
if (kEvent.getSourceNodeId() != null) {
vEventProperties.add(new XProperty(ICAL_X_OLAT_SOURCENODEID, kEvent.getSourceNodeId()));
}
if (kEvent.getManagedFlags() != null) {
String val = CalendarManagedFlag.toString(kEvent.getManagedFlags());
vEventProperties.add(new XProperty(ICAL_X_OLAT_MANAGED, val));
}
if (StringHelper.containsNonWhitespace(kEvent.getExternalId())) {
vEventProperties.add(new XProperty(ICAL_X_OLAT_EXTERNAL_ID, kEvent.getExternalId()));
}
if (StringHelper.containsNonWhitespace(kEvent.getExternalSource())) {
vEventProperties.add(new XProperty(ICAL_X_OLAT_EXTERNAL_SOURCE, kEvent.getExternalSource()));
}
String recurenceId = kEvent.getRecurrenceID();
if (StringHelper.containsNonWhitespace(recurenceId)) {
try {
RecurrenceId recurId = new RecurrenceId(tz);
// VALUE=DATE recurrence id need to be specially saved
if (recurenceId.length() < 9) {
recurId = new RecurrenceId(tz);
recurId.setDate(CalendarUtils.createDate(new net.fortuna.ical4j.model.Date(recurenceId)));
} else {
recurId = new RecurrenceId(recurenceId, tz);
}
vEventProperties.add(recurId);
} catch (ParseException e) {
log.error("cannot create recurrence ID: " + recurenceId, e);
}
}
// recurrence
String recurrence = kEvent.getRecurrenceRule();
if (recurrence != null && !recurrence.equals("")) {
try {
Recur recur = new Recur(recurrence);
RRule rrule = new RRule(recur);
vEventProperties.add(rrule);
} catch (ParseException e) {
log.error("cannot create recurrence rule: " + recurrence.toString(), e);
}
}
// recurrence exclusions
String recurrenceExc = kEvent.getRecurrenceExc();
if (recurrenceExc != null && !recurrenceExc.equals("")) {
ExDate exdate = new ExDate();
try {
exdate.setValue(recurrenceExc);
vEventProperties.add(exdate);
} catch (ParseException e) {
log.error("", e);
}
}
return vEvent;
}
use of net.fortuna.ical4j.model.property.Description in project OpenOLAT by OpenOLAT.
the class ICalFileCalendarManager method getKalendarEvent.
/**
* Build a KalendarEvent out of a source VEvent.
* @param event
* @return
*/
private KalendarEvent getKalendarEvent(VEvent event) {
// subject
Summary eventsummary = event.getSummary();
String subject = "";
if (eventsummary != null)
subject = eventsummary.getValue();
// start
DtStart dtStart = event.getStartDate();
Date start = dtStart.getDate();
Duration dur = event.getDuration();
// end
Date end = null;
if (dur != null) {
end = dur.getDuration().getTime(start);
} else if (event.getEndDate() != null) {
end = event.getEndDate().getDate();
}
// check all day event first
boolean isAllDay = false;
Parameter dateParameter = event.getProperties().getProperty(Property.DTSTART).getParameters().getParameter(Value.DATE.getName());
if (dateParameter != null) {
isAllDay = true;
// Make sure the time of the dates are 00:00 localtime because DATE fields in iCal are GMT 00:00
// Note that start date and end date can have different offset because of daylight saving switch
java.util.TimeZone timezone = java.util.GregorianCalendar.getInstance().getTimeZone();
start = new Date(start.getTime() - timezone.getOffset(start.getTime()));
end = new Date(end.getTime() - timezone.getOffset(end.getTime()));
// adjust end date: ICal sets end dates to the next day
end = new Date(end.getTime() - (1000 * 60 * 60 * 24));
} else if (start != null && end != null && (end.getTime() - start.getTime()) == (24 * 60 * 60 * 1000)) {
// check that start has no hour, no minute and no second
java.util.Calendar cal = java.util.Calendar.getInstance();
cal.setTime(start);
isAllDay = cal.get(java.util.Calendar.HOUR_OF_DAY) == 0 && cal.get(java.util.Calendar.MINUTE) == 0 && cal.get(java.util.Calendar.SECOND) == 0 && cal.get(java.util.Calendar.MILLISECOND) == 0;
// adjust end date: ICal sets end dates to the next day
end = new Date(end.getTime() - (1000 * 60 * 60 * 24));
}
Uid eventuid = event.getUid();
String uid;
if (eventuid != null) {
uid = eventuid.getValue();
} else {
uid = CodeHelper.getGlobalForeverUniqueID();
}
RecurrenceId eventRecurenceId = event.getRecurrenceId();
String recurrenceId = null;
if (eventRecurenceId != null) {
recurrenceId = eventRecurenceId.getValue();
}
KalendarEvent calEvent = new KalendarEvent(uid, recurrenceId, subject, start, end);
calEvent.setAllDayEvent(isAllDay);
// classification
Clazz classification = event.getClassification();
if (classification != null) {
String sClass = classification.getValue();
int iClassification = KalendarEvent.CLASS_PRIVATE;
if (sClass.equals(ICAL_CLASS_PRIVATE.getValue()))
iClassification = KalendarEvent.CLASS_PRIVATE;
else if (sClass.equals(ICAL_CLASS_X_FREEBUSY.getValue()))
iClassification = KalendarEvent.CLASS_X_FREEBUSY;
else if (sClass.equals(ICAL_CLASS_PUBLIC.getValue()))
iClassification = KalendarEvent.CLASS_PUBLIC;
calEvent.setClassification(iClassification);
}
// created/last modified
Created created = event.getCreated();
if (created != null) {
calEvent.setCreated(created.getDate().getTime());
}
// created/last modified
Contact contact = (Contact) event.getProperty(Property.CONTACT);
if (contact != null) {
calEvent.setCreatedBy(contact.getValue());
}
LastModified lastModified = event.getLastModified();
if (lastModified != null) {
calEvent.setLastModified(lastModified.getDate().getTime());
}
Description description = event.getDescription();
if (description != null) {
calEvent.setDescription(description.getValue());
}
// location
Location location = event.getLocation();
if (location != null) {
calEvent.setLocation(location.getValue());
}
// links if any
PropertyList linkProperties = event.getProperties(ICAL_X_OLAT_LINK);
List<KalendarEventLink> kalendarEventLinks = new ArrayList<KalendarEventLink>();
for (Iterator<?> iter = linkProperties.iterator(); iter.hasNext(); ) {
XProperty linkProperty = (XProperty) iter.next();
if (linkProperty != null) {
String encodedLink = linkProperty.getValue();
StringTokenizer st = new StringTokenizer(encodedLink, "§", false);
if (st.countTokens() >= 4) {
String provider = st.nextToken();
String id = st.nextToken();
String displayName = st.nextToken();
String uri = st.nextToken();
String iconCss = "";
// migration: iconCss has been added later, check if available first
if (st.hasMoreElements()) {
iconCss = st.nextToken();
}
KalendarEventLink eventLink = new KalendarEventLink(provider, id, displayName, uri, iconCss);
kalendarEventLinks.add(eventLink);
}
}
}
calEvent.setKalendarEventLinks(kalendarEventLinks);
Property comment = event.getProperty(ICAL_X_OLAT_COMMENT);
if (comment != null)
calEvent.setComment(comment.getValue());
Property numParticipants = event.getProperty(ICAL_X_OLAT_NUMPARTICIPANTS);
if (numParticipants != null)
calEvent.setNumParticipants(Integer.parseInt(numParticipants.getValue()));
Property participants = event.getProperty(ICAL_X_OLAT_PARTICIPANTS);
if (participants != null) {
StringTokenizer strTok = new StringTokenizer(participants.getValue(), "§", false);
String[] parts = new String[strTok.countTokens()];
for (int i = 0; strTok.hasMoreTokens(); i++) {
parts[i] = strTok.nextToken();
}
calEvent.setParticipants(parts);
}
Property sourceNodId = event.getProperty(ICAL_X_OLAT_SOURCENODEID);
if (sourceNodId != null) {
calEvent.setSourceNodeId(sourceNodId.getValue());
}
// managed properties
Property managed = event.getProperty(ICAL_X_OLAT_MANAGED);
if (managed != null) {
String value = managed.getValue();
if ("true".equals(value)) {
value = "all";
}
CalendarManagedFlag[] values = CalendarManagedFlag.toEnum(value);
calEvent.setManagedFlags(values);
}
Property externalId = event.getProperty(ICAL_X_OLAT_EXTERNAL_ID);
if (externalId != null) {
calEvent.setExternalId(externalId.getValue());
}
Property externalSource = event.getProperty(ICAL_X_OLAT_EXTERNAL_SOURCE);
if (externalSource != null) {
calEvent.setExternalSource(externalSource.getValue());
}
// recurrence
if (event.getProperty(ICAL_RRULE) != null) {
calEvent.setRecurrenceRule(event.getProperty(ICAL_RRULE).getValue());
}
// recurrence exclusions
if (event.getProperty(ICAL_EXDATE) != null) {
calEvent.setRecurrenceExc(event.getProperty(ICAL_EXDATE).getValue());
}
return calEvent;
}
use of net.fortuna.ical4j.model.property.Description in project openhab1-addons by openhab.
the class Util method createCalendar.
public static Calendar createCalendar(CalDavEvent calDavEvent, DateTimeZone timeZone) {
TimeZoneRegistry registry = TimeZoneRegistryFactory.getInstance().createRegistry();
TimeZone timezone = registry.getTimeZone(timeZone.getID());
Calendar calendar = new Calendar();
calendar.getProperties().add(Version.VERSION_2_0);
calendar.getProperties().add(new ProdId("openHAB"));
VEvent vEvent = new VEvent();
vEvent.getProperties().add(new Summary(calDavEvent.getName()));
vEvent.getProperties().add(new Description(calDavEvent.getContent()));
final DtStart dtStart = new DtStart(new net.fortuna.ical4j.model.DateTime(calDavEvent.getStart().toDate()));
dtStart.setTimeZone(timezone);
vEvent.getProperties().add(dtStart);
final DtEnd dtEnd = new DtEnd(new net.fortuna.ical4j.model.DateTime(calDavEvent.getEnd().toDate()));
dtEnd.setTimeZone(timezone);
vEvent.getProperties().add(dtEnd);
vEvent.getProperties().add(new Uid(calDavEvent.getId()));
vEvent.getProperties().add(Clazz.PUBLIC);
vEvent.getProperties().add(new LastModified(new net.fortuna.ical4j.model.DateTime(calDavEvent.getLastChanged().toDate())));
calendar.getComponents().add(vEvent);
return calendar;
}
use of net.fortuna.ical4j.model.property.Description in project ofbiz-framework by apache.
the class ICalConverter method getAlarms.
protected static void getAlarms(GenericValue workEffort, ComponentList alarms) throws GenericEntityException {
Description description = null;
if (workEffort.get("description") != null) {
description = new Description(workEffort.getString("description"));
} else {
description = new Description(workEffort.getString("workEffortName"));
}
Summary summary = new Summary(UtilProperties.getMessage("WorkEffortUiLabels", "WorkEffortEventReminder", Locale.getDefault()));
Delegator delegator = workEffort.getDelegator();
String workEffortId = workEffort.getString("workEffortId");
List<GenericValue> reminderList = EntityQuery.use(delegator).from("WorkEffortEventReminder").where("workEffortId", workEffort.get("workEffortId")).queryList();
for (GenericValue reminder : reminderList) {
String reminderId = workEffortId + "-" + reminder.getString("sequenceId");
VAlarm alarm = null;
PropertyList alarmProps = null;
boolean newAlarm = true;
Iterator<VAlarm> i = UtilGenerics.cast(alarms.iterator());
while (i.hasNext()) {
alarm = i.next();
Property xProperty = alarm.getProperty(reminderXPropName);
if (xProperty != null && reminderId.equals(xProperty.getValue())) {
newAlarm = false;
alarmProps = alarm.getProperties();
// TODO: Write update code. For now, just re-create
alarmProps.clear();
break;
}
}
if (newAlarm) {
alarm = createAlarm(reminder);
alarms.add(alarm);
alarmProps = alarm.getProperties();
alarmProps.add(new XProperty(reminderXPropName, reminderId));
}
GenericValue contactMech = reminder.getRelatedOne("ContactMech", false);
if (contactMech != null && "EMAIL_ADDRESS".equals(contactMech.get("contactMechTypeId"))) {
try {
alarmProps.add(new Attendee(contactMech.getString("infoString")));
alarmProps.add(Action.EMAIL);
alarmProps.add(summary);
alarmProps.add(description);
} catch (URISyntaxException e) {
alarmProps.add(Action.DISPLAY);
alarmProps.add(new Description("Error encountered while creating iCalendar: " + e));
}
} else {
alarmProps.add(Action.DISPLAY);
alarmProps.add(description);
}
if (Debug.verboseOn()) {
try {
alarm.validate(true);
Debug.logVerbose("iCalendar alarm passes validation", module);
} catch (ValidationException e) {
if (Debug.verboseOn())
Debug.logVerbose("iCalendar alarm fails validation: " + e, module);
}
}
}
}
Aggregations