001package biweekly.io;
002
003import java.util.ArrayList;
004import java.util.Date;
005import java.util.List;
006import java.util.TimeZone;
007
008import biweekly.ICalVersion;
009import biweekly.component.ICalComponent;
010import biweekly.util.ICalDate;
011
012/*
013 Copyright (c) 2013-2015, Michael Angstadt
014 All rights reserved.
015
016 Redistribution and use in source and binary forms, with or without
017 modification, are permitted provided that the following conditions are met: 
018
019 1. Redistributions of source code must retain the above copyright notice, this
020 list of conditions and the following disclaimer. 
021 2. Redistributions in binary form must reproduce the above copyright notice,
022 this list of conditions and the following disclaimer in the documentation
023 and/or other materials provided with the distribution. 
024
025 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
026 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
027 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
028 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
029 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
030 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
031 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
032 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
033 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
034 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
035 */
036
037/**
038 * Stores information used to write the properties in an iCalendar object.
039 * @author Michael Angstadt
040 */
041public class WriteContext {
042        private final ICalVersion version;
043        private final TimezoneInfo timezoneOptions;
044        private final List<Date> dates = new ArrayList<Date>();
045        private ICalComponent parent;
046
047        public WriteContext(ICalVersion version, TimezoneInfo timezoneOptions) {
048                this.version = version;
049                this.timezoneOptions = timezoneOptions;
050        }
051
052        /**
053         * Gets the version of the iCalendar object that is being written.
054         * @return the iCalendar version
055         */
056        public ICalVersion getVersion() {
057                return version;
058        }
059
060        /**
061         * Gets the timezone options for this iCalendar object.
062         * @return the timezone options
063         */
064        public TimezoneInfo getTimezoneInfo() {
065                return timezoneOptions;
066        }
067
068        /**
069         * Gets the parent component of the property that is being written.
070         * @return the parent component
071         */
072        public ICalComponent getParent() {
073                return parent;
074        }
075
076        /**
077         * Sets the parent component of the property that is being written.
078         * @param parent the parent component
079         */
080        public void setParent(ICalComponent parent) {
081                this.parent = parent;
082        }
083
084        /**
085         * Gets the timezoned date-time property values that are in the iCalendar
086         * object.
087         * @return the timezoned date-time property values
088         */
089        public List<Date> getDates() {
090                return dates;
091        }
092
093        /**
094         * Records the timezoned date-time values that are being written. This is
095         * used to generate a DAYLIGHT property for vCalendar objects.
096         * @param floating true if the date is floating, false if not
097         * @param tz the timezone to format the date in or null for UTC
098         * @param date the date value
099         */
100        public void addDate(ICalDate date, boolean floating, TimeZone tz) {
101                if (date != null && date.hasTime() && !floating && tz != null) {
102                        dates.add(date);
103                }
104        }
105}