Tue, 10 Feb 2015 19:38:00 +0100
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 java.util.Iterator; |
michael@0 | 35 | |
michael@0 | 36 | import net.fortuna.ical4j.model.Component; |
michael@0 | 37 | import net.fortuna.ical4j.model.ComponentList; |
michael@0 | 38 | import net.fortuna.ical4j.model.Parameter; |
michael@0 | 39 | import net.fortuna.ical4j.model.Property; |
michael@0 | 40 | import net.fortuna.ical4j.model.PropertyList; |
michael@0 | 41 | import net.fortuna.ical4j.model.ValidationException; |
michael@0 | 42 | import net.fortuna.ical4j.model.Validator; |
michael@0 | 43 | import net.fortuna.ical4j.model.parameter.Value; |
michael@0 | 44 | import net.fortuna.ical4j.model.property.DtEnd; |
michael@0 | 45 | import net.fortuna.ical4j.model.property.DtStamp; |
michael@0 | 46 | import net.fortuna.ical4j.model.property.DtStart; |
michael@0 | 47 | import net.fortuna.ical4j.model.property.Method; |
michael@0 | 48 | import net.fortuna.ical4j.util.PropertyValidator; |
michael@0 | 49 | import net.fortuna.ical4j.util.Strings; |
michael@0 | 50 | |
michael@0 | 51 | /** |
michael@0 | 52 | * $Id$ [Apr 5, 2004] |
michael@0 | 53 | * |
michael@0 | 54 | * Defines an iCalendar VAVAILABILITY component. |
michael@0 | 55 | * |
michael@0 | 56 | * <pre> |
michael@0 | 57 | Component Name: VAVAILABILITY |
michael@0 | 58 | |
michael@0 | 59 | Purpose: Provide a grouping of component properties that describe |
michael@0 | 60 | the availability associated with a calendar user. |
michael@0 | 61 | |
michael@0 | 62 | Format Definition: A "VAVAILABILITY" calendar component is defined |
michael@0 | 63 | by the following notation: |
michael@0 | 64 | |
michael@0 | 65 | availabilityc = "BEGIN" ":" "VAVAILABILITY" CRLF |
michael@0 | 66 | availabilityprop *availablec |
michael@0 | 67 | "END" ":" "VAVAILABILITY" CRLF |
michael@0 | 68 | |
michael@0 | 69 | availabilityprop = *( |
michael@0 | 70 | |
michael@0 | 71 | ; the following are REQUIRED, |
michael@0 | 72 | ; but MUST NOT occur more than once |
michael@0 | 73 | |
michael@0 | 74 | dtstamp / dtstart / uid |
michael@0 | 75 | |
michael@0 | 76 | ; the following are OPTIONAL, |
michael@0 | 77 | ; but MUST NOT occur more than once |
michael@0 | 78 | |
michael@0 | 79 | busytype / created / last-mod / |
michael@0 | 80 | organizer / seq / summary / url / |
michael@0 | 81 | |
michael@0 | 82 | ; either 'dtend' or 'duration' may appear |
michael@0 | 83 | ; in a 'availabilityprop', but 'dtend' and |
michael@0 | 84 | ; 'duration' MUST NOT occur in the same |
michael@0 | 85 | ; 'availabilityprop' |
michael@0 | 86 | |
michael@0 | 87 | dtend / duration / |
michael@0 | 88 | |
michael@0 | 89 | ; the following are OPTIONAL, |
michael@0 | 90 | ; and MAY occur more than once |
michael@0 | 91 | |
michael@0 | 92 | categories / comment / contact / x-prop |
michael@0 | 93 | |
michael@0 | 94 | ) |
michael@0 | 95 | |
michael@0 | 96 | * |
michael@0 | 97 | * </pre> |
michael@0 | 98 | * |
michael@0 | 99 | * @author Ben Fortuna |
michael@0 | 100 | * @author Mike Douglass |
michael@0 | 101 | */ |
michael@0 | 102 | public class VAvailability extends CalendarComponent { |
michael@0 | 103 | |
michael@0 | 104 | private static final long serialVersionUID = -3001603309266267258L; |
michael@0 | 105 | |
michael@0 | 106 | private ComponentList available; |
michael@0 | 107 | |
michael@0 | 108 | /** |
michael@0 | 109 | * Default constructor. |
michael@0 | 110 | */ |
michael@0 | 111 | public VAvailability() { |
michael@0 | 112 | super(VAVAILABILITY); |
michael@0 | 113 | this.available = new ComponentList(); |
michael@0 | 114 | getProperties().add(new DtStamp()); |
michael@0 | 115 | } |
michael@0 | 116 | |
michael@0 | 117 | /** |
michael@0 | 118 | * Constructs a new instance containing the specified properties. |
michael@0 | 119 | * @param properties a list of properties |
michael@0 | 120 | */ |
michael@0 | 121 | public VAvailability(final PropertyList properties) { |
michael@0 | 122 | super(VAVAILABILITY, properties); |
michael@0 | 123 | this.available = new ComponentList(); |
michael@0 | 124 | } |
michael@0 | 125 | |
michael@0 | 126 | /** |
michael@0 | 127 | * Constructor. |
michael@0 | 128 | * @param properties a list of properties |
michael@0 | 129 | * @param available a list of available components |
michael@0 | 130 | */ |
michael@0 | 131 | public VAvailability(final PropertyList properties, final ComponentList available) { |
michael@0 | 132 | super(VEVENT, properties); |
michael@0 | 133 | this.available = available; |
michael@0 | 134 | } |
michael@0 | 135 | |
michael@0 | 136 | /** |
michael@0 | 137 | * Returns the list of available times. |
michael@0 | 138 | * @return a component list |
michael@0 | 139 | */ |
michael@0 | 140 | public final ComponentList getAvailable() { |
michael@0 | 141 | return available; |
michael@0 | 142 | } |
michael@0 | 143 | |
michael@0 | 144 | /** |
michael@0 | 145 | * {@inheritDoc} |
michael@0 | 146 | */ |
michael@0 | 147 | public final String toString() { |
michael@0 | 148 | final StringBuffer b = new StringBuffer(); |
michael@0 | 149 | b.append(BEGIN); |
michael@0 | 150 | b.append(':'); |
michael@0 | 151 | b.append(getName()); |
michael@0 | 152 | b.append(Strings.LINE_SEPARATOR); |
michael@0 | 153 | b.append(getProperties()); |
michael@0 | 154 | b.append(getAvailable()); |
michael@0 | 155 | b.append(END); |
michael@0 | 156 | b.append(':'); |
michael@0 | 157 | b.append(getName()); |
michael@0 | 158 | b.append(Strings.LINE_SEPARATOR); |
michael@0 | 159 | return b.toString(); |
michael@0 | 160 | } |
michael@0 | 161 | |
michael@0 | 162 | /** |
michael@0 | 163 | * {@inheritDoc} |
michael@0 | 164 | */ |
michael@0 | 165 | public final void validate(final boolean recurse) |
michael@0 | 166 | throws ValidationException { |
michael@0 | 167 | |
michael@0 | 168 | // validate that getAvailable() only contains Available components |
michael@0 | 169 | final Iterator iterator = getAvailable().iterator(); |
michael@0 | 170 | while (iterator.hasNext()) { |
michael@0 | 171 | final Component component = (Component) iterator.next(); |
michael@0 | 172 | |
michael@0 | 173 | if (!(component instanceof Available)) { |
michael@0 | 174 | throw new ValidationException("Component [" |
michael@0 | 175 | + component.getName() + "] may not occur in VAVAILABILITY"); |
michael@0 | 176 | } |
michael@0 | 177 | } |
michael@0 | 178 | |
michael@0 | 179 | /* |
michael@0 | 180 | * ; dtstamp / dtstart / uid are required, but MUST NOT occur more than once / |
michael@0 | 181 | */ |
michael@0 | 182 | PropertyValidator.getInstance().assertOne(Property.DTSTART, |
michael@0 | 183 | getProperties()); |
michael@0 | 184 | PropertyValidator.getInstance().assertOne(Property.DTSTAMP, |
michael@0 | 185 | getProperties()); |
michael@0 | 186 | PropertyValidator.getInstance().assertOne(Property.UID, |
michael@0 | 187 | getProperties()); |
michael@0 | 188 | |
michael@0 | 189 | /* If specified, the "DTSTART" and "DTEND" properties in |
michael@0 | 190 | * "VAVAILABILITY" components and "AVAILABLE" sub-components MUST be |
michael@0 | 191 | * "DATE-TIME" values specified as either date with UTC time or date |
michael@0 | 192 | * with local time and a time zone reference. |
michael@0 | 193 | */ |
michael@0 | 194 | final DtStart start = (DtStart) getProperty(Property.DTSTART); |
michael@0 | 195 | if (Value.DATE.equals(start.getParameter(Parameter.VALUE))) { |
michael@0 | 196 | throw new ValidationException("Property [" + Property.DTSTART |
michael@0 | 197 | + "] must be a " + Value.DATE_TIME); |
michael@0 | 198 | } |
michael@0 | 199 | |
michael@0 | 200 | /* |
michael@0 | 201 | * ; either 'dtend' or 'duration' may appear in ; a 'eventprop', but 'dtend' and 'duration' ; MUST NOT occur in |
michael@0 | 202 | * the same 'eventprop' dtend / duration / |
michael@0 | 203 | */ |
michael@0 | 204 | if (getProperty(Property.DTEND) != null) { |
michael@0 | 205 | PropertyValidator.getInstance().assertOne(Property.DTEND, |
michael@0 | 206 | getProperties()); |
michael@0 | 207 | /* Must be DATE_TIME */ |
michael@0 | 208 | final DtEnd end = (DtEnd) getProperty(Property.DTEND); |
michael@0 | 209 | if (Value.DATE.equals(end.getParameter(Parameter.VALUE))) { |
michael@0 | 210 | throw new ValidationException("Property [" + Property.DTEND |
michael@0 | 211 | + "] must be a " + Value.DATE_TIME); |
michael@0 | 212 | } |
michael@0 | 213 | |
michael@0 | 214 | if (getProperty(Property.DURATION) != null) { |
michael@0 | 215 | throw new ValidationException("Only one of Property [" + Property.DTEND |
michael@0 | 216 | + "] or [" + Property.DURATION + |
michael@0 | 217 | " must appear a VAVAILABILITY"); |
michael@0 | 218 | } |
michael@0 | 219 | } |
michael@0 | 220 | |
michael@0 | 221 | /* |
michael@0 | 222 | * ; the following are optional, |
michael@0 | 223 | * ; but MUST NOT occur more than once |
michael@0 | 224 | * |
michael@0 | 225 | * busytype / created / last-mod / |
michael@0 | 226 | * organizer / seq / summary / url / |
michael@0 | 227 | */ |
michael@0 | 228 | PropertyValidator.getInstance().assertOneOrLess(Property.BUSYTYPE, |
michael@0 | 229 | getProperties()); |
michael@0 | 230 | PropertyValidator.getInstance().assertOneOrLess(Property.CREATED, |
michael@0 | 231 | getProperties()); |
michael@0 | 232 | PropertyValidator.getInstance().assertOneOrLess(Property.LAST_MODIFIED, |
michael@0 | 233 | getProperties()); |
michael@0 | 234 | PropertyValidator.getInstance().assertOneOrLess(Property.ORGANIZER, |
michael@0 | 235 | getProperties()); |
michael@0 | 236 | PropertyValidator.getInstance().assertOneOrLess(Property.SEQUENCE, |
michael@0 | 237 | getProperties()); |
michael@0 | 238 | PropertyValidator.getInstance().assertOneOrLess(Property.SUMMARY, |
michael@0 | 239 | getProperties()); |
michael@0 | 240 | PropertyValidator.getInstance().assertOneOrLess(Property.URL, |
michael@0 | 241 | getProperties()); |
michael@0 | 242 | |
michael@0 | 243 | /* |
michael@0 | 244 | * ; the following are optional, ; and MAY occur more than once |
michael@0 | 245 | * categories / comment / contact / x-prop |
michael@0 | 246 | */ |
michael@0 | 247 | |
michael@0 | 248 | if (recurse) { |
michael@0 | 249 | validateProperties(); |
michael@0 | 250 | } |
michael@0 | 251 | } |
michael@0 | 252 | |
michael@0 | 253 | /** |
michael@0 | 254 | * {@inheritDoc} |
michael@0 | 255 | */ |
michael@0 | 256 | protected Validator getValidator(Method method) { |
michael@0 | 257 | // TODO Auto-generated method stub |
michael@0 | 258 | return null; |
michael@0 | 259 | } |
michael@0 | 260 | } |