@Parameters public static Collection<Object[]> parameters() throws IOException, ParserException { VCardOutputter outputter = new VCardOutputter(false, 1000); VCardBuilder builder = null; List<Object[]> params = new ArrayList<Object[]>(); File[] testFiles = new File("src/test/resources/samples/valid") .listFiles((FileFilter) VCardFileFilter.INSTANCE); // enable relaxed parsing for non-standard GEO support.. CompatibilityHints.setHintEnabled(CompatibilityHints.KEY_RELAXED_PARSING, true); for (int i = 0; i < testFiles.length; i++) { builder = new VCardBuilder(new FileReader(testFiles[i])); VCard card = builder.build(); params.add(new Object[] {outputter, card, card.toString()}); } CompatibilityHints.setHintEnabled(CompatibilityHints.KEY_RELAXED_PARSING, false); return params; }
@Inject public Export2iCalConverter( TimeZoneConverter timezoneConverter, RaplaLocale raplaLocale, Logger logger, ClientFacade facade) throws RaplaException { this.timezoneConverter = timezoneConverter; this.facade = facade; this.raplaLocale = raplaLocale; this.logger = logger; TimeZone zone = timezoneConverter.getImportExportTimeZone(); calendar = raplaLocale.createCalendar(); DynamicType[] dynamicTypes = facade.getDynamicTypes(DynamicTypeAnnotations.VALUE_CLASSIFICATION_TYPE_RESOURCE); for (DynamicType type : dynamicTypes) { if (type.getAnnotation(DynamicTypeAnnotations.KEY_LOCATION) != null) { hasLocationType = true; } } CompatibilityHints.setHintEnabled(CompatibilityHints.KEY_RELAXED_VALIDATION, true); RaplaConfiguration config = facade .getSystemPreferences() .getEntry(Export2iCalPlugin.ICAL_CONFIG, new RaplaConfiguration()); global_export_attendees = config .getChild(Export2iCalPlugin.EXPORT_ATTENDEES) .getValueAsBoolean(Export2iCalPlugin.DEFAULT_exportAttendees); global_export_attendees_participation_status = config .getChild(Export2iCalPlugin.EXPORT_ATTENDEES_PARTICIPATION_STATUS) .getValue(Export2iCalPlugin.DEFAULT_attendee_participation_status); try { exportAttendeesAttribute = config.getChild(Export2iCalPlugin.EXPORT_ATTENDEES_EMAIL_ATTRIBUTE).getValue(); } catch (ConfigurationException e) { exportAttendeesAttribute = ""; getLogger().info("ExportAttendeesMailAttribute is not set. So do not export as meeting"); } if (zone != null) { final String timezoneId = zone.getID(); try { TimeZoneRegistry registry = TimeZoneRegistryFactory.getInstance().createRegistry(); timeZone = registry.getTimeZone(timezoneId); } catch (Exception rc) { final VTimeZone vTimeZone = new VTimeZone(); timeZone = new net.fortuna.ical4j.model.TimeZone(vTimeZone); final int rawOffset = zone.getRawOffset(); timeZone.setRawOffset(rawOffset); } } }
/** * Constructor. * * @param aString a string representation of a day list */ public WeekDayList(final String aString) { final boolean outlookCompatibility = CompatibilityHints.isHintEnabled(CompatibilityHints.KEY_OUTLOOK_COMPATIBILITY); final StringTokenizer t = new StringTokenizer(aString, ","); while (t.hasMoreTokens()) { if (outlookCompatibility) { add(new WeekDay(t.nextToken().replaceAll(" ", ""))); } else { add(new WeekDay(t.nextToken())); } } }
/* * (non-Javadoc) * @see net.fortuna.ical4j.model.Component#validate(boolean) */ public final void validate(final boolean recurse) throws ValidationException { if (!CompatibilityHints.isHintEnabled(CompatibilityHints.KEY_RELAXED_VALIDATION)) { // From "4.8.4.7 Unique Identifier": // Conformance: The property MUST be specified in the "VEVENT", "VTODO", // "VJOURNAL" or "VFREEBUSY" calendar components. PropertyValidator.getInstance().assertOne(Property.UID, getProperties()); // From "4.8.7.2 Date/Time Stamp": // Conformance: This property MUST be included in the "VEVENT", "VTODO", // "VJOURNAL" or "VFREEBUSY" calendar components. PropertyValidator.getInstance().assertOne(Property.DTSTAMP, getProperties()); } /* * ; the following are optional, ; but MUST NOT occur more than once class / created / description / dtstart / * dtstamp / last-mod / organizer / recurid / seq / status / summary / uid / url / */ PropertyValidator.getInstance().assertOneOrLess(Property.CLASS, getProperties()); PropertyValidator.getInstance().assertOneOrLess(Property.CREATED, getProperties()); PropertyValidator.getInstance().assertOneOrLess(Property.DESCRIPTION, getProperties()); PropertyValidator.getInstance().assertOneOrLess(Property.DTSTART, getProperties()); PropertyValidator.getInstance().assertOneOrLess(Property.DTSTAMP, getProperties()); PropertyValidator.getInstance().assertOneOrLess(Property.LAST_MODIFIED, getProperties()); PropertyValidator.getInstance().assertOneOrLess(Property.ORGANIZER, getProperties()); PropertyValidator.getInstance().assertOneOrLess(Property.RECURRENCE_ID, getProperties()); PropertyValidator.getInstance().assertOneOrLess(Property.SEQUENCE, getProperties()); PropertyValidator.getInstance().assertOneOrLess(Property.STATUS, getProperties()); PropertyValidator.getInstance().assertOneOrLess(Property.SUMMARY, getProperties()); PropertyValidator.getInstance().assertOneOrLess(Property.UID, getProperties()); PropertyValidator.getInstance().assertOneOrLess(Property.URL, getProperties()); Status status = (Status) getProperty(Property.STATUS); if (status != null && !Status.VJOURNAL_DRAFT.equals(status) && !Status.VJOURNAL_FINAL.equals(status) && !Status.VJOURNAL_CANCELLED.equals(status)) { throw new ValidationException( "Status property [" + status.toString() + "] may not occur in VJOURNAL"); } /* * ; the following are optional, ; and MAY occur more than once attach / attendee / categories / comment / * contact / exdate / exrule / related / rdate / rrule / rstatus / x-prop */ if (recurse) { validateProperties(); } }
@After public void tearDown() { CompatibilityHints.setHintEnabled(CompatibilityHints.KEY_RELAXED_PARSING, false); }
@Before public void setUp() { CompatibilityHints.setHintEnabled(CompatibilityHints.KEY_RELAXED_PARSING, true); }
/** * Perform validation on the calendar in its current state. * * @param recurse indicates whether to validate the calendar's properties and components * @throws ValidationException where the calendar is not in a valid state */ public void validate(final boolean recurse) throws ValidationException { // 'prodid' and 'version' are both REQUIRED, // but MUST NOT occur more than once PropertyValidator.getInstance().assertOne(Property.PRODID, properties); PropertyValidator.getInstance().assertOne(Property.VERSION, properties); if (!CompatibilityHints.isHintEnabled(CompatibilityHints.KEY_RELAXED_VALIDATION)) { // require VERSION:2.0 for RFC2445.. if (!Version.VERSION_2_0.equals(getProperty(Property.VERSION))) { throw new ValidationException( "Unsupported Version: " + getProperty(Property.VERSION).getValue()); } } // 'calscale' and 'method' are optional, // but MUST NOT occur more than once PropertyValidator.getInstance().assertOneOrLess(Property.CALSCALE, properties); PropertyValidator.getInstance().assertOneOrLess(Property.METHOD, properties); // must contain at least one component if (getComponents().isEmpty()) { throw new ValidationException("Calendar must contain at least one component"); } // validate properties.. for (final Property property : getProperties()) { if (!(property instanceof XProperty) && !property.isCalendarProperty()) { throw new ValidationException("Invalid property: " + property.getName()); } } // if (!CompatibilityHints.isHintEnabled(CompatibilityHints.KEY_RELAXED_VALIDATION)) { // validate method.. final Method method = (Method) getProperty(Property.METHOD); if (Method.PUBLISH.equals(method)) { if (getComponent(Component.VEVENT) != null) { ComponentValidator.assertNone(Component.VFREEBUSY, getComponents()); ComponentValidator.assertNone(Component.VJOURNAL, getComponents()); if (!CompatibilityHints.isHintEnabled(CompatibilityHints.KEY_RELAXED_VALIDATION)) { ComponentValidator.assertNone(Component.VTODO, getComponents()); } } else if (getComponent(Component.VFREEBUSY) != null) { ComponentValidator.assertNone(Component.VTODO, getComponents()); ComponentValidator.assertNone(Component.VJOURNAL, getComponents()); ComponentValidator.assertNone(Component.VTIMEZONE, getComponents()); ComponentValidator.assertNone(Component.VALARM, getComponents()); } else if (getComponent(Component.VTODO) != null) { // ComponentValidator.assertNone(Component.VFREEBUSY, getComponents()); // ComponentValidator.assertNone(Component.VEVENT, getComponents()); ComponentValidator.assertNone(Component.VJOURNAL, getComponents()); } // else if (getComponent(Component.VJOURNAL) != null) { // ComponentValidator.assertNone(Component.VFREEBUSY, getComponents()); // ComponentValidator.assertNone(Component.VEVENT, getComponents()); // ComponentValidator.assertNone(Component.VTODO, getComponents()); // } } else if (Method.REQUEST.equals(getProperty(Property.METHOD))) { if (getComponent(Component.VEVENT) != null) { ComponentValidator.assertNone(Component.VFREEBUSY, getComponents()); ComponentValidator.assertNone(Component.VJOURNAL, getComponents()); ComponentValidator.assertNone(Component.VTODO, getComponents()); } else if (getComponent(Component.VFREEBUSY) != null) { ComponentValidator.assertNone(Component.VTODO, getComponents()); ComponentValidator.assertNone(Component.VJOURNAL, getComponents()); ComponentValidator.assertNone(Component.VTIMEZONE, getComponents()); ComponentValidator.assertNone(Component.VALARM, getComponents()); } else if (getComponent(Component.VTODO) != null) { // ComponentValidator.assertNone(Component.VFREEBUSY, getComponents()); // ComponentValidator.assertNone(Component.VEVENT, getComponents()); ComponentValidator.assertNone(Component.VJOURNAL, getComponents()); } } else if (Method.REPLY.equals(getProperty(Property.METHOD))) { if (getComponent(Component.VEVENT) != null) { ComponentValidator.assertOneOrLess(Component.VTIMEZONE, getComponents()); ComponentValidator.assertNone(Component.VALARM, getComponents()); ComponentValidator.assertNone(Component.VFREEBUSY, getComponents()); ComponentValidator.assertNone(Component.VJOURNAL, getComponents()); ComponentValidator.assertNone(Component.VTODO, getComponents()); } else if (getComponent(Component.VFREEBUSY) != null) { ComponentValidator.assertNone(Component.VTODO, getComponents()); ComponentValidator.assertNone(Component.VJOURNAL, getComponents()); ComponentValidator.assertNone(Component.VTIMEZONE, getComponents()); ComponentValidator.assertNone(Component.VALARM, getComponents()); } else if (getComponent(Component.VTODO) != null) { ComponentValidator.assertOneOrLess(Component.VTIMEZONE, getComponents()); ComponentValidator.assertNone(Component.VALARM, getComponents()); // ComponentValidator.assertNone(Component.VFREEBUSY, getComponents()); // ComponentValidator.assertNone(Component.VEVENT, getComponents()); ComponentValidator.assertNone(Component.VJOURNAL, getComponents()); } } else if (Method.ADD.equals(getProperty(Property.METHOD))) { if (getComponent(Component.VEVENT) != null) { ComponentValidator.assertNone(Component.VFREEBUSY, getComponents()); ComponentValidator.assertNone(Component.VJOURNAL, getComponents()); ComponentValidator.assertNone(Component.VTODO, getComponents()); } else if (getComponent(Component.VTODO) != null) { ComponentValidator.assertNone(Component.VFREEBUSY, getComponents()); // ComponentValidator.assertNone(Component.VEVENT, getComponents()); ComponentValidator.assertNone(Component.VJOURNAL, getComponents()); } else if (getComponent(Component.VJOURNAL) != null) { ComponentValidator.assertOneOrLess(Component.VTIMEZONE, getComponents()); ComponentValidator.assertNone(Component.VFREEBUSY, getComponents()); // ComponentValidator.assertNone(Component.VEVENT, getComponents()); // ComponentValidator.assertNone(Component.VTODO, getComponents()); } } else if (Method.CANCEL.equals(getProperty(Property.METHOD))) { if (getComponent(Component.VEVENT) != null) { ComponentValidator.assertNone(Component.VALARM, getComponents()); ComponentValidator.assertNone(Component.VFREEBUSY, getComponents()); ComponentValidator.assertNone(Component.VJOURNAL, getComponents()); ComponentValidator.assertNone(Component.VTODO, getComponents()); } else if (getComponent(Component.VTODO) != null) { ComponentValidator.assertOneOrLess(Component.VTIMEZONE, getComponents()); ComponentValidator.assertNone(Component.VALARM, getComponents()); ComponentValidator.assertNone(Component.VFREEBUSY, getComponents()); // ComponentValidator.assertNone(Component.VEVENT, getComponents()); ComponentValidator.assertNone(Component.VJOURNAL, getComponents()); } else if (getComponent(Component.VJOURNAL) != null) { ComponentValidator.assertNone(Component.VALARM, getComponents()); ComponentValidator.assertNone(Component.VFREEBUSY, getComponents()); // ComponentValidator.assertNone(Component.VEVENT, getComponents()); // ComponentValidator.assertNone(Component.VTODO, getComponents()); } } else if (Method.REFRESH.equals(getProperty(Property.METHOD))) { if (getComponent(Component.VEVENT) != null) { ComponentValidator.assertNone(Component.VALARM, getComponents()); ComponentValidator.assertNone(Component.VFREEBUSY, getComponents()); ComponentValidator.assertNone(Component.VJOURNAL, getComponents()); ComponentValidator.assertNone(Component.VTODO, getComponents()); } else if (getComponent(Component.VTODO) != null) { ComponentValidator.assertNone(Component.VALARM, getComponents()); ComponentValidator.assertNone(Component.VFREEBUSY, getComponents()); // ComponentValidator.assertNone(Component.VEVENT, getComponents()); ComponentValidator.assertNone(Component.VJOURNAL, getComponents()); ComponentValidator.assertNone(Component.VTIMEZONE, getComponents()); } } else if (Method.COUNTER.equals(getProperty(Property.METHOD))) { if (getComponent(Component.VEVENT) != null) { ComponentValidator.assertNone(Component.VFREEBUSY, getComponents()); ComponentValidator.assertNone(Component.VJOURNAL, getComponents()); ComponentValidator.assertNone(Component.VTODO, getComponents()); } else if (getComponent(Component.VTODO) != null) { ComponentValidator.assertOneOrLess(Component.VTIMEZONE, getComponents()); ComponentValidator.assertNone(Component.VFREEBUSY, getComponents()); // ComponentValidator.assertNone(Component.VEVENT, getComponents()); ComponentValidator.assertNone(Component.VJOURNAL, getComponents()); } } else if (Method.DECLINE_COUNTER.equals(getProperty(Property.METHOD))) { if (getComponent(Component.VEVENT) != null) { ComponentValidator.assertNone(Component.VFREEBUSY, getComponents()); ComponentValidator.assertNone(Component.VJOURNAL, getComponents()); ComponentValidator.assertNone(Component.VTODO, getComponents()); ComponentValidator.assertNone(Component.VTIMEZONE, getComponents()); ComponentValidator.assertNone(Component.VALARM, getComponents()); } else if (getComponent(Component.VTODO) != null) { ComponentValidator.assertNone(Component.VALARM, getComponents()); ComponentValidator.assertNone(Component.VFREEBUSY, getComponents()); // ComponentValidator.assertNone(Component.VEVENT, getComponents()); ComponentValidator.assertNone(Component.VJOURNAL, getComponents()); } } // } // perform ITIP validation on components.. if (method != null) { for (CalendarComponent component : getComponents()) { component.validate(method); } } if (recurse) { validateProperties(); validateComponents(); } }
/* * (non-Javadoc) * @see net.fortuna.ical4j.model.Component#validate(boolean) */ public final void validate(final boolean recurse) throws ValidationException { // validate that getAlarms() only contains VAlarm components Iterator iterator = getAlarms().iterator(); while (iterator.hasNext()) { Component component = (Component) iterator.next(); if (!(component instanceof VAlarm)) { throw new ValidationException( "Component [" + component.getName() + "] may not occur in VTODO"); } ((VAlarm) component).validate(recurse); } if (!CompatibilityHints.isHintEnabled(CompatibilityHints.KEY_RELAXED_VALIDATION)) { // From "4.8.4.7 Unique Identifier": // Conformance: The property MUST be specified in the "VEVENT", "VTODO", // "VJOURNAL" or "VFREEBUSY" calendar components. PropertyValidator.getInstance().assertOne(Property.UID, getProperties()); // From "4.8.7.2 Date/Time Stamp": // Conformance: This property MUST be included in the "VEVENT", "VTODO", // "VJOURNAL" or "VFREEBUSY" calendar components. PropertyValidator.getInstance().assertOne(Property.DTSTAMP, getProperties()); } /* * ; the following are optional, ; but MUST NOT occur more than once class / completed / created / description / * dtstamp / dtstart / geo / last-mod / location / organizer / percent / priority / recurid / seq / status / * summary / uid / url / */ PropertyValidator.getInstance().assertOneOrLess(Property.CLASS, getProperties()); PropertyValidator.getInstance().assertOneOrLess(Property.COMPLETED, getProperties()); PropertyValidator.getInstance().assertOneOrLess(Property.CREATED, getProperties()); PropertyValidator.getInstance().assertOneOrLess(Property.DESCRIPTION, getProperties()); PropertyValidator.getInstance().assertOneOrLess(Property.DTSTAMP, getProperties()); PropertyValidator.getInstance().assertOneOrLess(Property.DTSTART, getProperties()); PropertyValidator.getInstance().assertOneOrLess(Property.GEO, getProperties()); PropertyValidator.getInstance().assertOneOrLess(Property.LAST_MODIFIED, getProperties()); PropertyValidator.getInstance().assertOneOrLess(Property.LOCATION, getProperties()); PropertyValidator.getInstance().assertOneOrLess(Property.ORGANIZER, getProperties()); PropertyValidator.getInstance().assertOneOrLess(Property.PERCENT_COMPLETE, getProperties()); PropertyValidator.getInstance().assertOneOrLess(Property.PRIORITY, getProperties()); PropertyValidator.getInstance().assertOneOrLess(Property.RECURRENCE_ID, getProperties()); PropertyValidator.getInstance().assertOneOrLess(Property.SEQUENCE, getProperties()); PropertyValidator.getInstance().assertOneOrLess(Property.STATUS, getProperties()); PropertyValidator.getInstance().assertOneOrLess(Property.SUMMARY, getProperties()); PropertyValidator.getInstance().assertOneOrLess(Property.UID, getProperties()); PropertyValidator.getInstance().assertOneOrLess(Property.URL, getProperties()); Status status = (Status) getProperty(Property.STATUS); if (status != null && !Status.VTODO_NEEDS_ACTION.equals(status) && !Status.VTODO_COMPLETED.equals(status) && !Status.VTODO_IN_PROCESS.equals(status) && !Status.VTODO_CANCELLED.equals(status)) { throw new ValidationException( "Status property [" + status.toString() + "] may not occur in VTODO"); } /* * ; either 'due' or 'duration' may appear in ; a 'todoprop', but 'due' and 'duration' ; MUST NOT occur in the * same 'todoprop' due / duration / */ try { PropertyValidator.getInstance().assertNone(Property.DUE, getProperties()); } catch (ValidationException ve) { PropertyValidator.getInstance().assertNone(Property.DURATION, getProperties()); } /* * ; the following are optional, ; and MAY occur more than once attach / attendee / categories / comment / * contact / exdate / exrule / rstatus / related / resources / rdate / rrule / x-prop */ if (recurse) { validateProperties(); } }