001 package biweekly.property;
002
003 import java.util.Date;
004 import java.util.List;
005
006 import biweekly.Warning;
007 import biweekly.component.ICalComponent;
008 import biweekly.component.VTimezone;
009 import biweekly.util.ICalDateFormatter;
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 recurrence rule defined in a component.
039 * </p>
040 * <p>
041 * <b>Examples:</b>
042 *
043 * <pre class="brush:java">
044 * //date and times
045 * ExceptionDates exdate = new ExceptionDates(true);
046 * Date datetime1 = ...;
047 * exdate.addValue(datetime1);
048 * Date datetime2 = ...;
049 * exdate.addValue(datetime2);
050 *
051 * //dates
052 * ExceptionDates exdate = new ExceptionDates(false);
053 * Date date1 = ...;
054 * exdate.addValue(date1);
055 * Date date2 = ...;
056 * exdate.addValue(date2);
057 * </pre>
058 *
059 * </p>
060 * @author Michael Angstadt
061 * @rfc 5545 p.118-20
062 */
063 public class ExceptionDates extends ListProperty<Date> {
064 private boolean hasTime = true;
065
066 /**
067 * Creates an exception dates property.
068 * @param hasTime true if the dates have a time component, false if they are
069 * strictly dates
070 */
071 public ExceptionDates(boolean hasTime) {
072 setHasTime(hasTime);
073 }
074
075 /**
076 * Gets whether the dates have time components.
077 * @return true if the dates have time components, false if they are
078 * strictly dates
079 */
080 public boolean hasTime() {
081 return hasTime;
082 }
083
084 /**
085 * Sets whether the dates have time components.
086 * @param hasTime true if the dates have time components, false if they are
087 * strictly dates
088 */
089 public void setHasTime(boolean hasTime) {
090 this.hasTime = hasTime;
091 }
092
093 @Override
094 public String getTimezoneId() {
095 return super.getTimezoneId();
096 }
097
098 @Override
099 public void setTimezoneId(String timezoneId) {
100 super.setTimezoneId(timezoneId);
101 }
102
103 @Override
104 public void setTimezone(VTimezone timezone) {
105 super.setTimezone(timezone);
106 }
107
108 @Override
109 protected void validate(List<ICalComponent> components, List<Warning> warnings) {
110 String tzid = getTimezoneId();
111 if (tzid != null && tzid.contains("/") && ICalDateFormatter.parseTimeZoneId(tzid) == null) {
112 warnings.add(Warning.validate(27, tzid));
113 }
114 }
115 }