001package ezvcard.io.chain;
002
003import java.io.IOException;
004import java.util.List;
005
006import org.w3c.dom.Document;
007
008import ezvcard.Ezvcard;
009import ezvcard.VCard;
010
011/*
012 Copyright (c) 2012-2018, 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 * Chainer class for parsing xCards (XML-encoded vCards) from strings or DOMs.
038 * @see Ezvcard#parseXml(String)
039 * @see Ezvcard#parseXml(Document)
040 * @author Michael Angstadt
041 */
042public class ChainingXmlMemoryParser extends ChainingXmlParser<ChainingXmlMemoryParser> {
043        public ChainingXmlMemoryParser(String xml) {
044                super(xml);
045        }
046
047        public ChainingXmlMemoryParser(Document dom) {
048                super(dom);
049        }
050
051        @Override
052        public VCard first() {
053                try {
054                        return super.first();
055                } catch (IOException e) {
056                        //should never be thrown because we're reading from a string
057                        throw new RuntimeException(e);
058                }
059        }
060
061        @Override
062        public List<VCard> all() {
063                try {
064                        return super.all();
065                } catch (IOException e) {
066                        //should never be thrown because we're reading from a string
067                        throw new RuntimeException(e);
068                }
069        }
070}