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.

michael@0 1 /**
michael@0 2 * Copyright (c) 2012, Ben Fortuna
michael@0 3 * All rights reserved.
michael@0 4 *
michael@0 5 * Redistribution and use in source and binary forms, with or without
michael@0 6 * modification, are permitted provided that the following conditions
michael@0 7 * are met:
michael@0 8 *
michael@0 9 * o Redistributions of source code must retain the above copyright
michael@0 10 * notice, this list of conditions and the following disclaimer.
michael@0 11 *
michael@0 12 * o Redistributions in binary form must reproduce the above copyright
michael@0 13 * notice, this list of conditions and the following disclaimer in the
michael@0 14 * documentation and/or other materials provided with the distribution.
michael@0 15 *
michael@0 16 * o Neither the name of Ben Fortuna nor the names of any other contributors
michael@0 17 * may be used to endorse or promote products derived from this software
michael@0 18 * without specific prior written permission.
michael@0 19 *
michael@0 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
michael@0 21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
michael@0 22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
michael@0 23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
michael@0 24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
michael@0 25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
michael@0 26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
michael@0 27 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
michael@0 28 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
michael@0 29 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
michael@0 30 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
michael@0 31 */
michael@0 32 package net.fortuna.ical4j.model.component;
michael@0 33
michael@0 34 import net.fortuna.ical4j.model.Component;
michael@0 35 import net.fortuna.ical4j.model.Parameter;
michael@0 36 import net.fortuna.ical4j.model.Property;
michael@0 37 import net.fortuna.ical4j.model.PropertyList;
michael@0 38 import net.fortuna.ical4j.model.ValidationException;
michael@0 39 import net.fortuna.ical4j.model.parameter.Value;
michael@0 40 import net.fortuna.ical4j.model.property.DtEnd;
michael@0 41 import net.fortuna.ical4j.model.property.DtStart;
michael@0 42 import net.fortuna.ical4j.util.PropertyValidator;
michael@0 43
michael@0 44 /**
michael@0 45 * $Id$ [05-Apr-2004]
michael@0 46 *
michael@0 47 * Defines an iCalendar Available component.
michael@0 48 *
michael@0 49 * <pre>
michael@0 50 *
michael@0 51 * availablec = &quot;BEGIN&quot; &quot;:&quot; &quot;AVAILABLE&quot; CRLF
michael@0 52 *
michael@0 53 * availableprop
michael@0 54 *
michael@0 55 * &quot;END&quot; &quot;:&quot; &quot;AVAILABLE&quot; CRLF
michael@0 56 *
michael@0 57 availableprop = *(
michael@0 58
michael@0 59 ; the following are REQUIRED,
michael@0 60 ; but MUST NOT occur more than once
michael@0 61
michael@0 62 dtstamp / dtstart / uid /
michael@0 63
michael@0 64 ; either a 'dtend' or a 'duration' is required
michael@0 65 ; in a 'availableprop', but 'dtend' and
michael@0 66 ; 'duration' MUST NOT occur in the same
michael@0 67 ; 'availableprop', and each MUST NOT occur more
michael@0 68 ; than once
michael@0 69
michael@0 70 dtend / duration /
michael@0 71
michael@0 72 ; the following are OPTIONAL,
michael@0 73 ; but MUST NOT occur more than once
michael@0 74
michael@0 75 created / last-mod / recurid / rrule /
michael@0 76 summary /
michael@0 77
michael@0 78 ; the following are OPTIONAL,
michael@0 79 ; and MAY occur more than once
michael@0 80
michael@0 81 categories / comment / contact / exdate /
michael@0 82 rdate / x-prop
michael@0 83
michael@0 84 )
michael@0 85 * </pre>
michael@0 86 *
michael@0 87 * @author Ben Fortuna
michael@0 88 * @author Mike Douglass
michael@0 89 */
michael@0 90 public class Available extends Component {
michael@0 91
michael@0 92 private static final long serialVersionUID = -2494710612002978763L;
michael@0 93
michael@0 94 /**
michael@0 95 * Default constructor.
michael@0 96 */
michael@0 97 public Available() {
michael@0 98 super(AVAILABLE);
michael@0 99 }
michael@0 100
michael@0 101 /**
michael@0 102 * Constructor.
michael@0 103 * @param properties a list of properties
michael@0 104 */
michael@0 105 public Available(final PropertyList properties) {
michael@0 106 super(AVAILABLE, properties);
michael@0 107 }
michael@0 108
michael@0 109 /**
michael@0 110 * {@inheritDoc}
michael@0 111 */
michael@0 112 public final void validate(final boolean recurse)
michael@0 113 throws ValidationException {
michael@0 114
michael@0 115 /*
michael@0 116 * ; dtstamp / dtstart / uid are required, but MUST NOT occur more than once /
michael@0 117 */
michael@0 118 PropertyValidator.getInstance().assertOne(Property.DTSTART,
michael@0 119 getProperties());
michael@0 120 PropertyValidator.getInstance().assertOne(Property.DTSTAMP,
michael@0 121 getProperties());
michael@0 122 PropertyValidator.getInstance().assertOne(Property.UID,
michael@0 123 getProperties());
michael@0 124
michael@0 125 /* If specified, the "DTSTART" and "DTEND" properties in
michael@0 126 * "VAVAILABILITY" components and "AVAILABLE" sub-components MUST be
michael@0 127 * "DATE-TIME" values specified as either date with UTC time or date
michael@0 128 * with local time and a time zone reference.
michael@0 129 */
michael@0 130 final DtStart start = (DtStart) getProperty(Property.DTSTART);
michael@0 131 if (Value.DATE.equals(start.getParameter(Parameter.VALUE))) {
michael@0 132 throw new ValidationException("Property [" + Property.DTSTART
michael@0 133 + "] must be a " + Value.DATE_TIME);
michael@0 134 }
michael@0 135
michael@0 136 /*
michael@0 137 * ; the following are optional,
michael@0 138 * ; but MUST NOT occur more than once
michael@0 139 *
michael@0 140 * created / last-mod / recurid / rrule /
michael@0 141 * summary /
michael@0 142 */
michael@0 143 PropertyValidator.getInstance().assertOneOrLess(Property.CREATED,
michael@0 144 getProperties());
michael@0 145 PropertyValidator.getInstance().assertOneOrLess(Property.LAST_MODIFIED,
michael@0 146 getProperties());
michael@0 147 PropertyValidator.getInstance().assertOneOrLess(Property.RECURRENCE_ID,
michael@0 148 getProperties());
michael@0 149 PropertyValidator.getInstance().assertOneOrLess(Property.RRULE,
michael@0 150 getProperties());
michael@0 151 PropertyValidator.getInstance().assertOneOrLess(Property.SUMMARY,
michael@0 152 getProperties());
michael@0 153
michael@0 154 /*
michael@0 155 ; either a 'dtend' or a 'duration' is required
michael@0 156 ; in a 'availableprop', but 'dtend' and
michael@0 157 ; 'duration' MUST NOT occur in the same
michael@0 158 ; 'availableprop', and each MUST NOT occur more
michael@0 159 ; than once
michael@0 160 */
michael@0 161 if (getProperty(Property.DTEND) != null) {
michael@0 162 PropertyValidator.getInstance().assertOne(Property.DTEND,
michael@0 163 getProperties());
michael@0 164 /* Must be DATE_TIME */
michael@0 165 final DtEnd end = (DtEnd) getProperty(Property.DTEND);
michael@0 166 if (Value.DATE.equals(end.getParameter(Parameter.VALUE))) {
michael@0 167 throw new ValidationException("Property [" + Property.DTEND
michael@0 168 + "] must be a " + Value.DATE_TIME);
michael@0 169 }
michael@0 170 } else {
michael@0 171 PropertyValidator.getInstance().assertOne(Property.DURATION,
michael@0 172 getProperties());
michael@0 173 }
michael@0 174
michael@0 175 /*
michael@0 176 * ; the following are optional, ; and MAY occur more than once
michael@0 177 * categories / comment / contact / exdate /
michael@0 178 * rdate / x-prop
michael@0 179 */
michael@0 180
michael@0 181 if (recurse) {
michael@0 182 validateProperties();
michael@0 183 }
michael@0 184 }
michael@0 185 }

mercurial