michael@0: /** michael@0: * Copyright (c) 2012, Ben Fortuna michael@0: * All rights reserved. michael@0: * michael@0: * Redistribution and use in source and binary forms, with or without michael@0: * modification, are permitted provided that the following conditions michael@0: * are met: michael@0: * michael@0: * o Redistributions of source code must retain the above copyright michael@0: * notice, this list of conditions and the following disclaimer. michael@0: * michael@0: * o Redistributions in binary form must reproduce the above copyright michael@0: * notice, this list of conditions and the following disclaimer in the michael@0: * documentation and/or other materials provided with the distribution. michael@0: * michael@0: * o Neither the name of Ben Fortuna nor the names of any other contributors michael@0: * may be used to endorse or promote products derived from this software michael@0: * without specific prior written permission. michael@0: * michael@0: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS michael@0: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT michael@0: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR michael@0: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR michael@0: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, michael@0: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, michael@0: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR michael@0: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF michael@0: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING michael@0: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS michael@0: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. michael@0: */ michael@0: package net.fortuna.ical4j.model.component; michael@0: michael@0: import net.fortuna.ical4j.model.Component; michael@0: import net.fortuna.ical4j.model.Parameter; michael@0: import net.fortuna.ical4j.model.Property; michael@0: import net.fortuna.ical4j.model.PropertyList; michael@0: import net.fortuna.ical4j.model.ValidationException; michael@0: import net.fortuna.ical4j.model.parameter.Value; michael@0: import net.fortuna.ical4j.model.property.DtEnd; michael@0: import net.fortuna.ical4j.model.property.DtStart; michael@0: import net.fortuna.ical4j.util.PropertyValidator; michael@0: michael@0: /** michael@0: * $Id$ [05-Apr-2004] michael@0: * michael@0: * Defines an iCalendar Available component. michael@0: * michael@0: *
michael@0: * michael@0: * availablec = "BEGIN" ":" "AVAILABLE" CRLF michael@0: * michael@0: * availableprop michael@0: * michael@0: * "END" ":" "AVAILABLE" CRLF michael@0: * michael@0: availableprop = *( michael@0: michael@0: ; the following are REQUIRED, michael@0: ; but MUST NOT occur more than once michael@0: michael@0: dtstamp / dtstart / uid / michael@0: michael@0: ; either a 'dtend' or a 'duration' is required michael@0: ; in a 'availableprop', but 'dtend' and michael@0: ; 'duration' MUST NOT occur in the same michael@0: ; 'availableprop', and each MUST NOT occur more michael@0: ; than once michael@0: michael@0: dtend / duration / michael@0: michael@0: ; the following are OPTIONAL, michael@0: ; but MUST NOT occur more than once michael@0: michael@0: created / last-mod / recurid / rrule / michael@0: summary / michael@0: michael@0: ; the following are OPTIONAL, michael@0: ; and MAY occur more than once michael@0: michael@0: categories / comment / contact / exdate / michael@0: rdate / x-prop michael@0: michael@0: ) michael@0: *michael@0: * michael@0: * @author Ben Fortuna michael@0: * @author Mike Douglass michael@0: */ michael@0: public class Available extends Component { michael@0: michael@0: private static final long serialVersionUID = -2494710612002978763L; michael@0: michael@0: /** michael@0: * Default constructor. michael@0: */ michael@0: public Available() { michael@0: super(AVAILABLE); michael@0: } michael@0: michael@0: /** michael@0: * Constructor. michael@0: * @param properties a list of properties michael@0: */ michael@0: public Available(final PropertyList properties) { michael@0: super(AVAILABLE, properties); michael@0: } michael@0: michael@0: /** michael@0: * {@inheritDoc} michael@0: */ michael@0: public final void validate(final boolean recurse) michael@0: throws ValidationException { michael@0: michael@0: /* michael@0: * ; dtstamp / dtstart / uid are required, but MUST NOT occur more than once / michael@0: */ michael@0: PropertyValidator.getInstance().assertOne(Property.DTSTART, michael@0: getProperties()); michael@0: PropertyValidator.getInstance().assertOne(Property.DTSTAMP, michael@0: getProperties()); michael@0: PropertyValidator.getInstance().assertOne(Property.UID, michael@0: getProperties()); michael@0: michael@0: /* If specified, the "DTSTART" and "DTEND" properties in michael@0: * "VAVAILABILITY" components and "AVAILABLE" sub-components MUST be michael@0: * "DATE-TIME" values specified as either date with UTC time or date michael@0: * with local time and a time zone reference. michael@0: */ michael@0: final DtStart start = (DtStart) getProperty(Property.DTSTART); michael@0: if (Value.DATE.equals(start.getParameter(Parameter.VALUE))) { michael@0: throw new ValidationException("Property [" + Property.DTSTART michael@0: + "] must be a " + Value.DATE_TIME); michael@0: } michael@0: michael@0: /* michael@0: * ; the following are optional, michael@0: * ; but MUST NOT occur more than once michael@0: * michael@0: * created / last-mod / recurid / rrule / michael@0: * summary / michael@0: */ michael@0: PropertyValidator.getInstance().assertOneOrLess(Property.CREATED, michael@0: getProperties()); michael@0: PropertyValidator.getInstance().assertOneOrLess(Property.LAST_MODIFIED, michael@0: getProperties()); michael@0: PropertyValidator.getInstance().assertOneOrLess(Property.RECURRENCE_ID, michael@0: getProperties()); michael@0: PropertyValidator.getInstance().assertOneOrLess(Property.RRULE, michael@0: getProperties()); michael@0: PropertyValidator.getInstance().assertOneOrLess(Property.SUMMARY, michael@0: getProperties()); michael@0: michael@0: /* michael@0: ; either a 'dtend' or a 'duration' is required michael@0: ; in a 'availableprop', but 'dtend' and michael@0: ; 'duration' MUST NOT occur in the same michael@0: ; 'availableprop', and each MUST NOT occur more michael@0: ; than once michael@0: */ michael@0: if (getProperty(Property.DTEND) != null) { michael@0: PropertyValidator.getInstance().assertOne(Property.DTEND, michael@0: getProperties()); michael@0: /* Must be DATE_TIME */ michael@0: final DtEnd end = (DtEnd) getProperty(Property.DTEND); michael@0: if (Value.DATE.equals(end.getParameter(Parameter.VALUE))) { michael@0: throw new ValidationException("Property [" + Property.DTEND michael@0: + "] must be a " + Value.DATE_TIME); michael@0: } michael@0: } else { michael@0: PropertyValidator.getInstance().assertOne(Property.DURATION, michael@0: getProperties()); michael@0: } michael@0: michael@0: /* michael@0: * ; the following are optional, ; and MAY occur more than once michael@0: * categories / comment / contact / exdate / michael@0: * rdate / x-prop michael@0: */ michael@0: michael@0: if (recurse) { michael@0: validateProperties(); michael@0: } michael@0: } michael@0: }