use of net.fortuna.ical4j.model.property.Clazz in project bw-calendar-engine by Bedework.
the class VEventUtil method toIcalComponent.
/**
* Make an Icalendar component from a BwEvent object. This may produce a
* VEvent, VTodo, VJournal or VPoll.
*
* @param ei the event
* @param isOverride - true if event object is an override
* @param tzreg - timezone registry
* @param currentPrincipal - href for current authenticated user
* @return Component
* @throws CalFacadeException
*/
public static Component toIcalComponent(final EventInfo ei, final boolean isOverride, final TimeZoneRegistry tzreg, final String currentPrincipal) throws CalFacadeException {
if ((ei == null) || (ei.getEvent() == null)) {
return null;
}
final BwEvent val = ei.getEvent();
boolean isInstance = false;
try {
Component xcomp = null;
Calendar cal = null;
final List<BwXproperty> xcompProps = val.getXproperties(BwXproperty.bedeworkIcal);
if (!Util.isEmpty(xcompProps)) {
final BwXproperty xcompProp = xcompProps.get(0);
final String xcompPropVal = xcompProp.getValue();
if (xcompPropVal != null) {
final StringBuilder sb = new StringBuilder();
final Icalendar ic = new Icalendar();
try {
sb.append("BEGIN:VCALENDAR\n");
sb.append(Version.VERSION_2_0.toString());
sb.append("\n");
sb.append(xcompPropVal);
if (!xcompPropVal.endsWith("\n")) {
sb.append("\n");
}
sb.append("END:VCALENDAR\n");
CalendarBuilder bldr = new CalendarBuilder(new CalendarParserImpl(), ic);
UnfoldingReader ufrdr = new UnfoldingReader(new StringReader(sb.toString()), true);
cal = bldr.build(ufrdr);
} catch (Throwable t) {
error(t);
error("Trying to parse:\n" + xcompPropVal);
}
}
}
Component comp;
PropertyList pl = new PropertyList();
boolean freeBusy = false;
boolean vavail = false;
boolean todo = false;
boolean vpoll = false;
int entityType = val.getEntityType();
if (entityType == IcalDefs.entityTypeEvent) {
comp = new VEvent(pl);
} else if (entityType == IcalDefs.entityTypeTodo) {
comp = new VToDo(pl);
todo = true;
} else if (entityType == IcalDefs.entityTypeJournal) {
comp = new VJournal(pl);
} else if (entityType == IcalDefs.entityTypeFreeAndBusy) {
comp = new VFreeBusy(pl);
freeBusy = true;
} else if (entityType == IcalDefs.entityTypeVavailability) {
comp = new VAvailability(pl);
vavail = true;
} else if (entityType == IcalDefs.entityTypeAvailable) {
comp = new Available(pl);
} else if (entityType == IcalDefs.entityTypeVpoll) {
comp = new VPoll(pl);
vpoll = true;
} else {
throw new CalFacadeException("org.bedework.invalid.entity.type", String.valueOf(entityType));
}
if (cal != null) {
xcomp = cal.getComponent(comp.getName());
}
Property prop;
/* ------------------- RecurrenceID --------------------
* Done early so we know if this is an instance.
*/
String strval = val.getRecurrenceId();
if ((strval != null) && (strval.length() > 0)) {
isInstance = true;
pl.add(new RecurrenceId(makeZonedDt(val, strval)));
}
/* ------------------- Alarms -------------------- */
VAlarmUtil.processEventAlarm(val, comp, currentPrincipal);
/* ------------------- Attachments -------------------- */
if (val.getNumAttachments() > 0) {
for (BwAttachment att : val.getAttachments()) {
pl.add(setAttachment(att));
}
}
/* ------------------- Attendees -------------------- */
if (!vpoll && (val.getNumAttendees() > 0)) {
for (BwAttendee att : val.getAttendees()) {
prop = setAttendee(att);
mergeXparams(prop, xcomp);
pl.add(prop);
}
}
if (val.getNumCategories() > 0) {
// LANG - filter on language - group language in one cat list?
for (BwCategory cat : val.getCategories()) {
prop = new Categories();
TextList cl = ((Categories) prop).getCategories();
cl.add(cat.getWord().getValue());
pl.add(langProp(prop, cat.getWord()));
}
}
/* ------------------- Class -------------------- */
final String pval = val.getClassification();
if (pval != null) {
pl.add(new Clazz(pval));
}
if (val.getNumComments() > 0) {
for (final BwString str : val.getComments()) {
pl.add(langProp(new Comment(str.getValue()), str));
}
}
if ((todo || vpoll) && (val.getCompleted() != null)) {
prop = new Completed(new DateTime(val.getCompleted()));
pl.add(prop);
}
if (val.getNumContacts() > 0) {
for (final BwContact c : val.getContacts()) {
// LANG
prop = new Contact(c.getCn().getValue());
final String l = c.getLink();
if (l != null) {
prop.getParameters().add(new AltRep(l));
}
pl.add(langProp(uidProp(prop, c.getUid()), c.getCn()));
}
}
if (val.getCost() != null) {
IcalUtil.addXproperty(pl, BwXproperty.bedeworkCost, null, val.getCost());
}
/* ------------------- Created -------------------- */
prop = new Created(val.getCreated());
// if (pars.includeDateTimeProperty) {
// prop.getParameters().add(Value.DATE_TIME);
// }
pl.add(prop);
if (val.getDeleted()) {
IcalUtil.addXproperty(pl, BwXproperty.bedeworkDeleted, null, String.valueOf(val.getDeleted()));
}
/* ------------------- Description -------------------- */
BwStringBase bwstr = val.findDescription(null);
if (bwstr != null) {
pl.add(langProp(new Description(bwstr.getValue()), bwstr));
}
if (val.getEndType() == StartEndComponent.endTypeDate) {
if (todo) {
Due due = val.getDtend().makeDue(tzreg);
if (freeBusy | val.getForceUTC()) {
due.setUtc(true);
}
pl.add(due);
} else {
DtEnd dtend = val.getDtend().makeDtEnd(tzreg);
if (freeBusy | val.getForceUTC()) {
dtend.setUtc(true);
}
pl.add(dtend);
}
} else if (val.getEndType() == StartEndComponent.endTypeDuration) {
addProperty(comp, new Duration(new Dur(val.getDuration())));
}
/* ------------------- DtStamp -------------------- */
prop = new DtStamp(new DateTime(val.getDtstamp()));
// if (pars.includeDateTimeProperty) {
// prop.getParameters().add(Value.DATE_TIME);
// }
pl.add(prop);
if (!val.getNoStart()) {
DtStart dtstart = val.getDtstart().makeDtStart(tzreg);
if (freeBusy | val.getForceUTC()) {
dtstart.setUtc(true);
}
pl.add(dtstart);
}
if (freeBusy) {
Collection<BwFreeBusyComponent> fbps = val.getFreeBusyPeriods();
if (fbps != null) {
for (BwFreeBusyComponent fbc : fbps) {
FreeBusy fb = new FreeBusy();
int type = fbc.getType();
if (type == BwFreeBusyComponent.typeBusy) {
addParameter(fb, FbType.BUSY);
} else if (type == BwFreeBusyComponent.typeFree) {
addParameter(fb, FbType.FREE);
} else if (type == BwFreeBusyComponent.typeBusyUnavailable) {
addParameter(fb, FbType.BUSY_UNAVAILABLE);
} else if (type == BwFreeBusyComponent.typeBusyTentative) {
addParameter(fb, FbType.BUSY_TENTATIVE);
} else {
throw new CalFacadeException("Bad free-busy type " + type);
}
PeriodList pdl = fb.getPeriods();
for (Period p : fbc.getPeriods()) {
// XXX inverse.ca plugin cannot handle durations.
Period np = new Period(p.getStart(), p.getEnd());
pdl.add(np);
}
pl.add(fb);
}
}
}
if (!vpoll) {
BwGeo bwgeo = val.getGeo();
if (bwgeo != null) {
Geo geo = new Geo(bwgeo.getLatitude(), bwgeo.getLongitude());
pl.add(geo);
}
}
/* ------------------- LastModified -------------------- */
prop = new LastModified(new DateTime(val.getLastmod()));
// if (pars.includeDateTimeProperty) {
// prop.getParameters().add(Value.DATE_TIME);
// }
pl.add(prop);
if (!vpoll) {
final BwLocation loc = val.getLocation();
if (loc != null) {
prop = new Location(loc.getCombinedValues());
pl.add(langProp(uidProp(prop, loc.getUid()), loc.getAddress()));
IcalUtil.addXproperty(pl, BwXproperty.xBedeworkLocationAddr, null, loc.getAddressField());
IcalUtil.addXproperty(pl, BwXproperty.xBedeworkLocationRoom, null, loc.getRoomField());
IcalUtil.addXproperty(pl, BwXproperty.xBedeworkLocationAccessible, null, String.valueOf(loc.getAccessible()));
IcalUtil.addXproperty(pl, BwXproperty.xBedeworkLocationSfield1, null, loc.getSubField1());
IcalUtil.addXproperty(pl, BwXproperty.xBedeworkLocationSfield2, null, loc.getSubField2());
IcalUtil.addXproperty(pl, BwXproperty.xBedeworkLocationGeo, null, loc.getGeouri());
IcalUtil.addXproperty(pl, BwXproperty.xBedeworkLocationStreet, null, loc.getStreet());
IcalUtil.addXproperty(pl, BwXproperty.xBedeworkLocationCity, null, loc.getCity());
IcalUtil.addXproperty(pl, BwXproperty.xBedeworkLocationState, null, loc.getState());
IcalUtil.addXproperty(pl, BwXproperty.xBedeworkLocationZip, null, loc.getZip());
IcalUtil.addXproperty(pl, BwXproperty.xBedeworkLocationLink, null, loc.getLink());
}
}
/* ------------------- Organizer -------------------- */
BwOrganizer org = val.getOrganizer();
if (org != null) {
prop = setOrganizer(org);
mergeXparams(prop, xcomp);
pl.add(prop);
}
if (todo) {
Integer pc = val.getPercentComplete();
if (pc != null) {
pl.add(new PercentComplete(pc.intValue()));
}
}
/* ------------------- Priority -------------------- */
Integer prio = val.getPriority();
if (prio != null) {
pl.add(new Priority(prio.intValue()));
}
/* ------------------- RDate -below------------------- */
/* ------------------- RelatedTo -------------------- */
/* We encode related to (maybe) as triples - reltype, value-type, value */
String[] info = null;
BwRelatedTo relto = val.getRelatedTo();
if (relto != null) {
info = new String[3];
info[0] = relto.getRelType();
// default
info[1] = "";
info[2] = relto.getValue();
} else {
String relx = val.getXproperty(BwXproperty.bedeworkRelatedTo);
if (relx != null) {
info = Util.decodeArray(relx);
}
}
if (info != null) {
int i = 0;
while (i < info.length) {
RelatedTo irelto;
String reltype = info[i];
String valtype = info[i + 1];
String relval = info[i + 2];
ParameterList rtpl = null;
if (reltype.length() > 0) {
rtpl = new ParameterList();
rtpl.add(new RelType(reltype));
}
if (valtype.length() > 0) {
if (rtpl == null) {
rtpl = new ParameterList();
}
rtpl.add(new Value(valtype));
}
if (rtpl != null) {
irelto = new RelatedTo(rtpl, relval);
} else {
irelto = new RelatedTo(relval);
}
pl.add(irelto);
i += 3;
}
}
if (val.getNumResources() > 0) {
/* This event has a resource */
prop = new Resources();
TextList rl = ((Resources) prop).getResources();
for (BwString str : val.getResources()) {
// LANG
rl.add(str.getValue());
}
pl.add(prop);
}
if (val.getSequence() > 0) {
pl.add(new Sequence(val.getSequence()));
}
/* ------------------- Status -------------------- */
String status = val.getStatus();
if ((status != null) && !status.equals(BwEvent.statusMasterSuppressed)) {
pl.add(new Status(status));
}
/* ------------------- Summary -------------------- */
bwstr = val.findSummary(null);
if (bwstr != null) {
pl.add(langProp(new Summary(bwstr.getValue()), bwstr));
}
if (!todo && !vpoll) {
strval = val.getPeruserTransparency(currentPrincipal);
if ((strval != null) && (strval.length() > 0)) {
pl.add(new Transp(strval));
}
}
/* ------------------- Uid -------------------- */
pl.add(new Uid(val.getUid()));
/* ------------------- Url -------------------- */
strval = val.getLink();
if (strval != null) {
// Possibly drop this if we do it on input and check all data
strval = strval.trim();
}
if ((strval != null) && (strval.length() > 0)) {
URI uri = Util.validURI(strval);
if (uri != null) {
pl.add(new Url(uri));
}
}
if (val.getNumXproperties() > 0) {
try {
IcalUtil.xpropertiesToIcal(pl, val.getXproperties());
} catch (Throwable t) {
// XXX For the moment swallow these.
error(t);
}
}
if (!vpoll && !isInstance && !isOverride && val.testRecurring()) {
doRecurring(val, pl);
}
if (vavail) {
if (ei.getNumContainedItems() > 0) {
final VAvailability va = (VAvailability) comp;
for (final EventInfo aei : ei.getContainedItems()) {
va.getAvailable().add((Available) toIcalComponent(aei, false, tzreg, currentPrincipal));
}
}
/* ----------- Vavailability - busyType ----------------- */
String s = val.getBusyTypeString();
if (s != null) {
pl.add(new BusyType(s));
}
}
if (vpoll) {
final Integer ival = val.getPollWinner();
if (ival != null) {
pl.add(new PollWinner(ival));
}
strval = val.getPollAcceptResponse();
if ((strval != null) && (strval.length() > 0)) {
pl.add(new AcceptResponse(strval));
}
strval = val.getPollMode();
if ((strval != null) && (strval.length() > 0)) {
pl.add(new PollMode(strval));
}
strval = val.getPollProperties();
if ((strval != null) && (strval.length() > 0)) {
pl.add(new PollProperties(strval));
}
final Map<String, VVoter> vvoters = parseVpollVvoters(val);
for (final VVoter vv : vvoters.values()) {
((VPoll) comp).getVoters().add(vv);
}
final Map<Integer, Component> comps = parseVpollCandidates(val);
for (final Component candidate : comps.values()) {
((VPoll) comp).getCandidates().add(candidate);
}
}
return comp;
} catch (final CalFacadeException cfe) {
throw cfe;
} catch (final Throwable t) {
throw new CalFacadeException(t);
}
}
use of net.fortuna.ical4j.model.property.Clazz 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.Clazz in project zm-mailbox by Zimbra.
the class DefaultTnefToICalendar method convert.
/* (non-Javadoc)
* @see com.zimbra.cs.util.tnef.TnefToICalendar#convert(java.io.InputStream, net.fortuna.ical4j.data.ContentHandler)
*/
public boolean convert(MimeMessage mimeMsg, InputStream tnefInput, ContentHandler icalOutput) throws ServiceException {
boolean conversionSuccessful = false;
recurDef = null;
TNEFInputStream tnefStream = null;
SchedulingViewOfTnef schedView = null;
Integer sequenceNum = 0;
icalType = ICALENDAR_TYPE.VEVENT;
try {
tnefStream = new TNEFInputStream(tnefInput);
schedView = new SchedulingViewOfTnef(tnefStream);
String msgClass = schedView.getMessageClass();
if (msgClass == null) {
sLog.debug("Unable to determine Class of TNEF - cannot generate ICALENDER equivalent");
// throw TNEFtoIcalendarServiceException.NON_CALENDARING_CLASS(msgClass);
return false;
}
icalType = schedView.getIcalType();
method = null;
PartStat partstat = null;
boolean replyWanted = schedView.getResponseRequested();
Boolean isCounterProposal = schedView.isCounterProposal();
if (msgClass != null) {
// just in case.
if (msgClass.startsWith("IPM.Microsoft Schedule.MtgReq")) {
method = Method.REQUEST;
partstat = PartStat.NEEDS_ACTION;
} else if (msgClass.startsWith("IPM.Microsoft Schedule.MtgRespP")) {
method = Method.REPLY;
partstat = PartStat.ACCEPTED;
replyWanted = false;
} else if (msgClass.startsWith("IPM.Microsoft Schedule.MtgRespN")) {
method = Method.REPLY;
partstat = PartStat.DECLINED;
replyWanted = false;
} else if (msgClass.startsWith("IPM.Microsoft Schedule.MtgRespA")) {
if ((isCounterProposal != null) && isCounterProposal) {
method = Method.COUNTER;
} else {
method = Method.REPLY;
}
partstat = PartStat.TENTATIVE;
replyWanted = false;
} else if (msgClass.startsWith("IPM.Microsoft Schedule.MtgCncl")) {
method = Method.CANCEL;
replyWanted = false;
} else if (msgClass.startsWith("IPM.TaskRequest.Accept")) {
method = Method.REPLY;
partstat = PartStat.ACCEPTED;
replyWanted = false;
} else if (msgClass.startsWith("IPM.TaskRequest.Decline")) {
method = Method.REPLY;
partstat = PartStat.DECLINED;
replyWanted = false;
} else if (msgClass.startsWith("IPM.TaskRequest.Update")) {
method = Method.REPLY;
// May be overridden?
partstat = PartStat.IN_PROCESS;
replyWanted = false;
} else if (msgClass.startsWith("IPM.TaskRequest")) {
method = Method.REQUEST;
partstat = PartStat.NEEDS_ACTION;
replyWanted = true;
}
}
if (method == null) {
sLog.debug("Unable to map class %s to ICALENDER", msgClass);
return false;
// throw TNEFtoIcalendarServiceException.NON_CALENDARING_CLASS(msgClass);
}
if (icalType == ICALENDAR_TYPE.VTODO) {
List<?> attaches = (List<?>) schedView.getAttachments();
if (attaches == null) {
sLog.debug("Unable to map class %s to ICALENDER - no attachments", msgClass);
return false;
}
schedView = null;
for (Object obj : attaches) {
if (obj instanceof Attachment) {
Attachment currAttach = (Attachment) obj;
MAPIProps attachMPs = currAttach.getMAPIProps();
if (attachMPs != null) {
MAPIProp attachData = attachMPs.getProp(MAPIProp.PR_ATTACH_DATA_OBJ);
if (attachData != null) {
Object theVal = attachData.getValue();
if ((theVal != null) && (theVal instanceof TNEFInputStream)) {
TNEFInputStream tnefSubStream = (TNEFInputStream) theVal;
schedView = new SchedulingViewOfTnef(tnefSubStream);
break;
}
}
}
}
}
if (schedView == null) {
sLog.debug("Unable to map class %s to ICALENDER - no properties found for sub-msg", msgClass);
return false;
}
}
uid = schedView.getIcalUID();
sequenceNum = schedView.getSequenceNumber();
boolean reminderSet = schedView.getReminderSet();
String location = schedView.getLocation();
Boolean isAllDayEvent = schedView.isAllDayEvent();
Integer importance = schedView.getMapiImportance();
Clazz icalClass = schedView.getIcalClass();
Integer ownerApptId = schedView.getOwnerAppointmentId();
EnumSet<MeetingTypeFlag> meetingTypeFlags = schedView.getMeetingTypeFlags();
BusyStatus busyStatus = schedView.getBusyStatus();
BusyStatus intendedBusyStatus = schedView.getIntendedBusyStatus();
// For some ICAL properties like TRANSP and STATUS, intendedBusyStatus
// seems closer to what is intended than straight busyStatus
BusyStatus bestBusyStatus = intendedBusyStatus;
if (bestBusyStatus == null) {
bestBusyStatus = busyStatus;
}
// An algorithm is used to choose the values for these
// TimeZoneDefinitions - they don't necessarily map to single
// MAPI properties
TimeZoneDefinition startTimeTZinfo = schedView.getStartDateTimezoneInfo();
TimeZoneDefinition endTimeTZinfo = schedView.getEndDateTimezoneInfo();
TimeZoneDefinition recurrenceTZinfo = schedView.getRecurrenceTimezoneInfo();
recurDef = schedView.getRecurrenceDefinition(recurrenceTZinfo);
DateTime icalStartDate = schedView.getStartTime();
DateTime icalEndDate = schedView.getEndTime();
DateTime icalDueDate = schedView.getDueDate();
DateTime icalDateTaskCompleted = schedView.getDateTaskCompleted();
DateTime icalCreateDate = MapiPropertyId.PidTagCreationTime.getDateTimeAsUTC(schedView);
DateTime icalLastModDate = MapiPropertyId.PidTagLastModificationTime.getDateTimeAsUTC(schedView);
DateTime recurrenceIdDateTime = schedView.getRecurrenceIdTime();
DateTime attendeeCriticalChange = schedView.getAttendeeCriticalChange();
DateTime ownerCriticalChange = schedView.getOwnerCriticalChange();
int percentComplete = schedView.getPercentComplete();
TaskStatus taskStatus = schedView.getTaskStatus();
TaskMode taskMode = schedView.getTaskMode();
String mileage = schedView.getMileage();
String billingInfo = schedView.getBillingInfo();
String companies = schedView.getCompanies();
Integer actualEffort = schedView.getActualEffort();
Integer estimatedEffort = schedView.getEstimatedEffort();
List<String> categories = schedView.getCategories();
String descriptionText = null;
String summary = null;
if (mimeMsg != null) {
summary = mimeMsg.getSubject();
PlainTextFinder finder = new PlainTextFinder();
finder.accept(mimeMsg);
descriptionText = finder.getPlainText();
}
// RTF might be useful as a basis for X-ALT-DESC if we can find a reliable
// conversion to HTML
// String rtfText = schedView.getRTF();
icalOutput.startCalendar();
// Results in a 2nd PRODID in iCalendar
// IcalUtil.addProperty(icalOutput, Property.PRODID,
// "Zimbra-TNEF-iCalendar-Converter");
IcalUtil.addProperty(icalOutput, method);
if (recurDef != null) {
String MsCalScale = recurDef.xMicrosoftCalscale();
if ((MsCalScale == null) || (MsCalScale.equals(""))) {
IcalUtil.addProperty(icalOutput, CalScale.GREGORIAN);
} else {
IcalUtil.addProperty(icalOutput, "X-MICROSOFT-CALSCALE", MsCalScale);
}
} else {
IcalUtil.addProperty(icalOutput, CalScale.GREGORIAN);
}
String startTZname = null;
String endTZname = null;
String recurTZname = null;
if (startTimeTZinfo != null) {
startTZname = startTimeTZinfo.getTimezoneName();
startTimeTZinfo.addVtimezone(icalOutput);
}
if (endTimeTZinfo != null) {
endTZname = endTimeTZinfo.getTimezoneName();
if ((startTZname == null) || (!endTZname.equals(startTZname))) {
endTimeTZinfo.addVtimezone(icalOutput);
}
}
if (recurrenceTZinfo != null) {
recurTZname = recurrenceTZinfo.getTimezoneName();
boolean addName = true;
if ((startTZname != null) && (recurTZname.equals(startTZname))) {
addName = false;
}
if ((endTZname != null) && (recurTZname.equals(endTZname))) {
addName = false;
}
if (addName) {
recurrenceTZinfo.addVtimezone(icalOutput);
}
}
if (uid == null) {
sLog.debug("Unable to map class %s to ICALENDER - no suitable value found for UID", msgClass);
return false;
}
icalOutput.startComponent(icalType.toString());
IcalUtil.addProperty(icalOutput, Property.UID, uid);
if ((attendeeCriticalChange != null) && (method.equals(Method.REPLY) || method.equals(Method.COUNTER))) {
dtstamp = new DtStamp(attendeeCriticalChange);
} else if (ownerCriticalChange != null) {
dtstamp = new DtStamp(ownerCriticalChange);
} else {
DateTime stampTime = new DateTime("20000101T000000Z");
dtstamp = new DtStamp(stampTime);
}
IcalUtil.addProperty(icalOutput, dtstamp);
IcalUtil.addProperty(icalOutput, Property.CREATED, icalCreateDate, false);
IcalUtil.addProperty(icalOutput, Property.LAST_MODIFIED, icalLastModDate, false);
IcalUtil.addProperty(icalOutput, Property.SEQUENCE, sequenceNum, false);
if ((summary == null) || (summary.length() == 0)) {
// TNEF_to_iCalendar.pdf Spec requires SUMMARY for certain method types
if (this.icalType == ICALENDAR_TYPE.VTODO) {
if (method.equals(Method.REQUEST)) {
summary = new String("Task Request");
} else if (method.equals(Method.REPLY)) {
summary = new String("Task Response");
} else {
summary = new String("Task");
}
} else {
if (method.equals(Method.REPLY)) {
summary = new String("Response");
} else if (method.equals(Method.CANCEL)) {
summary = new String("Canceled");
} else if (method.equals(Method.COUNTER)) {
summary = new String("Counter Proposal");
}
}
}
IcalUtil.addProperty(icalOutput, Property.SUMMARY, summary, false);
IcalUtil.addProperty(icalOutput, Property.LOCATION, location, false);
IcalUtil.addProperty(icalOutput, Property.DESCRIPTION, descriptionText, false);
if (method.equals(Method.COUNTER)) {
IcalUtil.addPropertyFromUtcTimeAndZone(icalOutput, Property.DTSTART, schedView.getProposedStartTime(), startTimeTZinfo, isAllDayEvent);
IcalUtil.addPropertyFromUtcTimeAndZone(icalOutput, Property.DTEND, schedView.getProposedEndTime(), endTimeTZinfo, isAllDayEvent);
IcalUtil.addPropertyFromUtcTimeAndZone(icalOutput, "X-MS-OLK-ORIGINALSTART", icalStartDate, startTimeTZinfo, isAllDayEvent);
IcalUtil.addPropertyFromUtcTimeAndZone(icalOutput, "X-MS-OLK-ORIGINALEND", icalEndDate, endTimeTZinfo, isAllDayEvent);
} else {
if (this.icalType == ICALENDAR_TYPE.VTODO) {
IcalUtil.addFloatingDateProperty(icalOutput, Property.DTSTART, icalStartDate);
IcalUtil.addFloatingDateProperty(icalOutput, Property.DUE, icalDueDate);
Status icalStatus = null;
if (method.equals(Method.CANCEL)) {
icalStatus = Status.VTODO_CANCELLED;
} else if (taskStatus != null) {
if (taskStatus.equals(TaskStatus.COMPLETE)) {
icalStatus = Status.VTODO_COMPLETED;
} else if (taskStatus.equals(TaskStatus.IN_PROGRESS)) {
icalStatus = Status.VTODO_IN_PROCESS;
}
}
IcalUtil.addProperty(icalOutput, icalStatus);
if (percentComplete != 0) {
IcalUtil.addProperty(icalOutput, Property.PERCENT_COMPLETE, percentComplete, false);
}
// COMPLETED must be a UTC DATE-TIME according to rfc5545
IcalUtil.addPropertyFromUtcTimeAndZone(icalOutput, Property.COMPLETED, icalDateTaskCompleted, null, false);
} else {
IcalUtil.addPropertyFromUtcTimeAndZone(icalOutput, Property.DTSTART, icalStartDate, startTimeTZinfo, isAllDayEvent);
IcalUtil.addPropertyFromUtcTimeAndZone(icalOutput, Property.DTEND, icalEndDate, endTimeTZinfo, isAllDayEvent);
}
}
// just the original start date.
if (recurrenceIdDateTime != null) {
IcalUtil.addPropertyFromUtcTimeAndZone(icalOutput, Property.RECURRENCE_ID, recurrenceIdDateTime, startTimeTZinfo, isAllDayEvent);
} else {
// Outlook messages related to a specific instance still include info on
// the full recurrence but we don't want to include that.
addRecurrenceRelatedProps(icalOutput, recurDef, startTimeTZinfo, isAllDayEvent);
}
// VTODO REQUEST must have priority according to http://tools.ietf.org/html/rfc5546
// No harm in always setting it
Priority priority = Priority.MEDIUM;
if (importance != null) {
if (importance == 2) {
priority = Priority.HIGH;
} else if (importance == 1) {
priority = Priority.MEDIUM;
} else if (importance == 0) {
priority = Priority.LOW;
}
}
IcalUtil.addProperty(icalOutput, priority);
IcalUtil.addProperty(icalOutput, icalClass);
addStatusProperty(icalOutput, bestBusyStatus, meetingTypeFlags);
addTranspProperty(icalOutput, bestBusyStatus);
addAttendees(icalOutput, mimeMsg, partstat, replyWanted);
// Not done as Zimbra doesn't currently support "RESOURCES".
if (categories != null) {
CategoryList cl = new CategoryList();
for (String category : categories) {
cl.add(category);
}
if (cl.size() > 0) {
Categories myCategories = new Categories(cl);
IcalUtil.addProperty(icalOutput, myCategories);
}
}
if (taskStatus != null) {
if (taskStatus.equals(TaskStatus.DEFERRED) || taskStatus.equals(TaskStatus.WAITING_ON_OTHER)) {
IcalUtil.addProperty(icalOutput, "X-ZIMBRA-TASK-STATUS", taskStatus, false);
}
}
if ((taskMode != null) && (!taskMode.equals(TaskMode.TASK_REQUEST))) {
IcalUtil.addProperty(icalOutput, "X-ZIMBRA-TASK-MODE", taskMode, false);
}
IcalUtil.addProperty(icalOutput, "X-ZIMBRA-MILEAGE", mileage, false);
IcalUtil.addProperty(icalOutput, "X-ZIMBRA-BILLING-INFO", billingInfo, false);
IcalUtil.addProperty(icalOutput, "X-ZIMBRA-COMPANIES", companies, false);
IcalUtil.addProperty(icalOutput, "X-ZIMBRA-ACTUAL-WORK-MINS", actualEffort, false);
IcalUtil.addProperty(icalOutput, "X-ZIMBRA-TOTAL-WORK-MINS", estimatedEffort, false);
if (this.icalType == ICALENDAR_TYPE.VEVENT) {
IcalUtil.addProperty(icalOutput, "X-MICROSOFT-CDO-ALLDAYEVENT", isAllDayEvent ? "TRUE" : "FALSE");
IcalUtil.addProperty(icalOutput, "X-MICROSOFT-CDO-BUSYSTATUS", busyStatus, false);
if (method.equals(Method.REQUEST)) {
IcalUtil.addProperty(icalOutput, "X-MICROSOFT-CDO-INTENDEDSTATUS", intendedBusyStatus, false);
}
IcalUtil.addProperty(icalOutput, "X-MICROSOFT-CDO-OWNERAPPTID", ownerApptId, false);
IcalUtil.addProperty(icalOutput, "X-MICROSOFT-CDO-REPLYTIME", schedView.getAppointmentReplyTime(), false);
IcalUtil.addProperty(icalOutput, "X-MICROSOFT-CDO-OWNER-CRITICAL-CHANGE", ownerCriticalChange, false);
Boolean disallowCounter = schedView.isDisallowCounter();
if (disallowCounter != null) {
IcalUtil.addProperty(icalOutput, "X-MICROSOFT-CDO-DISALLOW-COUNTER", disallowCounter ? "TRUE" : "FALSE");
}
}
if (reminderSet) {
addAlarmComponent(icalOutput, schedView.getReminderDelta());
}
icalOutput.endComponent(icalType.toString());
if (recurrenceIdDateTime == null) {
// If this message primarily relates to a specific instance,
// exception information is superfluous
addExceptions(icalOutput, recurDef, recurrenceTZinfo, sequenceNum, ownerApptId, summary, location, isAllDayEvent);
}
icalOutput.endCalendar();
conversionSuccessful = true;
sLog.info("Calendaring TNEF message mapped to ICALENDAR with UID=%s", uid);
} catch (ParserException e) {
sLog.debug("Unexpected ParserException thrown", e);
} catch (URISyntaxException e) {
sLog.debug("Unexpected URISyntaxException thrown", e);
} catch (ParseException e) {
sLog.debug("Unexpected ParseException thrown", e);
} catch (MessagingException e) {
sLog.debug("Unexpected MessagingException thrown", e);
} catch (NegativeArraySizeException e) {
sLog.debug("Problem decoding TNEF for ICALENDAR", e);
} catch (IOException e) {
sLog.debug("Unexpected IOException thrown", e);
} catch (UnsupportedTnefCalendaringMsgException e) {
sLog.debug("Unable to map this message to ICALENDAR", e);
} catch (TNEFtoIcalendarServiceException e) {
sLog.debug("Problem encountered mapping this message to ICALENDAR", e);
} finally {
try {
if (tnefStream != null) {
tnefStream.close();
}
} catch (IOException ioe) {
sLog.debug("Problem encountered closing TNEF stream", ioe);
}
}
return conversionSuccessful;
}
use of net.fortuna.ical4j.model.property.Clazz in project openolat by klemens.
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;
}
Aggregations