use of net.fortuna.ical4j.model.parameter.Cn in project camel by apache.
the class ICalDataFormatTest method createTestCalendar.
/**
* Creates test calendar instance.
*
* @return ICal calendar object.
*/
protected Calendar createTestCalendar() throws ParseException {
// Create a TimeZone
TimeZoneRegistry registry = TimeZoneRegistryFactory.getInstance().createRegistry();
TimeZone timezone = registry.getTimeZone("America/New_York");
VTimeZone tz = timezone.getVTimeZone();
// Start Date is on: April 1, 2013, 9:00 am
java.util.Calendar startDate = new GregorianCalendar();
startDate.setTimeZone(timezone);
startDate.set(java.util.Calendar.MONTH, java.util.Calendar.APRIL);
startDate.set(java.util.Calendar.DAY_OF_MONTH, 1);
startDate.set(java.util.Calendar.YEAR, 2013);
startDate.set(java.util.Calendar.HOUR_OF_DAY, 17);
startDate.set(java.util.Calendar.MINUTE, 0);
startDate.set(java.util.Calendar.SECOND, 0);
// End Date is on: April 1, 2013, 13:00
java.util.Calendar endDate = new GregorianCalendar();
endDate.setTimeZone(timezone);
endDate.set(java.util.Calendar.MONTH, java.util.Calendar.APRIL);
endDate.set(java.util.Calendar.DAY_OF_MONTH, 1);
endDate.set(java.util.Calendar.YEAR, 2013);
endDate.set(java.util.Calendar.HOUR_OF_DAY, 21);
endDate.set(java.util.Calendar.MINUTE, 0);
endDate.set(java.util.Calendar.SECOND, 0);
// Create the event
PropertyList propertyList = new PropertyList();
propertyList.add(new DtStamp("20130324T180000Z"));
propertyList.add(new DtStart(new DateTime(startDate.getTime())));
propertyList.add(new DtEnd(new DateTime(endDate.getTime())));
propertyList.add(new Summary("Progress Meeting"));
VEvent meeting = new VEvent(propertyList);
// add timezone info..
meeting.getProperties().add(tz.getTimeZoneId());
// generate unique identifier..
meeting.getProperties().add(new Uid("00000000"));
// add attendees..
Attendee dev1 = new Attendee(URI.create("mailto:dev1@mycompany.com"));
dev1.getParameters().add(Role.REQ_PARTICIPANT);
dev1.getParameters().add(new Cn("Developer 1"));
meeting.getProperties().add(dev1);
Attendee dev2 = new Attendee(URI.create("mailto:dev2@mycompany.com"));
dev2.getParameters().add(Role.OPT_PARTICIPANT);
dev2.getParameters().add(new Cn("Developer 2"));
meeting.getProperties().add(dev2);
// Create a calendar
net.fortuna.ical4j.model.Calendar icsCalendar = new net.fortuna.ical4j.model.Calendar();
icsCalendar.getProperties().add(Version.VERSION_2_0);
icsCalendar.getProperties().add(new ProdId("-//Events Calendar//iCal4j 1.0//EN"));
icsCalendar.getProperties().add(CalScale.GREGORIAN);
// Add the event and print
icsCalendar.getComponents().add(meeting);
return icsCalendar;
}
use of net.fortuna.ical4j.model.parameter.Cn in project zm-mailbox by Zimbra.
the class DefaultTnefToICalendar method addAttendees.
/**
*
* @param icalOutput
* @param mimeMsg
* @param partstat
* @param replyWanted
* @throws ParserException
* @throws URISyntaxException
* @throws IOException
* @throws ParseException
* @throws MessagingException
*/
private void addAttendees(ContentHandler icalOutput, MimeMessage mimeMsg, PartStat partstat, boolean replyWanted) throws ParserException, URISyntaxException, IOException, ParseException, MessagingException {
// ATTENDEEs
InternetAddress firstFromIA = null;
String firstFromEmailAddr = null;
// Use for SENT-BY if applicable
String senderMailto = null;
String senderCn = null;
javax.mail.Address[] toRecips = null;
javax.mail.Address[] ccRecips = null;
javax.mail.Address[] bccRecips = null;
javax.mail.Address[] msgFroms = null;
javax.mail.Address msgSender = null;
if (mimeMsg != null) {
toRecips = mimeMsg.getRecipients(javax.mail.Message.RecipientType.TO);
ccRecips = mimeMsg.getRecipients(javax.mail.Message.RecipientType.CC);
bccRecips = mimeMsg.getRecipients(javax.mail.Message.RecipientType.BCC);
msgFroms = mimeMsg.getFrom();
msgSender = mimeMsg.getSender();
}
if (msgFroms != null) {
if (msgFroms.length != 1) {
sLog.debug(msgFroms.length + " From: recipients for " + method.getValue());
}
if (msgFroms.length >= 1) {
firstFromIA = (InternetAddress) msgFroms[0];
firstFromEmailAddr = firstFromIA.getAddress();
}
if (msgSender != null) {
String senderAddr = msgSender.toString();
if (msgSender instanceof InternetAddress) {
InternetAddress senderIA = (InternetAddress) msgSender;
senderAddr = senderIA.getAddress();
senderCn = senderIA.getPersonal();
if (!firstFromIA.equals(senderIA)) {
senderMailto = "Mailto:" + senderAddr;
}
}
}
}
if (method.equals(Method.REPLY) || method.equals(Method.COUNTER)) {
// from ATTENDEE to ORGANIZER
if (toRecips != null) {
if (toRecips.length != 1) {
sLog.debug(toRecips.length + " To: recipients for " + method.getValue());
}
if (toRecips.length >= 1) {
InternetAddress ia = (InternetAddress) toRecips[0];
String email = ia.getAddress();
String displayName = ia.getPersonal();
icalOutput.startProperty(Property.ORGANIZER);
icalOutput.propertyValue("Mailto:" + email);
if (displayName != null) {
icalOutput.parameter(Parameter.CN, displayName);
}
icalOutput.endProperty(Property.ORGANIZER);
}
}
if (firstFromEmailAddr != null) {
String displayName = firstFromIA.getPersonal();
icalOutput.startProperty(Property.ATTENDEE);
icalOutput.propertyValue("Mailto:" + firstFromEmailAddr);
if (displayName != null) {
icalOutput.parameter(Parameter.CN, displayName);
}
icalOutput.parameter(Parameter.CUTYPE, CuType.INDIVIDUAL.getValue());
if (partstat != null) {
icalOutput.parameter(Parameter.PARTSTAT, partstat.getValue());
}
if (senderMailto != null) {
icalOutput.parameter(Parameter.SENT_BY, senderMailto);
}
icalOutput.endProperty(Property.ATTENDEE);
}
} else {
// ORGANIZER to ATTENDEEs - REQUEST or CANCEL
InternetAddress organizerEmail = null;
if (firstFromEmailAddr != null) {
SentBy sentBy = null;
Cn cn = null;
if (senderMailto != null) {
sentBy = new SentBy(senderMailto);
}
organizerEmail = firstFromIA;
String displayName = firstFromIA.getPersonal();
if ((displayName != null) && (!displayName.equals(firstFromEmailAddr))) {
cn = new Cn(displayName);
}
Organizer organizer = new Organizer();
organizer.setValue("Mailto:" + firstFromEmailAddr);
if (cn != null) {
organizer.getParameters().add(cn);
}
if (sentBy != null) {
organizer.getParameters().add(sentBy);
}
IcalUtil.addProperty(icalOutput, organizer);
if (icalType == ICALENDAR_TYPE.VEVENT) {
// Assumption - ORGANIZER is an attendee and is attending.
Attendee attendee = new Attendee("Mailto:" + firstFromEmailAddr);
if (cn != null) {
attendee.getParameters().add(cn);
}
attendee.getParameters().add(CuType.INDIVIDUAL);
attendee.getParameters().add(Role.REQ_PARTICIPANT);
if (!method.equals(Method.CANCEL)) {
PartStat orgPartstat = PartStat.ACCEPTED;
if (ccRecips != null) {
for (Address a : ccRecips) {
InternetAddress ia = (InternetAddress) a;
if (organizerEmail.equals(ia)) {
orgPartstat = PartStat.TENTATIVE;
break;
}
}
}
attendee.getParameters().add(orgPartstat);
}
// Was including SENT-BY but probably not appropriate
// for a request
IcalUtil.addProperty(icalOutput, attendee);
}
}
if (toRecips != null) {
for (Address a : toRecips) {
InternetAddress ia = (InternetAddress) a;
if ((organizerEmail != null) && organizerEmail.equals(ia)) {
// No need to add the information twice
continue;
}
addAttendee(icalOutput, ia, Role.REQ_PARTICIPANT, CuType.INDIVIDUAL, partstat, replyWanted);
}
}
if (ccRecips != null) {
for (Address a : ccRecips) {
InternetAddress ia = (InternetAddress) a;
if ((organizerEmail != null) && organizerEmail.equals(ia)) {
// No need to add the information twice
continue;
}
addAttendee(icalOutput, ia, Role.OPT_PARTICIPANT, CuType.INDIVIDUAL, partstat, replyWanted);
}
}
if (bccRecips != null) {
for (Address a : bccRecips) {
InternetAddress ia = (InternetAddress) a;
addAttendee(icalOutput, ia, Role.NON_PARTICIPANT, CuType.RESOURCE, partstat, replyWanted);
}
}
}
if (senderMailto != null) {
XProperty msOlkSender = new XProperty("X-MS-OLK-SENDER", senderMailto);
if (senderCn != null) {
Cn cn = new Cn(senderCn);
msOlkSender.getParameters().add(cn);
}
IcalUtil.addProperty(icalOutput, msOlkSender);
}
}
use of net.fortuna.ical4j.model.parameter.Cn in project zm-mailbox by Zimbra.
the class DefaultTnefToICalendar method addAttendee.
/**
*
* @param icalOutput
* @param ia
* @param role
* @param cuType
* @param partstat
* @param rsvp
* @throws URISyntaxException
* @throws ParserException
* @throws IOException
* @throws ParseException
*/
private void addAttendee(ContentHandler icalOutput, InternetAddress ia, Role role, CuType cuType, PartStat partstat, boolean rsvp) throws URISyntaxException, ParserException, IOException, ParseException {
String email = ia.getAddress();
String displayName = ia.getPersonal();
Attendee attendee = new Attendee("Mailto:" + email);
if ((displayName != null) && (!displayName.equals(email))) {
Cn cn = new Cn(displayName);
attendee.getParameters().add(cn);
}
if (rsvp) {
attendee.getParameters().add(Rsvp.TRUE);
}
attendee.getParameters().add(role);
attendee.getParameters().add(cuType);
if (partstat != null) {
attendee.getParameters().add(partstat);
}
IcalUtil.addProperty(icalOutput, attendee);
}
Aggregations