src/net/fortuna/ical4j/model/component/VToDo.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
child 3
73bdfa70b04e
permissions
-rw-r--r--

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

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.io.IOException;
michael@0 35 import java.net.URISyntaxException;
michael@0 36 import java.text.ParseException;
michael@0 37 import java.util.HashMap;
michael@0 38 import java.util.Iterator;
michael@0 39 import java.util.Map;
michael@0 40
michael@0 41 import net.fortuna.ical4j.model.Component;
michael@0 42 import net.fortuna.ical4j.model.ComponentList;
michael@0 43 import net.fortuna.ical4j.model.Date;
michael@0 44 import net.fortuna.ical4j.model.Dur;
michael@0 45 import net.fortuna.ical4j.model.Property;
michael@0 46 import net.fortuna.ical4j.model.PropertyList;
michael@0 47 import net.fortuna.ical4j.model.ValidationException;
michael@0 48 import net.fortuna.ical4j.model.Validator;
michael@0 49 import net.fortuna.ical4j.model.property.Clazz;
michael@0 50 import net.fortuna.ical4j.model.property.Completed;
michael@0 51 import net.fortuna.ical4j.model.property.Created;
michael@0 52 import net.fortuna.ical4j.model.property.Description;
michael@0 53 import net.fortuna.ical4j.model.property.DtStamp;
michael@0 54 import net.fortuna.ical4j.model.property.DtStart;
michael@0 55 import net.fortuna.ical4j.model.property.Due;
michael@0 56 import net.fortuna.ical4j.model.property.Duration;
michael@0 57 import net.fortuna.ical4j.model.property.Geo;
michael@0 58 import net.fortuna.ical4j.model.property.LastModified;
michael@0 59 import net.fortuna.ical4j.model.property.Location;
michael@0 60 import net.fortuna.ical4j.model.property.Method;
michael@0 61 import net.fortuna.ical4j.model.property.Organizer;
michael@0 62 import net.fortuna.ical4j.model.property.PercentComplete;
michael@0 63 import net.fortuna.ical4j.model.property.Priority;
michael@0 64 import net.fortuna.ical4j.model.property.RecurrenceId;
michael@0 65 import net.fortuna.ical4j.model.property.Sequence;
michael@0 66 import net.fortuna.ical4j.model.property.Status;
michael@0 67 import net.fortuna.ical4j.model.property.Summary;
michael@0 68 import net.fortuna.ical4j.model.property.Uid;
michael@0 69 import net.fortuna.ical4j.model.property.Url;
michael@0 70 import net.fortuna.ical4j.util.CompatibilityHints;
michael@0 71 import net.fortuna.ical4j.util.ComponentValidator;
michael@0 72 import net.fortuna.ical4j.util.PropertyValidator;
michael@0 73 import net.fortuna.ical4j.util.Strings;
michael@0 74
michael@0 75 import org.apache.commons.lang.ObjectUtils;
michael@0 76 import org.apache.commons.lang.builder.HashCodeBuilder;
michael@0 77
michael@0 78 /**
michael@0 79 * $Id$ [Apr 5, 2004]
michael@0 80 *
michael@0 81 * Defines an iCalendar VTODO component.
michael@0 82 *
michael@0 83 * <pre>
michael@0 84 * 4.6.2 To-do Component
michael@0 85 *
michael@0 86 * Component Name: VTODO
michael@0 87 *
michael@0 88 * Purpose: Provide a grouping of calendar properties that describe a
michael@0 89 * to-do.
michael@0 90 *
michael@0 91 * Formal Definition: A &quot;VTODO&quot; calendar component is defined by the
michael@0 92 * following notation:
michael@0 93 *
michael@0 94 * todoc = &quot;BEGIN&quot; &quot;:&quot; &quot;VTODO&quot; CRLF
michael@0 95 * todoprop *alarmc
michael@0 96 * &quot;END&quot; &quot;:&quot; &quot;VTODO&quot; CRLF
michael@0 97 *
michael@0 98 * todoprop = *(
michael@0 99 *
michael@0 100 * ; the following are optional,
michael@0 101 * ; but MUST NOT occur more than once
michael@0 102 *
michael@0 103 * class / completed / created / description / dtstamp /
michael@0 104 * dtstart / geo / last-mod / location / organizer /
michael@0 105 * percent / priority / recurid / seq / status /
michael@0 106 * summary / uid / url /
michael@0 107 *
michael@0 108 * ; either 'due' or 'duration' may appear in
michael@0 109 * ; a 'todoprop', but 'due' and 'duration'
michael@0 110 * ; MUST NOT occur in the same 'todoprop'
michael@0 111 *
michael@0 112 * due / duration /
michael@0 113 *
michael@0 114 * ; the following are optional,
michael@0 115 * ; and MAY occur more than once
michael@0 116 * attach / attendee / categories / comment / contact /
michael@0 117 * exdate / exrule / rstatus / related / resources /
michael@0 118 * rdate / rrule / x-prop
michael@0 119 *
michael@0 120 * )
michael@0 121 * </pre>
michael@0 122 *
michael@0 123 * Example 1 - Creating a todo of two (2) hour duration starting tomorrow:
michael@0 124 *
michael@0 125 * <pre><code>
michael@0 126 * java.util.Calendar cal = java.util.Calendar.getInstance();
michael@0 127 * // tomorrow..
michael@0 128 * cal.add(java.util.Calendar.DAY_OF_MONTH, 1);
michael@0 129 * cal.set(java.util.Calendar.HOUR_OF_DAY, 11);
michael@0 130 * cal.set(java.util.Calendar.MINUTE, 00);
michael@0 131 *
michael@0 132 * VToDo documentation = new VEvent(cal.getTime(), 1000 * 60 * 60 * 2,
michael@0 133 * &quot;Document calendar component usage&quot;);
michael@0 134 *
michael@0 135 * // add timezone information..
michael@0 136 * VTimeZone tz = VTimeZone.getDefault();
michael@0 137 * TzId tzParam = new TzId(tz.getProperties().getProperty(Property.TZID)
michael@0 138 * .getValue());
michael@0 139 * documentation.getProperties().getProperty(Property.DTSTART).getParameters()
michael@0 140 * .add(tzParam);
michael@0 141 * </code></pre>
michael@0 142 *
michael@0 143 * @author Ben Fortuna
michael@0 144 */
michael@0 145 public class VToDo extends CalendarComponent {
michael@0 146
michael@0 147 private static final long serialVersionUID = -269658210065896668L;
michael@0 148
michael@0 149 private final Map methodValidators = new HashMap();
michael@0 150 {
michael@0 151 methodValidators.put(Method.ADD, new AddValidator());
michael@0 152 methodValidators.put(Method.CANCEL, new CancelValidator());
michael@0 153 methodValidators.put(Method.COUNTER, new CounterValidator());
michael@0 154 methodValidators.put(Method.DECLINE_COUNTER, new DeclineCounterValidator());
michael@0 155 methodValidators.put(Method.PUBLISH, new PublishValidator());
michael@0 156 methodValidators.put(Method.REFRESH, new RefreshValidator());
michael@0 157 methodValidators.put(Method.REPLY, new ReplyValidator());
michael@0 158 methodValidators.put(Method.REQUEST, new RequestValidator());
michael@0 159 }
michael@0 160
michael@0 161 private ComponentList alarms = new ComponentList();
michael@0 162
michael@0 163 /**
michael@0 164 * Default constructor.
michael@0 165 */
michael@0 166 public VToDo() {
michael@0 167 super(VTODO);
michael@0 168 getProperties().add(new DtStamp());
michael@0 169 }
michael@0 170
michael@0 171 /**
michael@0 172 * Constructor.
michael@0 173 * @param properties a list of properties
michael@0 174 */
michael@0 175 public VToDo(final PropertyList properties) {
michael@0 176 super(VTODO, properties);
michael@0 177 }
michael@0 178
michael@0 179 /**
michael@0 180 * Constructs a new VTODO instance starting at the specified time with the specified summary.
michael@0 181 * @param start the start date of the new todo
michael@0 182 * @param summary the todo summary
michael@0 183 */
michael@0 184 public VToDo(final Date start, final String summary) {
michael@0 185 this();
michael@0 186 getProperties().add(new DtStart(start));
michael@0 187 getProperties().add(new Summary(summary));
michael@0 188 }
michael@0 189
michael@0 190 /**
michael@0 191 * Constructs a new VTODO instance starting and ending at the specified times with the specified summary.
michael@0 192 * @param start the start date of the new todo
michael@0 193 * @param due the due date of the new todo
michael@0 194 * @param summary the todo summary
michael@0 195 */
michael@0 196 public VToDo(final Date start, final Date due, final String summary) {
michael@0 197 this();
michael@0 198 getProperties().add(new DtStart(start));
michael@0 199 getProperties().add(new Due(due));
michael@0 200 getProperties().add(new Summary(summary));
michael@0 201 }
michael@0 202
michael@0 203 /**
michael@0 204 * Constructs a new VTODO instance starting at the specified times, for the specified duration, with the specified
michael@0 205 * summary.
michael@0 206 * @param start the start date of the new todo
michael@0 207 * @param duration the duration of the new todo
michael@0 208 * @param summary the todo summary
michael@0 209 */
michael@0 210 public VToDo(final Date start, final Dur duration, final String summary) {
michael@0 211 this();
michael@0 212 getProperties().add(new DtStart(start));
michael@0 213 getProperties().add(new Duration(duration));
michael@0 214 getProperties().add(new Summary(summary));
michael@0 215 }
michael@0 216
michael@0 217 /**
michael@0 218 * Returns the list of alarms for this todo.
michael@0 219 * @return a component list
michael@0 220 */
michael@0 221 public final ComponentList getAlarms() {
michael@0 222 return alarms;
michael@0 223 }
michael@0 224
michael@0 225 /**
michael@0 226 * {@inheritDoc}
michael@0 227 */
michael@0 228 public final String toString() {
michael@0 229 final StringBuffer buffer = new StringBuffer();
michael@0 230 buffer.append(BEGIN);
michael@0 231 buffer.append(':');
michael@0 232 buffer.append(getName());
michael@0 233 buffer.append(Strings.LINE_SEPARATOR);
michael@0 234 buffer.append(getProperties());
michael@0 235 buffer.append(getAlarms());
michael@0 236 buffer.append(END);
michael@0 237 buffer.append(':');
michael@0 238 buffer.append(getName());
michael@0 239 buffer.append(Strings.LINE_SEPARATOR);
michael@0 240 return buffer.toString();
michael@0 241 }
michael@0 242
michael@0 243 /**
michael@0 244 * {@inheritDoc}
michael@0 245 */
michael@0 246 public final void validate(final boolean recurse)
michael@0 247 throws ValidationException {
michael@0 248
michael@0 249 // validate that getAlarms() only contains VAlarm components
michael@0 250 final Iterator iterator = getAlarms().iterator();
michael@0 251 while (iterator.hasNext()) {
michael@0 252 final Component component = (Component) iterator.next();
michael@0 253 if (!(component instanceof VAlarm)) {
michael@0 254 throw new ValidationException("Component ["
michael@0 255 + component.getName() + "] may not occur in VTODO");
michael@0 256 }
michael@0 257 ((VAlarm) component).validate(recurse);
michael@0 258 }
michael@0 259
michael@0 260 if (!CompatibilityHints
michael@0 261 .isHintEnabled(CompatibilityHints.KEY_RELAXED_VALIDATION)) {
michael@0 262
michael@0 263 // From "4.8.4.7 Unique Identifier":
michael@0 264 // Conformance: The property MUST be specified in the "VEVENT", "VTODO",
michael@0 265 // "VJOURNAL" or "VFREEBUSY" calendar components.
michael@0 266 PropertyValidator.getInstance().assertOne(Property.UID,
michael@0 267 getProperties());
michael@0 268
michael@0 269 // From "4.8.7.2 Date/Time Stamp":
michael@0 270 // Conformance: This property MUST be included in the "VEVENT", "VTODO",
michael@0 271 // "VJOURNAL" or "VFREEBUSY" calendar components.
michael@0 272 PropertyValidator.getInstance().assertOne(Property.DTSTAMP,
michael@0 273 getProperties());
michael@0 274 }
michael@0 275
michael@0 276 /*
michael@0 277 * ; the following are optional, ; but MUST NOT occur more than once class / completed / created / description /
michael@0 278 * dtstamp / dtstart / geo / last-mod / location / organizer / percent / priority / recurid / seq / status /
michael@0 279 * summary / uid / url /
michael@0 280 */
michael@0 281 PropertyValidator.getInstance().assertOneOrLess(Property.CLASS,
michael@0 282 getProperties());
michael@0 283 PropertyValidator.getInstance().assertOneOrLess(Property.COMPLETED,
michael@0 284 getProperties());
michael@0 285 PropertyValidator.getInstance().assertOneOrLess(Property.CREATED,
michael@0 286 getProperties());
michael@0 287 PropertyValidator.getInstance().assertOneOrLess(Property.DESCRIPTION,
michael@0 288 getProperties());
michael@0 289 PropertyValidator.getInstance().assertOneOrLess(Property.DTSTAMP,
michael@0 290 getProperties());
michael@0 291 PropertyValidator.getInstance().assertOneOrLess(Property.DTSTART,
michael@0 292 getProperties());
michael@0 293 PropertyValidator.getInstance().assertOneOrLess(Property.GEO,
michael@0 294 getProperties());
michael@0 295 PropertyValidator.getInstance().assertOneOrLess(Property.LAST_MODIFIED,
michael@0 296 getProperties());
michael@0 297 PropertyValidator.getInstance().assertOneOrLess(Property.LOCATION,
michael@0 298 getProperties());
michael@0 299 PropertyValidator.getInstance().assertOneOrLess(Property.ORGANIZER,
michael@0 300 getProperties());
michael@0 301 PropertyValidator.getInstance().assertOneOrLess(
michael@0 302 Property.PERCENT_COMPLETE, getProperties());
michael@0 303 PropertyValidator.getInstance().assertOneOrLess(Property.PRIORITY,
michael@0 304 getProperties());
michael@0 305 PropertyValidator.getInstance().assertOneOrLess(Property.RECURRENCE_ID,
michael@0 306 getProperties());
michael@0 307 PropertyValidator.getInstance().assertOneOrLess(Property.SEQUENCE,
michael@0 308 getProperties());
michael@0 309 PropertyValidator.getInstance().assertOneOrLess(Property.STATUS,
michael@0 310 getProperties());
michael@0 311 PropertyValidator.getInstance().assertOneOrLess(Property.SUMMARY,
michael@0 312 getProperties());
michael@0 313 PropertyValidator.getInstance().assertOneOrLess(Property.UID,
michael@0 314 getProperties());
michael@0 315 PropertyValidator.getInstance().assertOneOrLess(Property.URL,
michael@0 316 getProperties());
michael@0 317
michael@0 318 final Status status = (Status) getProperty(Property.STATUS);
michael@0 319 if (status != null && !Status.VTODO_NEEDS_ACTION.getValue().equals(status.getValue())
michael@0 320 && !Status.VTODO_COMPLETED.getValue().equals(status.getValue())
michael@0 321 && !Status.VTODO_IN_PROCESS.getValue().equals(status.getValue())
michael@0 322 && !Status.VTODO_CANCELLED.getValue().equals(status.getValue())) {
michael@0 323 throw new ValidationException("Status property ["
michael@0 324 + status.toString() + "] may not occur in VTODO");
michael@0 325 }
michael@0 326
michael@0 327 /*
michael@0 328 * ; either 'due' or 'duration' may appear in ; a 'todoprop', but 'due' and 'duration' ; MUST NOT occur in the
michael@0 329 * same 'todoprop' due / duration /
michael@0 330 */
michael@0 331 try {
michael@0 332 PropertyValidator.getInstance().assertNone(Property.DUE,
michael@0 333 getProperties());
michael@0 334 }
michael@0 335 catch (ValidationException ve) {
michael@0 336 PropertyValidator.getInstance().assertNone(Property.DURATION,
michael@0 337 getProperties());
michael@0 338 }
michael@0 339
michael@0 340 /*
michael@0 341 * ; the following are optional, ; and MAY occur more than once attach / attendee / categories / comment /
michael@0 342 * contact / exdate / exrule / rstatus / related / resources / rdate / rrule / x-prop
michael@0 343 */
michael@0 344
michael@0 345 if (recurse) {
michael@0 346 validateProperties();
michael@0 347 }
michael@0 348 }
michael@0 349
michael@0 350 /**
michael@0 351 * {@inheritDoc}
michael@0 352 */
michael@0 353 protected Validator getValidator(Method method) {
michael@0 354 return (Validator) methodValidators.get(method);
michael@0 355 }
michael@0 356
michael@0 357 /**
michael@0 358 * <pre>
michael@0 359 * Component/Property Presence
michael@0 360 * ------------------- ----------------------------------------------
michael@0 361 * METHOD 1 MUST be "ADD"
michael@0 362 * VTODO 1
michael@0 363 * DTSTAMP 1
michael@0 364 * ORGANIZER 1
michael@0 365 * PRIORITY 1
michael@0 366 * SEQUENCE 1 MUST be greater than 0
michael@0 367 * SUMMARY 1 Can be null.
michael@0 368 * UID 1 MUST match that of the original to-do
michael@0 369 *
michael@0 370 * ATTACH 0+
michael@0 371 * ATTENDEE 0+
michael@0 372 * CATEGORIES 0 or 1 This property may contain a list of
michael@0 373 * values
michael@0 374 * CLASS 0 or 1
michael@0 375 * COMMENT 0 or 1
michael@0 376 * CONTACT 0+
michael@0 377 * CREATED 0 or 1
michael@0 378 * DESCRIPTION 0 or 1 Can be null
michael@0 379 * DTSTART 0 or 1
michael@0 380 * DUE 0 or 1 If present DURATION MUST NOT be present
michael@0 381 * DURATION 0 or 1 If present DUE MUST NOT be present
michael@0 382 * EXDATE 0+
michael@0 383 * EXRULE 0+
michael@0 384 * GEO 0 or 1
michael@0 385 * LAST-MODIFIED 0 or 1
michael@0 386 * LOCATION 0 or 1
michael@0 387 * PERCENT-COMPLETE 0 or 1
michael@0 388 * RDATE 0+
michael@0 389 * RELATED-TO 0+
michael@0 390 * RESOURCES 0 or 1 This property may contain a list of
michael@0 391 * values
michael@0 392 * RRULE 0+
michael@0 393 * STATUS 0 or 1 MAY be one of COMPLETED/NEEDS ACTION/IN-
michael@0 394 * PROCESS
michael@0 395 * URL 0 or 1
michael@0 396 * X-PROPERTY 0+
michael@0 397 *
michael@0 398 * RECURRENCE-ID 0
michael@0 399 * REQUEST-STATUS 0
michael@0 400 *
michael@0 401 * VALARM 0+
michael@0 402 * VTIMEZONE 0+ MUST be present if any date/time refers
michael@0 403 * to a timezone
michael@0 404 * X-COMPONENT 0+
michael@0 405 *
michael@0 406 * VEVENT 0
michael@0 407 * VJOURNAL 0
michael@0 408 * VFREEBUSY 0
michael@0 409 * </pre>
michael@0 410 *
michael@0 411 */
michael@0 412 private class AddValidator implements Validator {
michael@0 413
michael@0 414 private static final long serialVersionUID = 1L;
michael@0 415
michael@0 416 public void validate() throws ValidationException {
michael@0 417 PropertyValidator.getInstance().assertOne(Property.DTSTAMP, getProperties());
michael@0 418 PropertyValidator.getInstance().assertOne(Property.ORGANIZER, getProperties());
michael@0 419 PropertyValidator.getInstance().assertOne(Property.PRIORITY, getProperties());
michael@0 420 PropertyValidator.getInstance().assertOne(Property.SEQUENCE, getProperties());
michael@0 421 PropertyValidator.getInstance().assertOne(Property.SUMMARY, getProperties());
michael@0 422 PropertyValidator.getInstance().assertOne(Property.UID, getProperties());
michael@0 423
michael@0 424 PropertyValidator.getInstance().assertOneOrLess(Property.CATEGORIES, getProperties());
michael@0 425 PropertyValidator.getInstance().assertOneOrLess(Property.CLASS, getProperties());
michael@0 426 PropertyValidator.getInstance().assertOneOrLess(Property.COMMENT, getProperties());
michael@0 427 PropertyValidator.getInstance().assertOneOrLess(Property.CREATED, getProperties());
michael@0 428 PropertyValidator.getInstance().assertOneOrLess(Property.DESCRIPTION, getProperties());
michael@0 429 PropertyValidator.getInstance().assertOneOrLess(Property.DTSTART, getProperties());
michael@0 430 PropertyValidator.getInstance().assertOneOrLess(Property.DUE, getProperties());
michael@0 431 PropertyValidator.getInstance().assertOneOrLess(Property.DURATION, getProperties());
michael@0 432 PropertyValidator.getInstance().assertOneOrLess(Property.GEO, getProperties());
michael@0 433 PropertyValidator.getInstance().assertOneOrLess(Property.LAST_MODIFIED, getProperties());
michael@0 434 PropertyValidator.getInstance().assertOneOrLess(Property.LOCATION, getProperties());
michael@0 435 PropertyValidator.getInstance().assertOneOrLess(Property.PERCENT_COMPLETE, getProperties());
michael@0 436 PropertyValidator.getInstance().assertOneOrLess(Property.RESOURCES, getProperties());
michael@0 437 PropertyValidator.getInstance().assertOneOrLess(Property.STATUS, getProperties());
michael@0 438 PropertyValidator.getInstance().assertOneOrLess(Property.URL, getProperties());
michael@0 439
michael@0 440 PropertyValidator.getInstance().assertNone(Property.RECURRENCE_ID, getProperties());
michael@0 441 PropertyValidator.getInstance().assertNone(Property.REQUEST_STATUS, getProperties());
michael@0 442
michael@0 443 for (final Iterator i = getAlarms().iterator(); i.hasNext();) {
michael@0 444 final VAlarm alarm = (VAlarm) i.next();
michael@0 445 alarm.validate(Method.ADD);
michael@0 446 }
michael@0 447 }
michael@0 448 }
michael@0 449
michael@0 450 /**
michael@0 451 * <pre>
michael@0 452 * Component/Property Presence
michael@0 453 * ------------------- ---------------------------------------------
michael@0 454 * METHOD 1 MUST be "CANCEL"
michael@0 455 * VTODO 1
michael@0 456 * ATTENDEE 0+ include all "Attendees" being removed from
michael@0 457 * the todo. MUST include all "Attendees" if
michael@0 458 * the entire todo is cancelled.
michael@0 459 * UID 1 MUST echo original UID
michael@0 460 * DTSTAMP 1
michael@0 461 * ORGANIZER 1
michael@0 462 * SEQUENCE 1
michael@0 463 *
michael@0 464 * ATTACH 0+
michael@0 465 * CATEGORIES 0 or 1 This property MAY contain a list of values
michael@0 466 * CLASS 0 or 1
michael@0 467 * COMMENT 0 or 1
michael@0 468 * CONTACT 0+
michael@0 469 * CREATED 0 or 1
michael@0 470 * DESCRIPTION 0 or 1
michael@0 471 * DTSTART 0 or 1
michael@0 472 * DUE 0 or 1 If present DURATION MUST NOT be present
michael@0 473 * DURATION 0 or 1 If present DUE MUST NOT be present
michael@0 474 * EXDATE 0+
michael@0 475 * EXRULE 0+
michael@0 476 * GEO 0 or 1
michael@0 477 * LAST-MODIFIED 0 or 1
michael@0 478 * LOCATION 0 or 1
michael@0 479 * PERCENT-COMPLETE 0 or 1
michael@0 480 * RDATE 0+
michael@0 481 * RECURRENCE-ID 0 or 1 MUST only if referring to one or more
michael@0 482 * instances of a recurring calendar
michael@0 483 * component. Otherwise it MUST NOT be
michael@0 484 * present.
michael@0 485 * RELATED-TO 0+
michael@0 486 * RESOURCES 0 or 1 This property MAY contain a list of values
michael@0 487 * RRULE 0+
michael@0 488 * PRIORITY 0 or 1
michael@0 489 * STATUS 0 or 1 If present it MUST be set to "CANCELLED".
michael@0 490 * MUST NOT be used if purpose is to remove
michael@0 491 * "ATTENDEES" rather than cancel the entire
michael@0 492 * VTODO.
michael@0 493 * URL 0 or 1
michael@0 494 * X-PROPERTY 0+
michael@0 495 *
michael@0 496 * REQUEST-STATUS 0
michael@0 497 *
michael@0 498 * VTIMEZONE 0 or 1 MUST be present if any date/time refers to
michael@0 499 * a timezone
michael@0 500 * X-COMPONENT 0+
michael@0 501 *
michael@0 502 * VALARM 0
michael@0 503 * VEVENT 0
michael@0 504 * VFREEBUSY 0
michael@0 505 * </pre>
michael@0 506 *
michael@0 507 */
michael@0 508 private class CancelValidator implements Validator {
michael@0 509
michael@0 510 private static final long serialVersionUID = 1L;
michael@0 511
michael@0 512 public void validate() throws ValidationException {
michael@0 513 PropertyValidator.getInstance().assertOne(Property.UID, getProperties());
michael@0 514 PropertyValidator.getInstance().assertOne(Property.DTSTAMP, getProperties());
michael@0 515 PropertyValidator.getInstance().assertOne(Property.ORGANIZER, getProperties());
michael@0 516 PropertyValidator.getInstance().assertOne(Property.SEQUENCE, getProperties());
michael@0 517
michael@0 518 PropertyValidator.getInstance().assertOneOrLess(Property.CATEGORIES, getProperties());
michael@0 519 PropertyValidator.getInstance().assertOneOrLess(Property.CLASS, getProperties());
michael@0 520 PropertyValidator.getInstance().assertOneOrLess(Property.COMMENT, getProperties());
michael@0 521 PropertyValidator.getInstance().assertOneOrLess(Property.CREATED, getProperties());
michael@0 522 PropertyValidator.getInstance().assertOneOrLess(Property.DESCRIPTION, getProperties());
michael@0 523 PropertyValidator.getInstance().assertOneOrLess(Property.DTSTART, getProperties());
michael@0 524 PropertyValidator.getInstance().assertOneOrLess(Property.DUE, getProperties());
michael@0 525 PropertyValidator.getInstance().assertOneOrLess(Property.DURATION, getProperties());
michael@0 526 PropertyValidator.getInstance().assertOneOrLess(Property.GEO, getProperties());
michael@0 527 PropertyValidator.getInstance().assertOneOrLess(Property.LAST_MODIFIED, getProperties());
michael@0 528 PropertyValidator.getInstance().assertOneOrLess(Property.LOCATION, getProperties());
michael@0 529 PropertyValidator.getInstance().assertOneOrLess(Property.PERCENT_COMPLETE, getProperties());
michael@0 530 PropertyValidator.getInstance().assertOneOrLess(Property.RECURRENCE_ID, getProperties());
michael@0 531 PropertyValidator.getInstance().assertOneOrLess(Property.RESOURCES, getProperties());
michael@0 532 PropertyValidator.getInstance().assertOneOrLess(Property.PRIORITY, getProperties());
michael@0 533 PropertyValidator.getInstance().assertOneOrLess(Property.STATUS, getProperties());
michael@0 534 PropertyValidator.getInstance().assertOneOrLess(Property.URL, getProperties());
michael@0 535
michael@0 536 PropertyValidator.getInstance().assertNone(Property.REQUEST_STATUS, getProperties());
michael@0 537
michael@0 538 ComponentValidator.assertNone(Component.VALARM, getAlarms());
michael@0 539 }
michael@0 540 }
michael@0 541
michael@0 542 /**
michael@0 543 * <pre>
michael@0 544 * Component/Property Presence
michael@0 545 * ------------------- ----------------------------------------------
michael@0 546 * METHOD 1 MUST be "COUNTER"
michael@0 547 * VTODO 1
michael@0 548 * ATTENDEE 1+
michael@0 549 * DTSTAMP 1
michael@0 550 * ORGANIZER 1
michael@0 551 * PRIORITY 1
michael@0 552 * SUMMARY 1 Can be null
michael@0 553 * UID 1
michael@0 554 *
michael@0 555 * ATTACH 0+
michael@0 556 * CATEGORIES 0 or 1 This property MAY contain a list of values
michael@0 557 * CLASS 0 or 1
michael@0 558 * COMMENT 0 or 1
michael@0 559 * CONTACT 0+
michael@0 560 * CREATED 0 or 1
michael@0 561 * DESCRIPTION 0 or 1 Can be null
michael@0 562 * DTSTART 0 or 1
michael@0 563 * DUE 0 or 1 If present DURATION MUST NOT be present
michael@0 564 * DURATION 0 or 1 If present DUE MUST NOT be present
michael@0 565 * EXDATE 0+
michael@0 566 * EXRULE 0+
michael@0 567 * GEO 0 or 1
michael@0 568 * LAST-MODIFIED 0 or 1
michael@0 569 * LOCATION 0 or 1
michael@0 570 * PERCENT-COMPLETE 0 or 1
michael@0 571 * RDATE 0+
michael@0 572 * RECURRENCE-ID 0 or 1 MUST only 3.5if referring to an instance of a
michael@0 573 * recurring calendar component. Otherwise it
michael@0 574 * MUST NOT be present.
michael@0 575 * RELATED-TO 0+
michael@0 576 * REQUEST-STATUS 0+
michael@0 577 * RESOURCES 0 or 1 This property MAY contain a list of values
michael@0 578 * RRULE 0 or 1
michael@0 579 * SEQUENCE 0 or 1 MUST echo the original SEQUENCE number.
michael@0 580 * MUST be present if non-zero. MAY be present
michael@0 581 * if zero.
michael@0 582 * STATUS 0 or 1 MAY be one of COMPLETED/NEEDS ACTION/IN-
michael@0 583 * PROCESS/CANCELLED
michael@0 584 * URL 0 or 1
michael@0 585 * X-PROPERTY 0+
michael@0 586 *
michael@0 587 *
michael@0 588 * VALARM 0+
michael@0 589 * VTIMEZONE 0 or 1 MUST be present if any date/time refers to
michael@0 590 * a timezone
michael@0 591 * X-COMPONENT 0+
michael@0 592 *
michael@0 593 * VEVENT 0
michael@0 594 * VFREEBUSY 0
michael@0 595 * </pre>
michael@0 596 *
michael@0 597 */
michael@0 598 private class CounterValidator implements Validator {
michael@0 599
michael@0 600 private static final long serialVersionUID = 1L;
michael@0 601
michael@0 602 public void validate() throws ValidationException {
michael@0 603 PropertyValidator.getInstance().assertOneOrMore(Property.ATTENDEE, getProperties());
michael@0 604
michael@0 605 PropertyValidator.getInstance().assertOne(Property.DTSTAMP, getProperties());
michael@0 606 PropertyValidator.getInstance().assertOne(Property.ORGANIZER, getProperties());
michael@0 607 PropertyValidator.getInstance().assertOne(Property.PRIORITY, getProperties());
michael@0 608 PropertyValidator.getInstance().assertOne(Property.SUMMARY, getProperties());
michael@0 609 PropertyValidator.getInstance().assertOne(Property.UID, getProperties());
michael@0 610
michael@0 611 PropertyValidator.getInstance().assertOneOrLess(Property.CATEGORIES, getProperties());
michael@0 612 PropertyValidator.getInstance().assertOneOrLess(Property.CLASS, getProperties());
michael@0 613 PropertyValidator.getInstance().assertOneOrLess(Property.COMMENT, getProperties());
michael@0 614 PropertyValidator.getInstance().assertOneOrLess(Property.CREATED, getProperties());
michael@0 615 PropertyValidator.getInstance().assertOneOrLess(Property.DESCRIPTION, getProperties());
michael@0 616 PropertyValidator.getInstance().assertOneOrLess(Property.DTSTART, getProperties());
michael@0 617 PropertyValidator.getInstance().assertOneOrLess(Property.DUE, getProperties());
michael@0 618 PropertyValidator.getInstance().assertOneOrLess(Property.DURATION, getProperties());
michael@0 619 PropertyValidator.getInstance().assertOneOrLess(Property.GEO, getProperties());
michael@0 620 PropertyValidator.getInstance().assertOneOrLess(Property.LAST_MODIFIED, getProperties());
michael@0 621 PropertyValidator.getInstance().assertOneOrLess(Property.LOCATION, getProperties());
michael@0 622 PropertyValidator.getInstance().assertOneOrLess(Property.PERCENT_COMPLETE, getProperties());
michael@0 623 PropertyValidator.getInstance().assertOneOrLess(Property.RECURRENCE_ID, getProperties());
michael@0 624 PropertyValidator.getInstance().assertOneOrLess(Property.RESOURCES, getProperties());
michael@0 625 PropertyValidator.getInstance().assertOneOrLess(Property.RRULE, getProperties());
michael@0 626 PropertyValidator.getInstance().assertOneOrLess(Property.SEQUENCE, getProperties());
michael@0 627 PropertyValidator.getInstance().assertOneOrLess(Property.STATUS, getProperties());
michael@0 628 PropertyValidator.getInstance().assertOneOrLess(Property.URL, getProperties());
michael@0 629
michael@0 630 for (final Iterator i = getAlarms().iterator(); i.hasNext();) {
michael@0 631 final VAlarm alarm = (VAlarm) i.next();
michael@0 632 alarm.validate(Method.COUNTER);
michael@0 633 }
michael@0 634 }
michael@0 635 }
michael@0 636
michael@0 637 /**
michael@0 638 * <pre>
michael@0 639 * Component/Property Presence
michael@0 640 * ------------------- ---------------------------------------------
michael@0 641 * METHOD 1 MUST be "DECLINECOUNTER"
michael@0 642 *
michael@0 643 * VTODO 1
michael@0 644 * ATTENDEE 1+ MUST for all attendees
michael@0 645 * DTSTAMP 1
michael@0 646 * ORGANIZER 1
michael@0 647 * SEQUENCE 1 MUST echo the original SEQUENCE number
michael@0 648 * UID 1 MUST echo original UID
michael@0 649 * ATTACH 0+
michael@0 650 * CATEGORIES 0 or 1 This property may contain a list of values
michael@0 651 * CLASS 0 or 1
michael@0 652 * COMMENT 0 or 1
michael@0 653 * CONTACT 0+
michael@0 654 * CREATED 0 or 1
michael@0 655 * DESCRIPTION 0 or 1
michael@0 656 * DTSTART 0 or 1
michael@0 657 * DUE 0 or 1 If present DURATION MUST NOT be present
michael@0 658 * DURATION 0 or 1 If present DUE MUST NOT be present
michael@0 659 * EXDATE 0+
michael@0 660 * EXRULE 0+
michael@0 661 * GEO 0 or 1
michael@0 662 * LAST-MODIFIED 0 or 1
michael@0 663 * LOCATION 0 or 1
michael@0 664 * PERCENT-COMPLETE 0 or 1
michael@0 665 * PRIORITY 0 or 1
michael@0 666 * RDATE 0+
michael@0 667 * RECURRENCE-ID 0 or 1 MUST only if referring to an instance of a
michael@0 668 * recurring calendar component. Otherwise
michael@0 669 * it MUST NOT be present.
michael@0 670 * RELATED-TO 0+
michael@0 671 * REQUEST-STATUS 0+
michael@0 672 * RESOURCES 0 or 1 This property MAY contain a list of values
michael@0 673 * RRULE 0+
michael@0 674 * STATUS 0 or 1 MAY be one of COMPLETED/NEEDS ACTION/IN-
michael@0 675 * PROCESS
michael@0 676 * URL 0 or 1
michael@0 677 * X-PROPERTY 0+
michael@0 678 *
michael@0 679 * VTIMEZONE 0+ MUST be present if any date/time refers to
michael@0 680 * a timezone
michael@0 681 * X-COMPONENT 0+
michael@0 682 *
michael@0 683 * VALARM 0
michael@0 684 * VEVENT 0
michael@0 685 * VFREEBUSY 0
michael@0 686 * </pre>
michael@0 687 *
michael@0 688 */
michael@0 689 private class DeclineCounterValidator implements Validator {
michael@0 690
michael@0 691 private static final long serialVersionUID = 1L;
michael@0 692
michael@0 693 public void validate() throws ValidationException {
michael@0 694 PropertyValidator.getInstance().assertOneOrMore(Property.ATTENDEE, getProperties());
michael@0 695
michael@0 696 PropertyValidator.getInstance().assertOne(Property.DTSTAMP, getProperties());
michael@0 697 PropertyValidator.getInstance().assertOne(Property.ORGANIZER, getProperties());
michael@0 698 PropertyValidator.getInstance().assertOne(Property.SEQUENCE, getProperties());
michael@0 699 PropertyValidator.getInstance().assertOne(Property.UID, getProperties());
michael@0 700
michael@0 701 PropertyValidator.getInstance().assertOneOrLess(Property.CATEGORIES, getProperties());
michael@0 702 PropertyValidator.getInstance().assertOneOrLess(Property.CLASS, getProperties());
michael@0 703 PropertyValidator.getInstance().assertOneOrLess(Property.COMMENT, getProperties());
michael@0 704 PropertyValidator.getInstance().assertOneOrLess(Property.CREATED, getProperties());
michael@0 705 PropertyValidator.getInstance().assertOneOrLess(Property.DESCRIPTION, getProperties());
michael@0 706 PropertyValidator.getInstance().assertOneOrLess(Property.DTSTART, getProperties());
michael@0 707 PropertyValidator.getInstance().assertOneOrLess(Property.DUE, getProperties());
michael@0 708 PropertyValidator.getInstance().assertOneOrLess(Property.DURATION, getProperties());
michael@0 709 PropertyValidator.getInstance().assertOneOrLess(Property.GEO, getProperties());
michael@0 710 PropertyValidator.getInstance().assertOneOrLess(Property.LAST_MODIFIED, getProperties());
michael@0 711 PropertyValidator.getInstance().assertOneOrLess(Property.LOCATION, getProperties());
michael@0 712 PropertyValidator.getInstance().assertOneOrLess(Property.PERCENT_COMPLETE, getProperties());
michael@0 713 PropertyValidator.getInstance().assertOneOrLess(Property.PRIORITY, getProperties());
michael@0 714 PropertyValidator.getInstance().assertOneOrLess(Property.RECURRENCE_ID, getProperties());
michael@0 715 PropertyValidator.getInstance().assertOneOrLess(Property.RESOURCES, getProperties());
michael@0 716 PropertyValidator.getInstance().assertOneOrLess(Property.STATUS, getProperties());
michael@0 717 PropertyValidator.getInstance().assertOneOrLess(Property.URL, getProperties());
michael@0 718
michael@0 719 ComponentValidator.assertNone(Component.VALARM, getAlarms());
michael@0 720 }
michael@0 721 }
michael@0 722
michael@0 723 /**
michael@0 724 * <pre>
michael@0 725 * Component/Property Presence
michael@0 726 * ------------------- ----------------------------------------------
michael@0 727 * METHOD 1 MUST be "PUBLISH"
michael@0 728 * VTODO 1+
michael@0 729 * DTSTAMP 1
michael@0 730 * DTSTART 1
michael@0 731 * ORGANIZER 1
michael@0 732 * PRIORITY 1
michael@0 733 * SEQUENCE 0 or 1 MUST be present if value is greater than
michael@0 734 * 0, MAY be present if 0
michael@0 735 * SUMMARY 1 Can be null.
michael@0 736 * UID 1
michael@0 737 *
michael@0 738 * ATTACH 0+
michael@0 739 * CATEGORIES 0 or 1 This property may contain a list of values
michael@0 740 * CLASS 0 or 1
michael@0 741 * COMMENT 0 or 1
michael@0 742 * CONTACT 0+
michael@0 743 * CREATED 0 or 1
michael@0 744 * DESCRIPTION 0 or 1 Can be null
michael@0 745 * DUE 0 or 1 If present DURATION MUST NOT be present
michael@0 746 * DURATION 0 or 1 If present DUE MUST NOT be present
michael@0 747 * EXDATE 0+
michael@0 748 * EXRULE 0+
michael@0 749 * GEO 0 or 1
michael@0 750 * LAST-MODIFIED 0 or 1
michael@0 751 * LOCATION 0 or 1
michael@0 752 * PERCENT-COMPLETE 0 or 1
michael@0 753 * RDATE 0+
michael@0 754 * RECURRENCE-ID 0 or 1 MUST only if referring to an instance of a
michael@0 755 * recurring calendar component. Otherwise
michael@0 756 * it MUST NOT be present.
michael@0 757 *
michael@0 758 * RELATED-TO 0+
michael@0 759 * RESOURCES 0 or 1 This property may contain a list of values
michael@0 760 * RRULE 0+
michael@0 761 * STATUS 0 or 1 MAY be one of COMPLETED/NEEDS ACTION/IN-
michael@0 762 * PROCESS/CANCELLED
michael@0 763 * URL 0 or 1
michael@0 764 * X-PROPERTY 0+
michael@0 765 *
michael@0 766 * ATTENDEE 0
michael@0 767 * REQUEST-STATUS 0
michael@0 768 *
michael@0 769 * VTIMEZONE 0+ MUST be present if any date/time refers to
michael@0 770 * a timezone
michael@0 771 * VALARM 0+
michael@0 772 * X-COMPONENT 0+
michael@0 773 *
michael@0 774 * VFREEBUSY 0
michael@0 775 * VEVENT 0
michael@0 776 * VJOURNAL 0
michael@0 777 * </pre>
michael@0 778 *
michael@0 779 */
michael@0 780 private class PublishValidator implements Validator {
michael@0 781
michael@0 782 private static final long serialVersionUID = 1L;
michael@0 783
michael@0 784 public void validate() throws ValidationException {
michael@0 785 PropertyValidator.getInstance().assertOne(Property.DTSTAMP, getProperties());
michael@0 786
michael@0 787 if (!CompatibilityHints.isHintEnabled(CompatibilityHints.KEY_RELAXED_VALIDATION)) {
michael@0 788 PropertyValidator.getInstance().assertOne(Property.ORGANIZER, getProperties());
michael@0 789 PropertyValidator.getInstance().assertOne(Property.PRIORITY, getProperties());
michael@0 790 }
michael@0 791
michael@0 792 PropertyValidator.getInstance().assertOne(Property.SUMMARY, getProperties());
michael@0 793 PropertyValidator.getInstance().assertOne(Property.UID, getProperties());
michael@0 794
michael@0 795 // DTSTART: RFC2446 conflicts with RCF2445..
michael@0 796 PropertyValidator.getInstance().assertOneOrLess(Property.DTSTART, getProperties());
michael@0 797 PropertyValidator.getInstance().assertOneOrLess(Property.SEQUENCE, getProperties());
michael@0 798 PropertyValidator.getInstance().assertOneOrLess(Property.CATEGORIES, getProperties());
michael@0 799 PropertyValidator.getInstance().assertOneOrLess(Property.CLASS, getProperties());
michael@0 800 PropertyValidator.getInstance().assertOneOrLess(Property.COMMENT, getProperties());
michael@0 801 PropertyValidator.getInstance().assertOneOrLess(Property.CREATED, getProperties());
michael@0 802 PropertyValidator.getInstance().assertOneOrLess(Property.DESCRIPTION, getProperties());
michael@0 803 PropertyValidator.getInstance().assertOneOrLess(Property.DUE, getProperties());
michael@0 804 PropertyValidator.getInstance().assertOneOrLess(Property.DURATION, getProperties());
michael@0 805 PropertyValidator.getInstance().assertOneOrLess(Property.GEO, getProperties());
michael@0 806 PropertyValidator.getInstance().assertOneOrLess(Property.LAST_MODIFIED, getProperties());
michael@0 807 PropertyValidator.getInstance().assertOneOrLess(Property.LOCATION, getProperties());
michael@0 808 PropertyValidator.getInstance().assertOneOrLess(Property.PERCENT_COMPLETE, getProperties());
michael@0 809 PropertyValidator.getInstance().assertOneOrLess(Property.RECURRENCE_ID, getProperties());
michael@0 810 PropertyValidator.getInstance().assertOneOrLess(Property.RESOURCES, getProperties());
michael@0 811 PropertyValidator.getInstance().assertOneOrLess(Property.STATUS, getProperties());
michael@0 812 PropertyValidator.getInstance().assertOneOrLess(Property.URL, getProperties());
michael@0 813
michael@0 814 PropertyValidator.getInstance().assertNone(Property.ATTENDEE, getProperties());
michael@0 815 PropertyValidator.getInstance().assertNone(Property.REQUEST_STATUS, getProperties());
michael@0 816
michael@0 817 for (final Iterator i = getAlarms().iterator(); i.hasNext();) {
michael@0 818 final VAlarm alarm = (VAlarm) i.next();
michael@0 819 alarm.validate(Method.PUBLISH);
michael@0 820 }
michael@0 821 }
michael@0 822 }
michael@0 823
michael@0 824 /**
michael@0 825 * <pre>
michael@0 826 * Component/Property Presence
michael@0 827 * ------------------- ---------------------------------------------
michael@0 828 * METHOD 1 MUST be "REFRESH"
michael@0 829 * VTODO 1
michael@0 830 * ATTENDEE 1
michael@0 831 * DTSTAMP 1
michael@0 832 * UID 1 MUST echo original UID
michael@0 833 *
michael@0 834 * RECURRENCE-ID 0 or 1 MUST only if referring to an instance of a
michael@0 835 * Recurring calendar component. Otherwise it
michael@0 836 * MUST NOT be present
michael@0 837 * X-PROPERTY 0+
michael@0 838 *
michael@0 839 * ATTACH 0
michael@0 840 * CATEGORIES 0
michael@0 841 * CLASS 0
michael@0 842 * COMMENT 0
michael@0 843 * CONTACT 0
michael@0 844 * CREATED 0
michael@0 845 * DESCRIPTION 0
michael@0 846 * DTSTART 0
michael@0 847 * DUE 0
michael@0 848 * DURATION 0
michael@0 849 * EXDATE 0
michael@0 850 * EXRULE 0
michael@0 851 * GEO 0
michael@0 852 * LAST-MODIFIED 0
michael@0 853 * LOCATION 0
michael@0 854 * ORGANIZER 0
michael@0 855 * PERCENT-COMPLETE 0
michael@0 856 * PRIORITY 0
michael@0 857 * RDATE 0
michael@0 858 * RELATED-TO 0
michael@0 859 * REQUEST-STATUS 0
michael@0 860 * RESOURCES 0
michael@0 861 * RRULE 0
michael@0 862 * SEQUENCE 0
michael@0 863 * STATUS 0
michael@0 864 * URL 0
michael@0 865 *
michael@0 866 * X-COMPONENT 0+
michael@0 867 *
michael@0 868 * VALARM 0
michael@0 869 * VEVENT 0
michael@0 870 * VFREEBUSY 0
michael@0 871 * VTIMEZONE 0
michael@0 872 * </pre>
michael@0 873 *
michael@0 874 */
michael@0 875 private class RefreshValidator implements Validator {
michael@0 876
michael@0 877 private static final long serialVersionUID = 1L;
michael@0 878
michael@0 879 public void validate() throws ValidationException {
michael@0 880 PropertyValidator.getInstance().assertOne(Property.ATTENDEE, getProperties());
michael@0 881 PropertyValidator.getInstance().assertOne(Property.DTSTAMP, getProperties());
michael@0 882 PropertyValidator.getInstance().assertOne(Property.UID, getProperties());
michael@0 883
michael@0 884 PropertyValidator.getInstance().assertOneOrLess(Property.RECURRENCE_ID, getProperties());
michael@0 885
michael@0 886 PropertyValidator.getInstance().assertNone(Property.ATTACH, getProperties());
michael@0 887 PropertyValidator.getInstance().assertNone(Property.CATEGORIES, getProperties());
michael@0 888 PropertyValidator.getInstance().assertNone(Property.CLASS, getProperties());
michael@0 889 PropertyValidator.getInstance().assertNone(Property.COMMENT, getProperties());
michael@0 890 PropertyValidator.getInstance().assertNone(Property.CONTACT, getProperties());
michael@0 891 PropertyValidator.getInstance().assertNone(Property.CREATED, getProperties());
michael@0 892 PropertyValidator.getInstance().assertNone(Property.DESCRIPTION, getProperties());
michael@0 893 PropertyValidator.getInstance().assertNone(Property.DTSTART, getProperties());
michael@0 894 PropertyValidator.getInstance().assertNone(Property.DUE, getProperties());
michael@0 895 PropertyValidator.getInstance().assertNone(Property.DURATION, getProperties());
michael@0 896 PropertyValidator.getInstance().assertNone(Property.EXDATE, getProperties());
michael@0 897 PropertyValidator.getInstance().assertNone(Property.EXRULE, getProperties());
michael@0 898 PropertyValidator.getInstance().assertNone(Property.GEO, getProperties());
michael@0 899 PropertyValidator.getInstance().assertNone(Property.LAST_MODIFIED, getProperties());
michael@0 900 PropertyValidator.getInstance().assertNone(Property.LOCATION, getProperties());
michael@0 901 PropertyValidator.getInstance().assertNone(Property.ORGANIZER, getProperties());
michael@0 902 PropertyValidator.getInstance().assertNone(Property.PERCENT_COMPLETE, getProperties());
michael@0 903 PropertyValidator.getInstance().assertNone(Property.PRIORITY, getProperties());
michael@0 904 PropertyValidator.getInstance().assertNone(Property.RDATE, getProperties());
michael@0 905 PropertyValidator.getInstance().assertNone(Property.RELATED_TO, getProperties());
michael@0 906 PropertyValidator.getInstance().assertNone(Property.REQUEST_STATUS, getProperties());
michael@0 907 PropertyValidator.getInstance().assertNone(Property.RESOURCES, getProperties());
michael@0 908 PropertyValidator.getInstance().assertNone(Property.RRULE, getProperties());
michael@0 909 PropertyValidator.getInstance().assertNone(Property.SEQUENCE, getProperties());
michael@0 910 PropertyValidator.getInstance().assertNone(Property.STATUS, getProperties());
michael@0 911 PropertyValidator.getInstance().assertNone(Property.URL, getProperties());
michael@0 912
michael@0 913 ComponentValidator.assertNone(Component.VALARM, getAlarms());
michael@0 914 }
michael@0 915 }
michael@0 916
michael@0 917 /**
michael@0 918 * <pre>
michael@0 919 * Component/Property Presence
michael@0 920 * ------------------- ---------------------------------------------
michael@0 921 * METHOD 1 MUST be "REPLY"
michael@0 922 * VTODO 1+ All component MUST have the same UID
michael@0 923 * ATTENDEE 1+
michael@0 924 * DTSTAMP 1
michael@0 925 * ORGANIZER 1
michael@0 926 * UID 1 MUST must be the address of the replying
michael@0 927 * attendee
michael@0 928 * REQUEST-STATUS 0+
michael@0 929 * ATTACH 0+
michael@0 930 * CATEGORIES 0 or 1 This property may contain a list of values
michael@0 931 * CLASS 0 or 1
michael@0 932 * COMMENT 0 or 1
michael@0 933 * CONTACT 0+
michael@0 934 * CREATED 0 or 1
michael@0 935 * DESCRIPTION 0 or 1
michael@0 936 * DTSTART 0 or 1
michael@0 937 * DUE 0 or 1 If present DURATION MUST NOT be present
michael@0 938 * DURATION 0 or 1 If present DUE MUST NOT be present
michael@0 939 * EXDATE 0+
michael@0 940 * EXRULE 0+
michael@0 941 * GEO 0 or 1
michael@0 942 * LAST-MODIFIED 0 or 1
michael@0 943 * LOCATION 0 or 1
michael@0 944 * PERCENT-COMPLETE 0 or 1
michael@0 945 * PRIORITY 0 or 1
michael@0 946 * RDATE 0+
michael@0 947 * RELATED-TO 0+
michael@0 948 * RESOURCES 0 or 1 This property may contain a list of values
michael@0 949 * RRULE 0+
michael@0 950 * RECURRENCE-ID 0 or 1 MUST only if referring to an instance of a
michael@0 951 * Recurring calendar component. Otherwise it
michael@0 952 * MUST NOT be present
michael@0 953 * SEQUENCE 0 or 1 MUST be the sequence number of
michael@0 954 * the original REQUEST if greater than 0.
michael@0 955 * MAY be present if 0.
michael@0 956 * STATUS 0 or 1
michael@0 957 * SUMMARY 0 or 1 Can be null
michael@0 958 * URL 0 or 1
michael@0 959 * X-PROPERTY 0+
michael@0 960 *
michael@0 961 * VTIMEZONE 0 or 1 MUST be present if any date/time refers to
michael@0 962 * a timezone
michael@0 963 * X-COMPONENT 0+
michael@0 964 *
michael@0 965 * VALARM 0
michael@0 966 * VEVENT 0
michael@0 967 * VFREEBUSY 0
michael@0 968 * </pre>
michael@0 969 *
michael@0 970 */
michael@0 971 private class ReplyValidator implements Validator {
michael@0 972
michael@0 973 private static final long serialVersionUID = 1L;
michael@0 974
michael@0 975 public void validate() throws ValidationException {
michael@0 976 PropertyValidator.getInstance().assertOneOrMore(Property.ATTENDEE, getProperties());
michael@0 977
michael@0 978 PropertyValidator.getInstance().assertOne(Property.DTSTAMP, getProperties());
michael@0 979 PropertyValidator.getInstance().assertOne(Property.ORGANIZER, getProperties());
michael@0 980 PropertyValidator.getInstance().assertOne(Property.UID, getProperties());
michael@0 981
michael@0 982 PropertyValidator.getInstance().assertOneOrLess(Property.CATEGORIES, getProperties());
michael@0 983 PropertyValidator.getInstance().assertOneOrLess(Property.CLASS, getProperties());
michael@0 984 PropertyValidator.getInstance().assertOneOrLess(Property.COMMENT, getProperties());
michael@0 985 PropertyValidator.getInstance().assertOneOrLess(Property.CREATED, getProperties());
michael@0 986 PropertyValidator.getInstance().assertOneOrLess(Property.DESCRIPTION, getProperties());
michael@0 987 PropertyValidator.getInstance().assertOneOrLess(Property.DTSTART, getProperties());
michael@0 988 PropertyValidator.getInstance().assertOneOrLess(Property.DUE, getProperties());
michael@0 989 PropertyValidator.getInstance().assertOneOrLess(Property.DURATION, getProperties());
michael@0 990 PropertyValidator.getInstance().assertOneOrLess(Property.GEO, getProperties());
michael@0 991 PropertyValidator.getInstance().assertOneOrLess(Property.LAST_MODIFIED, getProperties());
michael@0 992 PropertyValidator.getInstance().assertOneOrLess(Property.LOCATION, getProperties());
michael@0 993 PropertyValidator.getInstance().assertOneOrLess(Property.PERCENT_COMPLETE, getProperties());
michael@0 994 PropertyValidator.getInstance().assertOneOrLess(Property.PRIORITY, getProperties());
michael@0 995 PropertyValidator.getInstance().assertOneOrLess(Property.RESOURCES, getProperties());
michael@0 996 PropertyValidator.getInstance().assertOneOrLess(Property.RECURRENCE_ID, getProperties());
michael@0 997 PropertyValidator.getInstance().assertOneOrLess(Property.SEQUENCE, getProperties());
michael@0 998 PropertyValidator.getInstance().assertOneOrLess(Property.STATUS, getProperties());
michael@0 999 PropertyValidator.getInstance().assertOneOrLess(Property.SUMMARY, getProperties());
michael@0 1000 PropertyValidator.getInstance().assertOneOrLess(Property.URL, getProperties());
michael@0 1001
michael@0 1002 ComponentValidator.assertNone(Component.VALARM, getAlarms());
michael@0 1003 }
michael@0 1004 }
michael@0 1005
michael@0 1006 /**
michael@0 1007 * <pre>
michael@0 1008 * Component/Property Presence
michael@0 1009 * ------------------- ----------------------------------------------
michael@0 1010 * METHOD 1 MUST be "REQUEST"
michael@0 1011 * VTODO 1+ All components must have the same UID
michael@0 1012 * ATTENDEE 1+
michael@0 1013 * DTSTAMP 1
michael@0 1014 * DTSTART 1
michael@0 1015 * ORGANIZER 1
michael@0 1016 * PRIORITY 1
michael@0 1017 * SEQUENCE 0 or 1 MUST be present if value is greater than
michael@0 1018 * 0, MAY be present if 0
michael@0 1019 * SUMMARY 1 Can be null.
michael@0 1020 * UID 1
michael@0 1021 *
michael@0 1022 * ATTACH 0+
michael@0 1023 * CATEGORIES 0 or 1 This property may contain a list of
michael@0 1024 * values
michael@0 1025 * CLASS 0 or 1
michael@0 1026 * COMMENT 0 or 1
michael@0 1027 * CONTACT 0+
michael@0 1028 * CREATED 0 or 1
michael@0 1029 * DESCRIPTION 0 or 1 Can be null
michael@0 1030 * DUE 0 or 1 If present DURATION MUST NOT be present
michael@0 1031 * DURATION 0 or 1 If present DUE MUST NOT be present
michael@0 1032 * EXDATE 0+
michael@0 1033 * EXRULE 0+
michael@0 1034 * GEO 0 or 1
michael@0 1035 * LAST-MODIFIED 0 or 1
michael@0 1036 * LOCATION 0 or 1
michael@0 1037 * PERCENT-COMPLETE 0 or 1
michael@0 1038 * RDATE 0+
michael@0 1039 * RECURRENCE-ID 0 or 1 present if referring to an instance of a
michael@0 1040 * recurring calendar component. Otherwise
michael@0 1041 * it MUST NOT be present.
michael@0 1042 * RELATED-TO 0+
michael@0 1043 * RESOURCES 0 or 1 This property may contain a list of
michael@0 1044 * values
michael@0 1045 * RRULE 0+
michael@0 1046 * STATUS 0 or 1 MAY be one of COMPLETED/NEEDS ACTION/IN-
michael@0 1047 * PROCESS
michael@0 1048 * URL 0 or 1
michael@0 1049 * X-PROPERTY 0+
michael@0 1050 *
michael@0 1051 * REQUEST-STATUS 0
michael@0 1052 *
michael@0 1053 * VALARM 0+
michael@0 1054 *
michael@0 1055 * VTIMEZONE 0+ MUST be present if any date/time refers
michael@0 1056 * to a timezone
michael@0 1057 * X-COMPONENT 0+
michael@0 1058 *
michael@0 1059 * VEVENT 0
michael@0 1060 * VFREEBUSY 0
michael@0 1061 * VJOURNAL 0
michael@0 1062 * </pre>
michael@0 1063 *
michael@0 1064 */
michael@0 1065 private class RequestValidator implements Validator {
michael@0 1066
michael@0 1067 private static final long serialVersionUID = 1L;
michael@0 1068
michael@0 1069 public void validate() throws ValidationException {
michael@0 1070 PropertyValidator.getInstance().assertOneOrMore(Property.ATTENDEE, getProperties());
michael@0 1071
michael@0 1072 PropertyValidator.getInstance().assertOne(Property.DTSTAMP, getProperties());
michael@0 1073 PropertyValidator.getInstance().assertOne(Property.DTSTART, getProperties());
michael@0 1074 PropertyValidator.getInstance().assertOne(Property.ORGANIZER, getProperties());
michael@0 1075 PropertyValidator.getInstance().assertOne(Property.PRIORITY, getProperties());
michael@0 1076 PropertyValidator.getInstance().assertOne(Property.SUMMARY, getProperties());
michael@0 1077 PropertyValidator.getInstance().assertOne(Property.UID, getProperties());
michael@0 1078
michael@0 1079 PropertyValidator.getInstance().assertOneOrLess(Property.SEQUENCE, getProperties());
michael@0 1080 PropertyValidator.getInstance().assertOneOrLess(Property.CATEGORIES, getProperties());
michael@0 1081 PropertyValidator.getInstance().assertOneOrLess(Property.CLASS, getProperties());
michael@0 1082 PropertyValidator.getInstance().assertOneOrLess(Property.COMMENT, getProperties());
michael@0 1083 PropertyValidator.getInstance().assertOneOrLess(Property.CREATED, getProperties());
michael@0 1084 PropertyValidator.getInstance().assertOneOrLess(Property.DESCRIPTION, getProperties());
michael@0 1085 PropertyValidator.getInstance().assertOneOrLess(Property.DUE, getProperties());
michael@0 1086 PropertyValidator.getInstance().assertOneOrLess(Property.DURATION, getProperties());
michael@0 1087 PropertyValidator.getInstance().assertOneOrLess(Property.GEO, getProperties());
michael@0 1088 PropertyValidator.getInstance().assertOneOrLess(Property.LAST_MODIFIED, getProperties());
michael@0 1089 PropertyValidator.getInstance().assertOneOrLess(Property.LOCATION, getProperties());
michael@0 1090 PropertyValidator.getInstance().assertOneOrLess(Property.PERCENT_COMPLETE, getProperties());
michael@0 1091 PropertyValidator.getInstance().assertOneOrLess(Property.RECURRENCE_ID, getProperties());
michael@0 1092 PropertyValidator.getInstance().assertOneOrLess(Property.RESOURCES, getProperties());
michael@0 1093 PropertyValidator.getInstance().assertOneOrLess(Property.STATUS, getProperties());
michael@0 1094 PropertyValidator.getInstance().assertOneOrLess(Property.URL, getProperties());
michael@0 1095
michael@0 1096 PropertyValidator.getInstance().assertNone(Property.REQUEST_STATUS, getProperties());
michael@0 1097
michael@0 1098 for (final Iterator i = getAlarms().iterator(); i.hasNext();) {
michael@0 1099 final VAlarm alarm = (VAlarm) i.next();
michael@0 1100 alarm.validate(Method.REQUEST);
michael@0 1101 }
michael@0 1102 }
michael@0 1103 }
michael@0 1104
michael@0 1105 /**
michael@0 1106 * @return the optional access classification property
michael@0 1107 */
michael@0 1108 public final Clazz getClassification() {
michael@0 1109 return (Clazz) getProperty(Property.CLASS);
michael@0 1110 }
michael@0 1111
michael@0 1112 /**
michael@0 1113 * @return the optional date completed property
michael@0 1114 */
michael@0 1115 public final Completed getDateCompleted() {
michael@0 1116 return (Completed) getProperty(Property.COMPLETED);
michael@0 1117 }
michael@0 1118
michael@0 1119 /**
michael@0 1120 * @return the optional creation-time property
michael@0 1121 */
michael@0 1122 public final Created getCreated() {
michael@0 1123 return (Created) getProperty(Property.CREATED);
michael@0 1124 }
michael@0 1125
michael@0 1126 /**
michael@0 1127 * @return the optional description property
michael@0 1128 */
michael@0 1129 public final Description getDescription() {
michael@0 1130 return (Description) getProperty(Property.DESCRIPTION);
michael@0 1131 }
michael@0 1132
michael@0 1133 /**
michael@0 1134 * Convenience method to pull the DTSTART out of the property list.
michael@0 1135 * @return The DtStart object representation of the start Date
michael@0 1136 */
michael@0 1137 public final DtStart getStartDate() {
michael@0 1138 return (DtStart) getProperty(Property.DTSTART);
michael@0 1139 }
michael@0 1140
michael@0 1141 /**
michael@0 1142 * @return the optional geographic position property
michael@0 1143 */
michael@0 1144 public final Geo getGeographicPos() {
michael@0 1145 return (Geo) getProperty(Property.GEO);
michael@0 1146 }
michael@0 1147
michael@0 1148 /**
michael@0 1149 * @return the optional last-modified property
michael@0 1150 */
michael@0 1151 public final LastModified getLastModified() {
michael@0 1152 return (LastModified) getProperty(Property.LAST_MODIFIED);
michael@0 1153 }
michael@0 1154
michael@0 1155 /**
michael@0 1156 * @return the optional location property
michael@0 1157 */
michael@0 1158 public final Location getLocation() {
michael@0 1159 return (Location) getProperty(Property.LOCATION);
michael@0 1160 }
michael@0 1161
michael@0 1162 /**
michael@0 1163 * @return the optional organizer property
michael@0 1164 */
michael@0 1165 public final Organizer getOrganizer() {
michael@0 1166 return (Organizer) getProperty(Property.ORGANIZER);
michael@0 1167 }
michael@0 1168
michael@0 1169 /**
michael@0 1170 * @return the optional percentage complete property
michael@0 1171 */
michael@0 1172 public final PercentComplete getPercentComplete() {
michael@0 1173 return (PercentComplete) getProperty(Property.PERCENT_COMPLETE);
michael@0 1174 }
michael@0 1175
michael@0 1176 /**
michael@0 1177 * @return the optional priority property
michael@0 1178 */
michael@0 1179 public final Priority getPriority() {
michael@0 1180 return (Priority) getProperty(Property.PRIORITY);
michael@0 1181 }
michael@0 1182
michael@0 1183 /**
michael@0 1184 * @return the optional date-stamp property
michael@0 1185 */
michael@0 1186 public final DtStamp getDateStamp() {
michael@0 1187 return (DtStamp) getProperty(Property.DTSTAMP);
michael@0 1188 }
michael@0 1189
michael@0 1190 /**
michael@0 1191 * @return the optional sequence number property
michael@0 1192 */
michael@0 1193 public final Sequence getSequence() {
michael@0 1194 return (Sequence) getProperty(Property.SEQUENCE);
michael@0 1195 }
michael@0 1196
michael@0 1197 /**
michael@0 1198 * @return the optional status property
michael@0 1199 */
michael@0 1200 public final Status getStatus() {
michael@0 1201 return (Status) getProperty(Property.STATUS);
michael@0 1202 }
michael@0 1203
michael@0 1204 /**
michael@0 1205 * @return the optional summary property
michael@0 1206 */
michael@0 1207 public final Summary getSummary() {
michael@0 1208 return (Summary) getProperty(Property.SUMMARY);
michael@0 1209 }
michael@0 1210
michael@0 1211 /**
michael@0 1212 * @return the optional URL property
michael@0 1213 */
michael@0 1214 public final Url getUrl() {
michael@0 1215 return (Url) getProperty(Property.URL);
michael@0 1216 }
michael@0 1217
michael@0 1218 /**
michael@0 1219 * @return the optional recurrence identifier property
michael@0 1220 */
michael@0 1221 public final RecurrenceId getRecurrenceId() {
michael@0 1222 return (RecurrenceId) getProperty(Property.RECURRENCE_ID);
michael@0 1223 }
michael@0 1224
michael@0 1225 /**
michael@0 1226 * @return the optional Duration property
michael@0 1227 */
michael@0 1228 public final Duration getDuration() {
michael@0 1229 return (Duration) getProperty(Property.DURATION);
michael@0 1230 }
michael@0 1231
michael@0 1232 /**
michael@0 1233 * @return the optional due property
michael@0 1234 */
michael@0 1235 public final Due getDue() {
michael@0 1236 return (Due) getProperty(Property.DUE);
michael@0 1237 }
michael@0 1238
michael@0 1239 /**
michael@0 1240 * Returns the UID property of this component if available.
michael@0 1241 * @return a Uid instance, or null if no UID property exists
michael@0 1242 */
michael@0 1243 public final Uid getUid() {
michael@0 1244 return (Uid) getProperty(Property.UID);
michael@0 1245 }
michael@0 1246
michael@0 1247 /**
michael@0 1248 * {@inheritDoc}
michael@0 1249 */
michael@0 1250 public boolean equals(final Object arg0) {
michael@0 1251 if (arg0 instanceof VToDo) {
michael@0 1252 return super.equals(arg0)
michael@0 1253 && ObjectUtils.equals(alarms, ((VToDo) arg0).getAlarms());
michael@0 1254 }
michael@0 1255 return super.equals(arg0);
michael@0 1256 }
michael@0 1257
michael@0 1258 /**
michael@0 1259 * {@inheritDoc}
michael@0 1260 */
michael@0 1261 public int hashCode() {
michael@0 1262 return new HashCodeBuilder().append(getName()).append(getProperties())
michael@0 1263 .append(getAlarms()).toHashCode();
michael@0 1264 }
michael@0 1265
michael@0 1266 /**
michael@0 1267 * Overrides default copy method to add support for copying alarm sub-components.
michael@0 1268 * @return a copy of the instance
michael@0 1269 * @throws ParseException where an error occurs parsing data
michael@0 1270 * @throws IOException where an error occurs reading data
michael@0 1271 * @throws URISyntaxException where an invalid URI is encountered
michael@0 1272 * @see net.fortuna.ical4j.model.Component#copy()
michael@0 1273 */
michael@0 1274 public Component copy() throws ParseException, IOException, URISyntaxException {
michael@0 1275 final VToDo copy = (VToDo) super.copy();
michael@0 1276 copy.alarms = new ComponentList(alarms);
michael@0 1277 return copy;
michael@0 1278 }
michael@0 1279 }

mercurial