src/net/fortuna/ical4j/model/component/Available.java

Tue, 10 Feb 2015 19:38:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 10 Feb 2015 19:38:00 +0100
changeset 3
73bdfa70b04e
permissions
-rw-r--r--

Upgrade embedded ical4j from ancient whatever to upstream version 1.0.6.

     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.component;
    34 import net.fortuna.ical4j.model.Component;
    35 import net.fortuna.ical4j.model.Parameter;
    36 import net.fortuna.ical4j.model.Property;
    37 import net.fortuna.ical4j.model.PropertyList;
    38 import net.fortuna.ical4j.model.ValidationException;
    39 import net.fortuna.ical4j.model.parameter.Value;
    40 import net.fortuna.ical4j.model.property.DtEnd;
    41 import net.fortuna.ical4j.model.property.DtStart;
    42 import net.fortuna.ical4j.util.PropertyValidator;
    44 /**
    45  * $Id$ [05-Apr-2004]
    46  *
    47  * Defines an iCalendar Available component.
    48  *
    49  * <pre>
    50  *
    51  *       availablec  = &quot;BEGIN&quot; &quot;:&quot; &quot;AVAILABLE&quot; CRLF
    52  *
    53  *                    availableprop
    54  *
    55  *                    &quot;END&quot; &quot;:&quot; &quot;AVAILABLE&quot; CRLF
    56  *
    57           availableprop  = *(
    59                          ; the following are REQUIRED,
    60                          ; but MUST NOT occur more than once
    62                          dtstamp / dtstart / uid /
    64                          ; either a 'dtend' or a 'duration' is required
    65                          ; in a 'availableprop', but 'dtend' and
    66                          ; 'duration' MUST NOT occur in the same
    67                          ; 'availableprop', and each MUST NOT occur more
    68                          ; than once
    70                          dtend / duration /
    72                          ; the following are OPTIONAL,
    73                          ; but MUST NOT occur more than once
    75                          created / last-mod / recurid / rrule /
    76                          summary /
    78                          ; the following are OPTIONAL,
    79                          ; and MAY occur more than once
    81                          categories / comment / contact / exdate /
    82                          rdate / x-prop
    84                          )
    85  * </pre>
    86  *
    87  * @author Ben Fortuna
    88  * @author Mike Douglass
    89  */
    90 public class Available extends Component {
    92     private static final long serialVersionUID = -2494710612002978763L;
    94     /**
    95      * Default constructor.
    96      */
    97     public Available() {
    98         super(AVAILABLE);
    99     }
   101     /**
   102      * Constructor.
   103      * @param properties a list of properties
   104      */
   105     public Available(final PropertyList properties) {
   106         super(AVAILABLE, properties);
   107     }
   109     /**
   110      * {@inheritDoc}
   111      */
   112     public final void validate(final boolean recurse)
   113             throws ValidationException {
   115         /*
   116          * ; dtstamp / dtstart / uid are required, but MUST NOT occur more than once /
   117          */
   118         PropertyValidator.getInstance().assertOne(Property.DTSTART,
   119                 getProperties());
   120         PropertyValidator.getInstance().assertOne(Property.DTSTAMP,
   121                 getProperties());
   122         PropertyValidator.getInstance().assertOne(Property.UID,
   123                 getProperties());
   125         /*       If specified, the "DTSTART" and "DTEND" properties in
   126          *      "VAVAILABILITY" components and "AVAILABLE" sub-components MUST be
   127          *      "DATE-TIME" values specified as either date with UTC time or date
   128          *      with local time and a time zone reference.
   129          */
   130         final DtStart start = (DtStart) getProperty(Property.DTSTART);
   131         if (Value.DATE.equals(start.getParameter(Parameter.VALUE))) {
   132             throw new ValidationException("Property [" + Property.DTSTART
   133                     + "] must be a " + Value.DATE_TIME);
   134         }
   136         /*
   137          *                ; the following are optional,
   138          *                ; but MUST NOT occur more than once
   139          *
   140          *               created / last-mod / recurid / rrule /
   141          *               summary /
   142          */
   143         PropertyValidator.getInstance().assertOneOrLess(Property.CREATED,
   144                 getProperties());
   145         PropertyValidator.getInstance().assertOneOrLess(Property.LAST_MODIFIED,
   146                 getProperties());
   147         PropertyValidator.getInstance().assertOneOrLess(Property.RECURRENCE_ID,
   148                 getProperties());
   149         PropertyValidator.getInstance().assertOneOrLess(Property.RRULE,
   150                 getProperties());
   151         PropertyValidator.getInstance().assertOneOrLess(Property.SUMMARY,
   152                 getProperties());
   154         /*
   155          ; either a 'dtend' or a 'duration' is required
   156          ; in a 'availableprop', but 'dtend' and
   157          ; 'duration' MUST NOT occur in the same
   158          ; 'availableprop', and each MUST NOT occur more
   159          ; than once
   160          */
   161         if (getProperty(Property.DTEND) != null) {
   162             PropertyValidator.getInstance().assertOne(Property.DTEND,
   163                     getProperties());
   164             /* Must be DATE_TIME */
   165             final DtEnd end = (DtEnd) getProperty(Property.DTEND);
   166             if (Value.DATE.equals(end.getParameter(Parameter.VALUE))) {
   167                 throw new ValidationException("Property [" + Property.DTEND
   168                         + "] must be a " + Value.DATE_TIME);
   169             }
   170         } else {
   171             PropertyValidator.getInstance().assertOne(Property.DURATION,
   172                     getProperties());
   173         }
   175         /*
   176          * ; the following are optional, ; and MAY occur more than once
   177          *               categories / comment / contact / exdate /
   178          *               rdate / x-prop
   179          */
   181         if (recurse) {
   182             validateProperties();
   183         }
   184     }
   185 }

mercurial