net.fortuna.ical4j.model.Component Java Examples
The following examples show how to use
net.fortuna.ical4j.model.Component.
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: IcsConverter.java From ganttproject with GNU General Public License v3.0 | 7 votes |
public static void main(String[] args) throws Exception { Args mainArgs = new Args(); try { new JCommander(new Object[] { mainArgs }, args); } catch (Throwable e) { e.printStackTrace(); return; } if (mainArgs.file.size() != 1) { System.err.println("Only 1 input file should be specified"); return; } CalendarBuilder builder = new CalendarBuilder(); Calendar c = builder.build(new UnfoldingReader(new FileReader(mainArgs.file.get(0)))); for (Component comp : (List<Component>)c.getComponents()) { System.err.println(comp); } }
Example #2
Source File: TeamEventUtils.java From projectforge-webapp with GNU General Public License v3.0 | 6 votes |
public static List<VEvent> getVEvents(final net.fortuna.ical4j.model.Calendar calendar) { final List<VEvent> events = new ArrayList<VEvent>(); @SuppressWarnings("unchecked") final List<Component> list = calendar.getComponents(Component.VEVENT); if (list == null || list.size() == 0) { return events; } // Temporary not used, because multiple events are not supported. for (final Component c : list) { final VEvent event = (VEvent) c; if (StringUtils.equals(event.getSummary().getValue(), CalendarFeed.SETUP_EVENT) == true) { // skip setup event! continue; } events.add(event); } return events; }
Example #3
Source File: RecurrenceExpander.java From cosmo with Apache License 2.0 | 6 votes |
/** * Expand recurring event for given time-range. * @param calendar calendar containing recurring event and modifications * @param rangeStart expand start * @param rangeEnd expand end * @param timezone Optional timezone to use for floating dates. If null, the * system default is used. * @return InstanceList containing all occurences of recurring event during * time range */ public InstanceList getOcurrences(Calendar calendar, Date rangeStart, Date rangeEnd, TimeZone timezone) { ComponentList<VEvent> vevents = calendar.getComponents().getComponents(Component.VEVENT); List<Component> exceptions = new ArrayList<Component>(); Component masterComp = null; // get list of exceptions (VEVENT with RECURRENCEID) for (Iterator<VEvent> i = vevents.iterator(); i.hasNext();) { VEvent event = i.next(); if (event.getRecurrenceId() != null) { exceptions.add(event); } else { masterComp = event; } } return getOcurrences(masterComp, exceptions, rangeStart, rangeEnd, timezone); }
Example #4
Source File: RecurrenceExpander.java From cosmo with Apache License 2.0 | 6 votes |
/** * Return start and end Date that represent the start of the first * occurrence of a recurring component and the end of the last * occurence. If the recurring component has no end(infinite recurring event), * then no end date will be returned. * @param calendar Calendar containing master and modification components * @return array containing start (located at index 0) and end (index 1) of * recurring component. */ public Date[] calculateRecurrenceRange(Calendar calendar) { try{ ComponentList<VEvent> vevents = calendar.getComponents().getComponents(Component.VEVENT); List<Component> exceptions = new ArrayList<Component>(); Component masterComp = null; // get list of exceptions (VEVENT with RECURRENCEID) for (Iterator<VEvent> i = vevents.iterator(); i.hasNext();) { VEvent event = i.next(); if (event.getRecurrenceId() != null) { exceptions.add(event); } else { masterComp = event; } } return calculateRecurrenceRange(masterComp, exceptions); } catch (Exception e){ LOG.error("ERROR in calendar: " + calendar, e); throw e; } }
Example #5
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 #6
Source File: MultigetHandler.java From openmeetings with Apache License 2.0 | 6 votes |
public MultigetHandler(List<String> hrefs, boolean onlyEtag, String path, OmCalendar calendar, HttpClient client, HttpClientContext context, AppointmentDao appointmentDao, IcalUtils utils) { super(path, calendar, client, context, appointmentDao, utils); this.onlyEtag = onlyEtag; if (hrefs == null || hrefs.isEmpty() || calendar.getSyncType() == SyncType.NONE) { isMultigetDisabled = true; } else { DavPropertyNameSet properties = new DavPropertyNameSet(); properties.add(DavPropertyName.GETETAG); CalendarData calendarData = null; if (!onlyEtag) { calendarData = new CalendarData(); } CompFilter vcalendar = new CompFilter(Calendar.VCALENDAR); vcalendar.addCompFilter(new CompFilter(Component.VEVENT)); query = new CalendarMultiget(properties, calendarData, false, false); query.setHrefs(hrefs); } }
Example #7
Source File: EventCollectionResource.java From XPagesExtensionLibrary with Apache License 2.0 | 6 votes |
private String extractUid(String icalendar) throws IOException, ParserException { String uid = null; StringReader reader = new StringReader(icalendar); CalendarBuilder builder = new CalendarBuilder(); Calendar calendar = builder.build(new UnfoldingReader(reader, true)); if ( calendar != null && calendar.getComponents() != null ) { Iterator<Component> iterator = calendar.getComponents().iterator(); while (iterator.hasNext()) { Component component = iterator.next(); if ( component instanceof VEvent ) { uid = ((VEvent)component).getUid().getValue(); break; } } } return uid; }
Example #8
Source File: ICalConverter.java From scipio-erp with Apache License 2.0 | 6 votes |
protected static ResponseProperties storeWorkEffort(Component component, Map<String, Object> context) throws GenericEntityException { PropertyList<Property> propertyList = component.getProperties(); String workEffortId = fromXProperty(propertyList, workEffortIdXPropName); Delegator delegator = (Delegator) context.get("delegator"); GenericValue workEffort = EntityQuery.use(delegator).from("WorkEffort").where("workEffortId", workEffortId).queryOne(); if (workEffort == null) { return ICalWorker.createNotFoundResponse(null); } if (!hasPermission(workEffortId, "UPDATE", context)) { return null; } Map<String, Object> serviceMap = new HashMap<>(); serviceMap.put("workEffortId", workEffortId); setWorkEffortServiceMap(component, serviceMap); invokeService("updateWorkEffort", serviceMap, context); return storePartyAssignments(workEffortId, component, context); }
Example #9
Source File: CalendarResourceProvider.java From cosmo with Apache License 2.0 | 6 votes |
protected DavContent createCalendarResource(DavRequest request, DavResponse response, DavResourceLocator locator, Calendar calendar) throws CosmoDavException { if (!calendar.getComponents(Component.VEVENT).isEmpty()) { return new DavEvent(locator, getResourceFactory(), getEntityFactory()); } if (!calendar.getComponents(Component.VTODO).isEmpty()) { return new DavTask(locator, getResourceFactory(), getEntityFactory()); } if (!calendar.getComponents(Component.VJOURNAL).isEmpty()) { return new DavJournal(locator, getResourceFactory(), getEntityFactory()); } if (!calendar.getComponents(Component.VFREEBUSY).isEmpty()) { return new DavFreeBusy(locator, getResourceFactory(), getEntityFactory()); } if (!calendar.getComponents(ICalendarConstants.COMPONENT_VAVAILABLITY) .isEmpty()) { return new DavAvailability(locator, getResourceFactory(), getEntityFactory()); } throw new SupportedCalendarComponentException(); }
Example #10
Source File: CalendarDaoICalFileImpl.java From olat with Apache License 2.0 | 6 votes |
private OlatCalendar createKalendar(final String type, final String calendarID, final Calendar calendar) { final OlatCalendar olatCalendar = new OlatCalendar(calendarID, type); for (final Iterator iter = calendar.getComponents().iterator(); iter.hasNext();) { final Component comp = (Component) iter.next(); if (comp instanceof VEvent) { final VEvent vevent = (VEvent) comp; final CalendarEntry calEntry = getCalendarEntry(vevent); olatCalendar.addEvent(calEntry); } else if (comp instanceof VTimeZone) { log.info("createKalendar: VTimeZone Component is not supported and will not be added to calender"); log.debug("createKalendar: VTimeZone=" + comp); } else { log.warn("createKalendar: unknown Component=" + comp); } } return olatCalendar; }
Example #11
Source File: FreeBusyUtil.java From cosmo with Apache License 2.0 | 6 votes |
/** * Obfuscates the specified calendar by removing unnecessary properties and replacing text fields with specified * text. * * @param original * calendar to be obfuscated * @param productId * productId to be set for the copy calendar. * @param freeBusyText * @return obfuscated calendar. */ public static Calendar getFreeBusyCalendar(Calendar original, String productId, String freeBusyText) { // Make a copy of the original calendar Calendar copy = new Calendar(); copy.getProperties().add(new ProdId(productId)); copy.getProperties().add(Version.VERSION_2_0); copy.getProperties().add(CalScale.GREGORIAN); copy.getProperties().add(new XProperty(FREE_BUSY_X_PROPERTY, Boolean.TRUE.toString())); ComponentList<CalendarComponent> events = original.getComponents(Component.VEVENT); for (Component event : events) { copy.getComponents().add(getFreeBusyEvent((VEvent) event, freeBusyText)); } return copy; }
Example #12
Source File: TimezoneValidator.java From cosmo with Apache License 2.0 | 6 votes |
public boolean isValid(Calendar value, ConstraintValidatorContext context) { if(value==null) { return true; } try { Calendar calendar = (Calendar) value; // validate entire icalendar object calendar.validate(true); // make sure we have a VTIMEZONE VTimeZone timezone = (VTimeZone) calendar.getComponents() .getComponents(Component.VTIMEZONE).get(0); return timezone != null; } catch(ValidationException ve) { return false; } catch (RuntimeException e) { return false; } }
Example #13
Source File: ICalendarUtils.java From cosmo with Apache License 2.0 | 6 votes |
/** * Find and return the first DISPLAY VALARM in a comoponent * @param component VEVENT or VTODO * @return first DISPLAY VALARM, null if there is none */ public static VAlarm getDisplayAlarm(Component component) { ComponentList<VAlarm> alarms = null; if(component instanceof VEvent) { alarms = ((VEvent) component).getAlarms(); } else if(component instanceof VToDo) { alarms = ((VToDo) component).getAlarms(); } if(alarms==null || alarms.size()==0) { return null; } for(Iterator<VAlarm> it = alarms.iterator();it.hasNext();) { VAlarm alarm = it.next(); if(Action.DISPLAY.equals(alarm.getAction())) { return alarm; } } return null; }
Example #14
Source File: ComponentFilter.java From cosmo with Apache License 2.0 | 6 votes |
private void validateName(Element element) throws ParseException { name = DomUtil.getAttribute(element, ATTR_CALDAV_NAME, null); if (name == null) { throw new ParseException( "CALDAV:comp-filter a calendar component name (e.g., \"VEVENT\") is required", -1); } if (!(name.equals(Calendar.VCALENDAR) || CalendarUtils.isSupportedComponent(name) || name.equals(Component.VALARM) || name.equals(Component.VTIMEZONE))) { throw new ParseException(name + " is not a supported iCalendar component", -1); } }
Example #15
Source File: CalendarFilterEvaluater.java From cosmo with Apache License 2.0 | 6 votes |
/** * Evaluates. * @param comps The component list. * @param filter The time range filter. * @return the result. */ private boolean evaluate(ComponentList<? extends Component> comps, TimeRangeFilter filter) { Component comp = (Component) comps.get(0); if(comp instanceof VEvent) { return evaluateVEventTimeRange(comps, filter); } else if(comp instanceof VFreeBusy) { return evaulateVFreeBusyTimeRange((VFreeBusy) comp, filter); } else if(comp instanceof VToDo) { return evaulateVToDoTimeRange(comps, filter); } else if(comp instanceof VJournal) { return evaluateVJournalTimeRange((VJournal) comp, filter); } else if(comp instanceof VAlarm) { return evaluateVAlarmTimeRange(comps, filter); } else { return false; } }
Example #16
Source File: EntityConverter.java From cosmo with Apache License 2.0 | 6 votes |
/** * Updates note modification. * @param noteMod The note item modified. * @param event The event. */ private void updateNoteModification(NoteItem noteMod, VEvent event) { EventExceptionStamp exceptionStamp = StampUtils.getEventExceptionStamp(noteMod); exceptionStamp.setExceptionEvent(event); // copy VTIMEZONEs to front if present ComponentList<VTimeZone> vtimezones = exceptionStamp.getMasterStamp() .getEventCalendar().getComponents(Component.VTIMEZONE); for(VTimeZone vtimezone : vtimezones) { exceptionStamp.getEventCalendar().getComponents().add(0, vtimezone); } noteMod.setClientModifiedDate(new Date()); noteMod.setLastModifiedBy(noteMod.getModifies().getLastModifiedBy()); noteMod.setLastModification(ContentItem.Action.EDITED); setCalendarAttributes(noteMod, event); }
Example #17
Source File: EntityConverter.java From cosmo with Apache License 2.0 | 6 votes |
/** * Compact timezones. * @param calendar The calendar. */ private void compactTimezones(Calendar calendar) { if (calendar==null) { return; } // Get list of timezones in master calendar and remove all timezone // definitions that are in the registry. The idea is to not store // extra data. Instead, the timezones will be added to the calendar // by the getCalendar() api. ComponentList<VTimeZone> timezones = calendar.getComponents(Component.VTIMEZONE); List<VTimeZone> toRemove = new ArrayList<>(); for(VTimeZone vtz : timezones) { String tzid = vtz.getTimeZoneId().getValue(); TimeZone tz = TIMEZONE_REGISTRY.getTimeZone(tzid); // Remove timezone iff it matches the one in the registry if(tz!=null && vtz.equals(tz.getVTimeZone())) { toRemove.add(vtz); } } // remove known timezones from master calendar calendar.getComponents().removeAll(toRemove); }
Example #18
Source File: ICalendarStore.java From axelor-open-suite with GNU Affero General Public License v3.0 | 6 votes |
public static List<VEvent> getModifiedEvents( CalDavCalendarCollection calendar, Instant instant, Set<String> remoteUids) { final List<VEvent> events = new ArrayList<>(); for (Calendar cal : calendar.getEvents()) { cal.toString(); for (Object item : ((List<CalendarComponent>) cal.getComponents(Component.VEVENT))) { VEvent event = (VEvent) item; if (instant == null || event.getLastModified().getDate().toInstant().isAfter(instant)) { events.add(event); } remoteUids.add(event.getUid().getValue()); } } return events; }
Example #19
Source File: ItemFilterEvaluater.java From cosmo with Apache License 2.0 | 6 votes |
/** * Gets calendar filter. * @param esf event stamp filter. * @return calendar filter. */ private CalendarFilter getCalendarFilter(EventStampFilter esf) { ComponentFilter eventFilter = new ComponentFilter(Component.VEVENT); eventFilter.setTimeRangeFilter(new TimeRangeFilter(esf.getPeriod().getStart(), esf.getPeriod().getEnd())); if (esf.getTimezone() != null) { eventFilter.getTimeRangeFilter().setTimezone(esf.getTimezone().getVTimeZone()); } ComponentFilter calFilter = new ComponentFilter( net.fortuna.ical4j.model.Calendar.VCALENDAR); calFilter.getComponentFilters().add(eventFilter); CalendarFilter filter = new CalendarFilter(); filter.setFilter(calFilter); return filter; }
Example #20
Source File: OutputFilter.java From cosmo with Apache License 2.0 | 6 votes |
/** * Test subcomponent. * @param subcomp The component. * @return The result. */ public boolean testSubComponent(Component subcomp) { if (allSubComponents) { return true; } if (subComponents == null) { return false; } if (subComponents.containsKey(subcomp.getName().toUpperCase(CosmoConstants.LANGUAGE_LOCALE))) { return true; } return false; }
Example #21
Source File: StandardContentService.java From cosmo with Apache License 2.0 | 6 votes |
private void checkDatesForEvent(ContentItem item){ if(!(item instanceof NoteItem)){ return; } NoteItem noteItem = (NoteItem)item; Stamp stamp = noteItem.getStamp("event"); if(!(stamp instanceof EventStamp)){ return; } EventStamp eventStamp = (EventStamp) stamp; VEvent masterEvent = eventStamp.getMasterEvent(); checkDatesForComponent(masterEvent); for(Component component : eventStamp.getExceptions()){ checkDatesForComponent(component); } }
Example #22
Source File: ICalendarService.java From axelor-open-suite with GNU Affero General Public License v3.0 | 6 votes |
/** * Load the calendar events from the given reader. * * @param calendar the target {@link ICalendar} * @param reader the input source reader * @throws IOException * @throws ParserException */ @Transactional(rollbackOn = {Exception.class}) public void load(ICalendar calendar, Reader reader) throws IOException, ParserException { Preconditions.checkNotNull(calendar, "calendar can't be null"); Preconditions.checkNotNull(reader, "reader can't be null"); final CalendarBuilder builder = new CalendarBuilder(); final Calendar cal = builder.build(reader); if (calendar.getName() == null && cal.getProperty(X_WR_CALNAME) != null) { calendar.setName(cal.getProperty(X_WR_CALNAME).getValue()); } for (Object item : cal.getComponents(Component.VEVENT)) { findOrCreateEvent((VEvent) item, calendar); } }
Example #23
Source File: InstanceList.java From cosmo with Apache License 2.0 | 5 votes |
/** * Add a component (either master or override instance) if it falls within * the specified time range. * * @param comp The component. * @param rangeStart The date. * @param rangeEnd The date. */ public void addComponent(Component comp, Date rangeStart, Date rangeEnd) { // See if it contains a recurrence ID if (comp.getProperties().getProperty(Property.RECURRENCE_ID) == null) { addMaster(comp, rangeStart, rangeEnd); } else { addOverride(comp, rangeStart, rangeEnd); } }
Example #24
Source File: MockEventStamp.java From cosmo with Apache License 2.0 | 5 votes |
/** * Gets exceptions. * @return The list with component. */ public List<Component> getExceptions() { ArrayList<Component> exceptions = new ArrayList<Component>(); // add all exception events NoteItem note = (NoteItem) getItem(); for(NoteItem exception : note.getModifications()) { EventExceptionStamp exceptionStamp = MockEventExceptionStamp.getStamp(exception); if (exceptionStamp != null) { exceptions.add(exceptionStamp.getEvent()); } } return exceptions; }
Example #25
Source File: ICalConverter.java From scipio-erp with Apache License 2.0 | 5 votes |
protected static ResponseProperties createWorkEffort(Component component, Map<String, Object> context) { Map<String, Object> serviceMap = new HashMap<>(); setWorkEffortServiceMap(component, serviceMap); serviceMap.put("workEffortTypeId", "VTODO".equals(component.getName()) ? "TASK" : "EVENT"); serviceMap.put("currentStatusId", "VTODO".equals(component.getName()) ? "CAL_NEEDS_ACTION" : "CAL_TENTATIVE"); serviceMap.put("partyId", ((GenericValue) context.get("userLogin")).get("partyId")); serviceMap.put("roleTypeId", "CAL_OWNER"); serviceMap.put("statusId", "PRTYASGN_ASSIGNED"); Map<String, Object> serviceResult = invokeService("createWorkEffortAndPartyAssign", serviceMap, context); if (ServiceUtil.isError(serviceResult)) { return ICalWorker.createPartialContentResponse(ServiceUtil.getErrorMessage(serviceResult)); } String workEffortId = (String) serviceResult.get("workEffortId"); if (workEffortId != null) { replaceProperty(component.getProperties(), toXProperty(workEffortIdXPropName, workEffortId)); serviceMap.clear(); serviceMap.put("workEffortIdFrom", context.get("workEffortId")); serviceMap.put("workEffortIdTo", workEffortId); serviceMap.put("workEffortAssocTypeId", "WORK_EFF_DEPENDENCY"); serviceMap.put("fromDate", new Timestamp(System.currentTimeMillis())); serviceResult = invokeService("createWorkEffortAssoc", serviceMap, context); if (ServiceUtil.isError(serviceResult)) { return ICalWorker.createPartialContentResponse(ServiceUtil.getErrorMessage(serviceResult)); } storePartyAssignments(workEffortId, component, context); } return null; }
Example #26
Source File: HibCalendarCollectionStamp.java From cosmo with Apache License 2.0 | 5 votes |
public TimeZone getTimezone() { Calendar timezone = getTimezoneCalendar(); if (timezone == null) { return null; } VTimeZone vtz = (VTimeZone) timezone.getComponents().getComponent(Component.VTIMEZONE); return new TimeZone(vtz); }
Example #27
Source File: HibCalendarCollectionStamp.java From cosmo with Apache License 2.0 | 5 votes |
public String getTimezoneName() { Calendar timezone = getTimezoneCalendar(); if (timezone == null) { return null; } return timezone.getComponents().getComponent(Component.VTIMEZONE). getProperties().getProperty(Property.TZID).getValue(); }
Example #28
Source File: DavCalendarCollection.java From cosmo with Apache License 2.0 | 5 votes |
/** * @return The default timezone for this calendar collection, if one has been set. */ public VTimeZone getTimeZone() { Calendar obj = getCalendarCollectionStamp().getTimezoneCalendar(); if (obj == null) { return null; } return (VTimeZone) obj.getComponents().getComponent(Component.VTIMEZONE); }
Example #29
Source File: EntityConverter.java From cosmo with Apache License 2.0 | 5 votes |
/** * Update existing NoteItem with calendar containing single VJOURNAL * @param note note to update * @param calendar calendar containing VJOURNAL * @return NoteItem representation of VJOURNAL */ public NoteItem convertJournalCalendar(NoteItem note, Calendar calendar) { VJournal vj = (VJournal) getMasterComponent(calendar.getComponents(Component.VJOURNAL)); setCalendarAttributes(note, vj); return note; }
Example #30
Source File: ICal3ClientFilter.java From cosmo with Apache License 2.0 | 5 votes |
private void fixDateTimeProperties(Component component) { PropertyList<Property> props = component.getProperties(); for(Property prop : props) { if(prop instanceof DateProperty || prop instanceof DateListProperty) { Value v = (Value) prop.getParameter(Parameter.VALUE); if(Value.DATE_TIME.equals(v)) { prop.getParameters().remove(v); } } } }