001package biweekly.property; 002 003import java.util.Date; 004import java.util.List; 005 006import biweekly.ICalVersion; 007import biweekly.Warning; 008import biweekly.component.ICalComponent; 009import biweekly.util.ICalDate; 010 011/* 012 Copyright (c) 2013-2015, Michael Angstadt 013 All rights reserved. 014 015 Redistribution and use in source and binary forms, with or without 016 modification, are permitted provided that the following conditions are met: 017 018 1. Redistributions of source code must retain the above copyright notice, this 019 list of conditions and the following disclaimer. 020 2. Redistributions in binary form must reproduce the above copyright notice, 021 this list of conditions and the following disclaimer in the documentation 022 and/or other materials provided with the distribution. 023 024 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 025 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 026 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 027 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 028 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 029 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 030 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 031 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 032 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 033 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 034 */ 035 036/** 037 * <p> 038 * Defines a list of exceptions to the dates specified in the 039 * {@link RecurrenceRule} property. 040 * </p> 041 * <p> 042 * <b>Code sample:</b> 043 * 044 * <pre class="brush:java"> 045 * VEvent event = new VEvent(); 046 * 047 * //dates with time components 048 * ExceptionDates exdate = new ExceptionDates(); 049 * Date datetime = ... 050 * exdate.addValue(new ICalDate(datetime, true)); 051 * event.addExceptionDates(exdate); 052 * 053 * //dates without time components 054 * exdate = new ExceptionDates(); 055 * Date date = ... 056 * exdate.addValue(new ICalDate(date, false)); 057 * event.addExceptionDates(exdate); 058 * </pre> 059 * 060 * </p> 061 * @author Michael Angstadt 062 * @see <a href="http://tools.ietf.org/html/rfc5545#page-118">RFC 5545 063 * p.118-20</a> 064 * @see <a href="http://tools.ietf.org/html/rfc2445#page-112">RFC 2445 065 * p.112-4</a> 066 * @see <a href="http://www.imc.org/pdi/vcal-10.doc">vCal 1.0 p.31</a> 067 */ 068public class ExceptionDates extends ListProperty<ICalDate> { 069 /** 070 * Adds a value to this property. 071 * @param value the value to add 072 */ 073 public void addValue(Date value) { 074 addValue(new ICalDate(value)); 075 } 076 077 @Override 078 protected void validate(List<ICalComponent> components, ICalVersion version, List<Warning> warnings) { 079 super.validate(components, version, warnings); 080 081 List<ICalDate> dates = getValues(); 082 if (dates.isEmpty()) { 083 return; 084 } 085 086 //can't mix date and date-time values 087 boolean hasTime = dates.get(0).hasTime(); 088 for (ICalDate date : dates.subList(1, dates.size())) { 089 if (date.hasTime() != hasTime) { 090 warnings.add(Warning.validate(50)); 091 break; 092 } 093 } 094 } 095}