Java Code Examples for net.fortuna.ical4j.model.Calendar#getComponent()
The following examples show how to use
net.fortuna.ical4j.model.Calendar#getComponent() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ICALAttributeDTO.java From james-project with Apache License 2.0 | 6 votes |
public RequiresSender from(Calendar calendar, byte[] originalEvent) { String ical = new String(originalEvent, StandardCharsets.UTF_8); VEvent vevent = (VEvent) calendar.getComponent("VEVENT"); Optional<String> uid = optionalOf(vevent.getUid()); Optional<String> method = optionalOf(calendar.getMethod()); Optional<String> recurrenceId = optionalOf(vevent.getRecurrenceId()); Optional<String> sequence = optionalOf(vevent.getSequence()); Optional<String> dtstamp = optionalOf(vevent.getDateStamp()); Preconditions.checkNotNull(ical); Preconditions.checkState(uid.isPresent(), "uid is a compulsory property of an ICAL object"); Preconditions.checkState(method.isPresent(), "method is a compulsory property of an ICAL object"); Preconditions.checkState(dtstamp.isPresent(), "dtstamp is a compulsory property of an ICAL object"); return sender -> recipient -> replyTo -> new ICALAttributeDTO( ical, uid.get(), sender.asString(), recipient.asString(), replyTo.asString(), dtstamp.get(), method.get(), sequence, recurrenceId); }
Example 2
Source File: EntityConverter.java From cosmo with Apache License 2.0 | 6 votes |
/** * Gets calendar from note. * @param note The note item. * @return The calendar. */ protected Calendar getCalendarFromNote(NoteItem note) { // Start with existing calendar if present Calendar calendar = note.getTaskCalendar(); // otherwise, start with new calendar if (calendar == null) { calendar = ICalendarUtils.createBaseCalendar(new VToDo()); } else { // use copy when merging calendar with item properties calendar = CalendarUtils.copyCalendar(calendar); } // merge in displayName,body VToDo task = (VToDo) calendar.getComponent(Component.VTODO); mergeCalendarProperties(task, note); return calendar; }
Example 3
Source File: DavAvailability.java From cosmo with Apache License 2.0 | 6 votes |
/** * <p> * Imports a calendar object containing a VAVAILABILITY. * @param cal The calendar imported. * @throws CosmoDavException - if something is wrong this exception is thrown. * </p> */ public void setCalendar(Calendar cal) throws CosmoDavException { AvailabilityItem availability = (AvailabilityItem) getItem(); availability.setAvailabilityCalendar(cal); Component comp = cal.getComponent(ICalendarConstants.COMPONENT_VAVAILABLITY); if (comp==null) { throw new UnprocessableEntityException("VCALENDAR does not contain a VAVAILABILITY"); } String val = null; Property prop = comp.getProperty(Property.UID); if (prop != null) { val = prop.getValue(); } if (StringUtils.isBlank(val)) { throw new UnprocessableEntityException("VAVAILABILITY does not contain a UID"); } availability.setIcalUid(val); }
Example 4
Source File: IcalUtils.java From openmeetings with Apache License 2.0 | 5 votes |
/** * Updating Appointments which already exist, by parsing the Calendar. And updating etag. * Doesn't work with complex Recurrences. * Note: Hasn't been tested to acknowledge DST, timezones should acknowledge this. * * @param a Appointment to be updated. * @param calendar iCalendar Representation. * @param etag The ETag of the calendar. * @return Updated Appointment. */ public Appointment parseCalendartoAppointment(Appointment a, Calendar calendar, String etag) { if (calendar == null) { return a; } CalendarComponent event = calendar.getComponent(Component.VEVENT); if (event != null) { a.setEtag(etag); a = addVEventPropertiestoAppointment(a, event); } return a; }
Example 5
Source File: IcalUtils.java From openmeetings with Apache License 2.0 | 5 votes |
/** * Parses the VTimezone Component of the given Calendar. If no, VTimezone component is found the * User Timezone is used * * @param calendar Calendar to parse * @param owner Owner of the Calendar * @return Parsed TimeZone */ public TimeZone parseTimeZone(Calendar calendar, User owner) { if (calendar != null) { Component timezone = calendar.getComponent(Component.VTIMEZONE); if (timezone != null) { Property tzid = timezone.getProperty(Property.TZID); if (tzid != null) { return getTimeZone(tzid.getValue()); } } } return getTimeZone(owner); }
Example 6
Source File: ICALToHeader.java From james-project with Apache License 2.0 | 5 votes |
private void writeToHeaders(Calendar calendar, Mail mail) throws MessagingException { MimeMessage mimeMessage = mail.getMessage(); VEvent vevent = (VEvent) calendar.getComponent("VEVENT"); addIfPresent(mimeMessage, X_MEETING_METHOD_HEADER, calendar.getMethod()); addIfPresent(mimeMessage, X_MEETING_UID_HEADER, vevent.getUid()); addIfPresent(mimeMessage, X_MEETING_RECURRENCE_ID_HEADER, vevent.getRecurrenceId()); addIfPresent(mimeMessage, X_MEETING_SEQUENCE_HEADER, vevent.getSequence()); addIfPresent(mimeMessage, X_MEETING_DTSTAMP_HEADER, vevent.getDateStamp()); }
Example 7
Source File: DavFreeBusy.java From cosmo with Apache License 2.0 | 5 votes |
/** * <p> * Imports a calendar object containing a VFREEBUSY. * </p> * @return The calendar imported. * @throws CosmoDavException - if something is wrong this exception is thrown. */ public void setCalendar(Calendar cal) throws CosmoDavException { FreeBusyItem freeBusy = (FreeBusyItem) getItem(); VFreeBusy vfb = (VFreeBusy) cal.getComponent(Component.VFREEBUSY); if (vfb==null) { throw new UnprocessableEntityException("VCALENDAR does not contain a VFREEBUSY"); } EntityConverter converter = new EntityConverter(getEntityFactory()); converter.convertFreeBusyCalendar(freeBusy, cal); }
Example 8
Source File: TimeZoneExtractor.java From cosmo with Apache License 2.0 | 3 votes |
/** * Creates an instance of <code>VTimeZone</code> from an * iCalendar string. * * The iCalendar string must include an enclosing VCALENDAR object * and exactly one enclosed VTIMEZONE component. All components, * properties and parameters are validated according to RFC 2445. * * @param ical the iCalendar string to parse * @return the <code>VTimeZone</code> representing the extracted * timezone, or <code>null</code> if the iCalendar string is * <code>null</code> * @throws CosmoDavException if the iCalendar string cannot be parsed or is * not a valid iCalendar object containing a single VTIMEZONE component */ public static VTimeZone extract(String ical) throws CosmoDavException { Calendar calendar = extractInCalendar(ical); if (calendar == null) { return null; } return (VTimeZone) calendar.getComponent(Component.VTIMEZONE); }