001package biweekly.property; 002 003import java.util.Date; 004import java.util.List; 005 006import biweekly.Warning; 007import biweekly.component.ICalComponent; 008import biweekly.component.VTimezone; 009import biweekly.util.ICalDateFormat; 010 011/* 012 Copyright (c) 2013, 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(true); 049 * Date datetime1 = ...; 050 * exdate.addValue(datetime1); 051 * Date datetime2 = ...; 052 * exdate.addValue(datetime2); 053 * event.addExceptionDates(exdate); 054 * 055 * //dates without time components 056 * exdate = new ExceptionDates(false); 057 * Date date1 = ...; 058 * exdate.addValue(date1); 059 * Date date2 = ...; 060 * exdate.addValue(date2); 061 * event.addExceptionDates(exdate); 062 * </pre> 063 * 064 * </p> 065 * @author Michael Angstadt 066 * @see <a href="http://tools.ietf.org/html/rfc5545#page-118">RFC 5545 067 * p.118-20</a> 068 */ 069public class ExceptionDates extends ListProperty<Date> { 070 private boolean hasTime = true; 071 072 /** 073 * Creates an exception dates property. 074 * @param hasTime true if the dates have a time component, false if they are 075 * strictly dates 076 */ 077 public ExceptionDates(boolean hasTime) { 078 setHasTime(hasTime); 079 } 080 081 /** 082 * Gets whether the dates have time components. 083 * @return true if the dates have time components, false if they are 084 * strictly dates 085 */ 086 public boolean hasTime() { 087 return hasTime; 088 } 089 090 /** 091 * Sets whether the dates have time components. 092 * @param hasTime true if the dates have time components, false if they are 093 * strictly dates 094 */ 095 public void setHasTime(boolean hasTime) { 096 this.hasTime = hasTime; 097 } 098 099 @Override 100 public String getTimezoneId() { 101 return super.getTimezoneId(); 102 } 103 104 @Override 105 public void setTimezoneId(String timezoneId) { 106 super.setTimezoneId(timezoneId); 107 } 108 109 @Override 110 public void setTimezone(VTimezone timezone) { 111 super.setTimezone(timezone); 112 } 113 114 @Override 115 protected void validate(List<ICalComponent> components, List<Warning> warnings) { 116 super.validate(components, warnings); 117 118 String tzid = getTimezoneId(); 119 if (tzid != null && tzid.contains("/") && ICalDateFormat.parseTimeZoneId(tzid) == null) { 120 warnings.add(Warning.validate(27, tzid)); 121 } 122 } 123}