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.property; michael@0: michael@0: import java.text.ParseException; michael@0: michael@0: import net.fortuna.ical4j.model.Date; michael@0: import net.fortuna.ical4j.model.DateTime; michael@0: import net.fortuna.ical4j.model.Parameter; michael@0: import net.fortuna.ical4j.model.ParameterList; michael@0: import net.fortuna.ical4j.model.PropertyFactoryImpl; michael@0: import net.fortuna.ical4j.model.TimeZone; michael@0: import net.fortuna.ical4j.model.ValidationException; michael@0: import net.fortuna.ical4j.util.ParameterValidator; michael@0: michael@0: /** michael@0: * $Id$ michael@0: * michael@0: * Created: [Apr 6, 2004] michael@0: * michael@0: * Defines a RECURRENCE-ID iCalendar component property. michael@0: * michael@0: *
michael@0: * 4.8.4.4 Recurrence ID michael@0: * michael@0: * Property Name: RECURRENCE-ID michael@0: * michael@0: * Purpose: This property is used in conjunction with the "UID" and michael@0: * "SEQUENCE" property to identify a specific instance of a recurring michael@0: * "VEVENT", "VTODO" or "VJOURNAL" calendar component. The property michael@0: * value is the effective value of the "DTSTART" property of the michael@0: * recurrence instance. michael@0: * michael@0: * Value Type: The default value type for this property is DATE-TIME. michael@0: * The time format can be any of the valid forms defined for a DATE-TIME michael@0: * value type. See DATE-TIME value type definition for specific michael@0: * interpretations of the various forms. The value type can be set to michael@0: * DATE. michael@0: * michael@0: * Property Parameters: Non-standard property, value data type, time michael@0: * zone identifier and recurrence identifier range parameters can be michael@0: * specified on this property. michael@0: * michael@0: * Conformance: This property can be specified in an iCalendar object michael@0: * containing a recurring calendar component. michael@0: * michael@0: * Description: The full range of calendar components specified by a michael@0: * recurrence set is referenced by referring to just the "UID" property michael@0: * value corresponding to the calendar component. The "RECURRENCE-ID" michael@0: * property allows the reference to an individual instance within the michael@0: * recurrence set. michael@0: * michael@0: * If the value of the "DTSTART" property is a DATE type value, then the michael@0: * value MUST be the calendar date for the recurrence instance. michael@0: * michael@0: * The date/time value is set to the time when the original recurrence michael@0: * instance would occur; meaning that if the intent is to change a michael@0: * Friday meeting to Thursday, the date/time is still set to the michael@0: * original Friday meeting. michael@0: * michael@0: * The "RECURRENCE-ID" property is used in conjunction with the "UID" michael@0: * and "SEQUENCE" property to identify a particular instance of a michael@0: * recurring event, to-do or journal. For a given pair of "UID" and michael@0: * "SEQUENCE" property values, the "RECURRENCE-ID" value for a michael@0: * recurrence instance is fixed. When the definition of the recurrence michael@0: * set for a calendar component changes, and hence the "SEQUENCE" michael@0: * property value changes, the "RECURRENCE-ID" for a given recurrence michael@0: * instance might also change.The "RANGE" parameter is used to specify michael@0: * the effective range of recurrence instances from the instance michael@0: * specified by the "RECURRENCE-ID" property value. The default value michael@0: * for the range parameter is the single recurrence instance only. The michael@0: * value can also be "THISANDPRIOR" to indicate a range defined by the michael@0: * given recurrence instance and all prior instances or the value can be michael@0: * "THISANDFUTURE" to indicate a range defined by the given recurrence michael@0: * instance and all subsequent instances. michael@0: * michael@0: * Format Definition: The property is defined by the following notation: michael@0: * michael@0: * recurid = "RECURRENCE-ID" ridparam ":" ridval CRLF michael@0: * michael@0: * ridparam = *( michael@0: * michael@0: * ; the following are optional, michael@0: * ; but MUST NOT occur more than once michael@0: * michael@0: * (";" "VALUE" "=" ("DATE-TIME" / "DATE)) / michael@0: * (";" tzidparam) / (";" rangeparam) / michael@0: * michael@0: * ; the following is optional, michael@0: * ; and MAY occur more than once michael@0: * michael@0: * (";" xparam) michael@0: * michael@0: * ) michael@0: * michael@0: * ridval = date-time / date michael@0: * ;Value MUST match value type michael@0: *michael@0: * michael@0: * @author Ben Fortuna michael@0: */ michael@0: public class RecurrenceId extends DateProperty { michael@0: michael@0: private static final long serialVersionUID = 4456883817126011006L; michael@0: michael@0: /** michael@0: * Default constructor. michael@0: */ michael@0: public RecurrenceId() { michael@0: super(RECURRENCE_ID, PropertyFactoryImpl.getInstance()); michael@0: setDate(new DateTime()); michael@0: } michael@0: michael@0: /** michael@0: * Creates a new RECURRENCE_ID property initialised with the specified timezone. michael@0: * @param timezone initial timezone michael@0: */ michael@0: public RecurrenceId(TimeZone timezone) { michael@0: super(RECURRENCE_ID, timezone, PropertyFactoryImpl.getInstance()); michael@0: } michael@0: michael@0: /** michael@0: * Creates a new instance initialised with the parsed value. michael@0: * @param value the RECURRENCE_ID value string to parse michael@0: * @throws ParseException where the specified string is not a valid RECURRENCE_ID value representation michael@0: */ michael@0: public RecurrenceId(final String value) throws ParseException { michael@0: super(RECURRENCE_ID, PropertyFactoryImpl.getInstance()); michael@0: setValue(value); michael@0: } michael@0: michael@0: /** michael@0: * Creates a new RECURRENCE_ID property initialised with the specified timezone and value. michael@0: * @param value a string representation of a RECURRENCE_ID value michael@0: * @param timezone initial timezone michael@0: * @throws ParseException where the specified value is not a valid string michael@0: * representation michael@0: */ michael@0: public RecurrenceId(String value, TimeZone timezone) throws ParseException { michael@0: super(RECURRENCE_ID, timezone, PropertyFactoryImpl.getInstance()); michael@0: setValue(value); michael@0: } michael@0: michael@0: /** michael@0: * @param aList a list of parameters for this component michael@0: * @param aValue a value string for this component michael@0: * @throws ParseException where the specified value string is not a valid date-time/date representation michael@0: */ michael@0: public RecurrenceId(final ParameterList aList, final String aValue) michael@0: throws ParseException { michael@0: super(RECURRENCE_ID, aList, PropertyFactoryImpl.getInstance()); michael@0: setValue(aValue); michael@0: } michael@0: michael@0: /** michael@0: * Constructor. Date or Date-Time format is determined based on the presence of a VALUE parameter. michael@0: * @param aDate a date representation of a date or date-time michael@0: */ michael@0: public RecurrenceId(final Date aDate) { michael@0: super(RECURRENCE_ID, PropertyFactoryImpl.getInstance()); michael@0: setDate(aDate); michael@0: } michael@0: michael@0: /** michael@0: * Constructor. Date or Date-Time format is determined based on the presence of a VALUE parameter. michael@0: * @param aList a list of parameters for this component michael@0: * @param aDate a date representation of a date or date-time michael@0: */ michael@0: public RecurrenceId(final ParameterList aList, final Date aDate) { michael@0: super(RECURRENCE_ID, aList, PropertyFactoryImpl.getInstance()); michael@0: setDate(aDate); michael@0: } michael@0: michael@0: /** michael@0: * {@inheritDoc} michael@0: */ michael@0: public final void validate() throws ValidationException { michael@0: super.validate(); michael@0: michael@0: /* michael@0: * ; the following are optional, ; but MUST NOT occur more than once (";" "VALUE" "=" ("DATE-TIME" / "DATE)) / michael@0: * (";" tzidparam) / (";" rangeparam) / michael@0: */ michael@0: michael@0: ParameterValidator.getInstance().assertOneOrLess(Parameter.RANGE, michael@0: getParameters()); michael@0: michael@0: /* michael@0: * ; the following is optional, ; and MAY occur more than once (";" xparam) michael@0: */ michael@0: } michael@0: }