001package biweekly.io.scribe.property;
002
003import java.util.ArrayList;
004import java.util.Arrays;
005import java.util.List;
006
007import biweekly.ICalDataType;
008import biweekly.ICalVersion;
009import biweekly.property.EmailAlarm;
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 * Marshals {@link EmailAlarm} properties.
038 * @author Michael Angstadt
039 */
040public class EmailAlarmScribe extends VCalAlarmPropertyScribe<EmailAlarm> {
041        public EmailAlarmScribe() {
042                super(EmailAlarm.class, "MALARM");
043        }
044
045        @Override
046        protected ICalDataType _defaultDataType(ICalVersion version) {
047                return ICalDataType.TEXT;
048        }
049
050        @Override
051        protected List<String> writeData(EmailAlarm property) {
052                String email = property.getEmail();
053                String note = property.getNote();
054                if (email == null && note == null) {
055                        return Arrays.asList();
056                }
057
058                List<String> dataValues = new ArrayList<String>(2);
059                dataValues.add((email == null) ? "" : email);
060                dataValues.add((note == null) ? "" : note);
061                return dataValues;
062        }
063
064        @Override
065        protected EmailAlarm create(ICalDataType dataType, SemiStructuredIterator it) {
066                String email = it.next();
067                String note = it.next();
068
069                EmailAlarm property = new EmailAlarm(email);
070                property.setNote(note);
071                return property;
072        }
073}