src/net/fortuna/ical4j/model/property/RecurrenceId.java

Tue, 10 Feb 2015 18:12:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 10 Feb 2015 18:12:00 +0100
changeset 0
fb9019fb1bf7
permissions
-rw-r--r--

Import initial revisions of existing project AndroidCaldavSyncAdapater,
forked from upstream repository at 27e8a0f8495c92e0780d450bdf0c7cec77a03a55.

     1 /**
     2  * Copyright (c) 2012, Ben Fortuna
     3  * All rights reserved.
     4  *
     5  * Redistribution and use in source and binary forms, with or without
     6  * modification, are permitted provided that the following conditions
     7  * are met:
     8  *
     9  *  o Redistributions of source code must retain the above copyright
    10  * notice, this list of conditions and the following disclaimer.
    11  *
    12  *  o Redistributions in binary form must reproduce the above copyright
    13  * notice, this list of conditions and the following disclaimer in the
    14  * documentation and/or other materials provided with the distribution.
    15  *
    16  *  o Neither the name of Ben Fortuna nor the names of any other contributors
    17  * may be used to endorse or promote products derived from this software
    18  * without specific prior written permission.
    19  *
    20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
    24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
    25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
    26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
    27  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
    28  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
    29  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
    30  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    31  */
    32 package net.fortuna.ical4j.model.property;
    34 import java.text.ParseException;
    36 import net.fortuna.ical4j.model.Date;
    37 import net.fortuna.ical4j.model.DateTime;
    38 import net.fortuna.ical4j.model.Parameter;
    39 import net.fortuna.ical4j.model.ParameterList;
    40 import net.fortuna.ical4j.model.PropertyFactoryImpl;
    41 import net.fortuna.ical4j.model.TimeZone;
    42 import net.fortuna.ical4j.model.ValidationException;
    43 import net.fortuna.ical4j.util.ParameterValidator;
    45 /**
    46  * $Id$
    47  * 
    48  * Created: [Apr 6, 2004]
    49  *
    50  * Defines a RECURRENCE-ID iCalendar component property.
    51  * 
    52  * <pre>
    53  *     4.8.4.4 Recurrence ID
    54  *     
    55  *        Property Name: RECURRENCE-ID
    56  *     
    57  *        Purpose: This property is used in conjunction with the &quot;UID&quot; and
    58  *        &quot;SEQUENCE&quot; property to identify a specific instance of a recurring
    59  *        &quot;VEVENT&quot;, &quot;VTODO&quot; or &quot;VJOURNAL&quot; calendar component. The property
    60  *        value is the effective value of the &quot;DTSTART&quot; property of the
    61  *        recurrence instance.
    62  *     
    63  *        Value Type: The default value type for this property is DATE-TIME.
    64  *        The time format can be any of the valid forms defined for a DATE-TIME
    65  *        value type. See DATE-TIME value type definition for specific
    66  *        interpretations of the various forms. The value type can be set to
    67  *        DATE.
    68  *     
    69  *        Property Parameters: Non-standard property, value data type, time
    70  *        zone identifier and recurrence identifier range parameters can be
    71  *        specified on this property.
    72  *     
    73  *        Conformance: This property can be specified in an iCalendar object
    74  *        containing a recurring calendar component.
    75  *     
    76  *        Description: The full range of calendar components specified by a
    77  *        recurrence set is referenced by referring to just the &quot;UID&quot; property
    78  *        value corresponding to the calendar component. The &quot;RECURRENCE-ID&quot;
    79  *        property allows the reference to an individual instance within the
    80  *        recurrence set.
    81  *     
    82  *        If the value of the &quot;DTSTART&quot; property is a DATE type value, then the
    83  *        value MUST be the calendar date for the recurrence instance.
    84  *     
    85  *        The date/time value is set to the time when the original recurrence
    86  *        instance would occur; meaning that if the intent is to change a
    87  *        Friday meeting to Thursday, the date/time is still set to the
    88  *        original Friday meeting.
    89  *     
    90  *        The &quot;RECURRENCE-ID&quot; property is used in conjunction with the &quot;UID&quot;
    91  *        and &quot;SEQUENCE&quot; property to identify a particular instance of a
    92  *        recurring event, to-do or journal. For a given pair of &quot;UID&quot; and
    93  *        &quot;SEQUENCE&quot; property values, the &quot;RECURRENCE-ID&quot; value for a
    94  *        recurrence instance is fixed. When the definition of the recurrence
    95  *        set for a calendar component changes, and hence the &quot;SEQUENCE&quot;
    96  *        property value changes, the &quot;RECURRENCE-ID&quot; for a given recurrence
    97  *        instance might also change.The &quot;RANGE&quot; parameter is used to specify
    98  *        the effective range of recurrence instances from the instance
    99  *        specified by the &quot;RECURRENCE-ID&quot; property value. The default value
   100  *        for the range parameter is the single recurrence instance only. The
   101  *        value can also be &quot;THISANDPRIOR&quot; to indicate a range defined by the
   102  *        given recurrence instance and all prior instances or the value can be
   103  *        &quot;THISANDFUTURE&quot; to indicate a range defined by the given recurrence
   104  *        instance and all subsequent instances.
   105  *     
   106  *        Format Definition: The property is defined by the following notation:
   107  *     
   108  *          recurid    = &quot;RECURRENCE-ID&quot; ridparam &quot;:&quot; ridval CRLF
   109  *     
   110  *          ridparam   = *(
   111  *     
   112  *                     ; the following are optional,
   113  *                     ; but MUST NOT occur more than once
   114  *     
   115  *                     (&quot;;&quot; &quot;VALUE&quot; &quot;=&quot; (&quot;DATE-TIME&quot; / &quot;DATE)) /
   116  *                     (&quot;;&quot; tzidparam) / (&quot;;&quot; rangeparam) /
   117  *     
   118  *                     ; the following is optional,
   119  *                     ; and MAY occur more than once
   120  *     
   121  *                     (&quot;;&quot; xparam)
   122  *     
   123  *                     )
   124  *     
   125  *          ridval     = date-time / date
   126  *          ;Value MUST match value type
   127  * </pre>
   128  * 
   129  * @author Ben Fortuna
   130  */
   131 public class RecurrenceId extends DateProperty {
   133     private static final long serialVersionUID = 4456883817126011006L;
   135     /**
   136      * Default constructor.
   137      */
   138     public RecurrenceId() {
   139         super(RECURRENCE_ID, PropertyFactoryImpl.getInstance());
   140         setDate(new DateTime());
   141     }
   143     /**
   144      * Creates a new RECURRENCE_ID property initialised with the specified timezone.
   145      * @param timezone initial timezone
   146      */
   147     public RecurrenceId(TimeZone timezone) {
   148         super(RECURRENCE_ID, timezone, PropertyFactoryImpl.getInstance());
   149     }
   151     /**
   152      * Creates a new instance initialised with the parsed value.
   153      * @param value the RECURRENCE_ID value string to parse
   154      * @throws ParseException where the specified string is not a valid RECURRENCE_ID value representation
   155      */
   156     public RecurrenceId(final String value) throws ParseException {
   157         super(RECURRENCE_ID, PropertyFactoryImpl.getInstance());
   158         setValue(value);
   159     }
   161     /**
   162      * Creates a new RECURRENCE_ID property initialised with the specified timezone and value.
   163      * @param value a string representation of a RECURRENCE_ID value
   164      * @param timezone initial timezone
   165      * @throws ParseException where the specified value is not a valid string
   166      * representation
   167      */
   168     public RecurrenceId(String value, TimeZone timezone) throws ParseException {
   169         super(RECURRENCE_ID, timezone, PropertyFactoryImpl.getInstance());
   170         setValue(value);
   171     }
   173     /**
   174      * @param aList a list of parameters for this component
   175      * @param aValue a value string for this component
   176      * @throws ParseException where the specified value string is not a valid date-time/date representation
   177      */
   178     public RecurrenceId(final ParameterList aList, final String aValue)
   179             throws ParseException {
   180         super(RECURRENCE_ID, aList, PropertyFactoryImpl.getInstance());
   181         setValue(aValue);
   182     }
   184     /**
   185      * Constructor. Date or Date-Time format is determined based on the presence of a VALUE parameter.
   186      * @param aDate a date representation of a date or date-time
   187      */
   188     public RecurrenceId(final Date aDate) {
   189         super(RECURRENCE_ID, PropertyFactoryImpl.getInstance());
   190         setDate(aDate);
   191     }
   193     /**
   194      * Constructor. Date or Date-Time format is determined based on the presence of a VALUE parameter.
   195      * @param aList a list of parameters for this component
   196      * @param aDate a date representation of a date or date-time
   197      */
   198     public RecurrenceId(final ParameterList aList, final Date aDate) {
   199         super(RECURRENCE_ID, aList, PropertyFactoryImpl.getInstance());
   200         setDate(aDate);
   201     }
   203     /**
   204      * {@inheritDoc}
   205      */
   206     public final void validate() throws ValidationException {
   207         super.validate();
   209         /*
   210          * ; the following are optional, ; but MUST NOT occur more than once (";" "VALUE" "=" ("DATE-TIME" / "DATE)) /
   211          * (";" tzidparam) / (";" rangeparam) /
   212          */
   214         ParameterValidator.getInstance().assertOneOrLess(Parameter.RANGE,
   215                 getParameters());
   217         /*
   218          * ; the following is optional, ; and MAY occur more than once (";" xparam)
   219          */
   220     }
   221 }

mercurial