001package ezvcard.io.chain; 002 003import java.io.IOException; 004import java.io.InputStream; 005import java.io.Reader; 006import java.nio.file.Path; 007 008import org.w3c.dom.Document; 009 010import ezvcard.Ezvcard; 011import ezvcard.io.StreamReader; 012import ezvcard.io.xml.XCardReader; 013 014/* 015 Copyright (c) 2012-2023, Michael Angstadt 016 All rights reserved. 017 018 Redistribution and use in source and binary forms, with or without 019 modification, are permitted provided that the following conditions are met: 020 021 1. Redistributions of source code must retain the above copyright notice, this 022 list of conditions and the following disclaimer. 023 2. Redistributions in binary form must reproduce the above copyright notice, 024 this list of conditions and the following disclaimer in the documentation 025 and/or other materials provided with the distribution. 026 027 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 028 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 029 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 030 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 031 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 032 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 033 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 034 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 035 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 036 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 037 */ 038 039/** 040 * Chainer class for parsing xCards (XML-encoded vCards). 041 * @see Ezvcard#parseXml(InputStream) 042 * @see Ezvcard#parseXml(Path) 043 * @see Ezvcard#parseXml(Reader) 044 * @author Michael Angstadt 045 */ 046public class ChainingXmlParser<T extends ChainingXmlParser<?>> extends ChainingParser<T> { 047 private Document dom; 048 049 public ChainingXmlParser(String string) { 050 super(string); 051 } 052 053 public ChainingXmlParser(InputStream in) { 054 super(in); 055 } 056 057 public ChainingXmlParser(Path file) { 058 super(file); 059 } 060 061 public ChainingXmlParser(Reader reader) { 062 super(reader); 063 } 064 065 public ChainingXmlParser(Document dom) { 066 this.dom = dom; 067 } 068 069 @Override 070 StreamReader constructReader() throws IOException { 071 if (string != null) { 072 return new XCardReader(string); 073 } 074 if (in != null) { 075 return new XCardReader(in); 076 } 077 if (reader != null) { 078 return new XCardReader(reader); 079 } 080 if (file != null) { 081 return new XCardReader(file); 082 } 083 return new XCardReader(dom); 084 } 085}