Debian Codegraph @

src/main/java/ezvcard/io/chain/ChainingXmlParser.java

raw symbols SCIP
1 package ezvcard.io.chain;
2
3 import java.io.IOException;
4 import java.io.InputStream;
5 import java.io.Reader;
6 import java.nio.file.Path;
7
8 import org.w3c.dom.Document;
9
10 import ezvcard.Ezvcard;
11 import ezvcard.io.StreamReader;
12 import ezvcard.io.xml.XCardReader;
13
14 /*
15 Copyright (c) 2012-2023, Michael Angstadt
16 All rights reserved.
17
18 Redistribution and use in source and binary forms, with or without
19 modification, are permitted provided that the following conditions are met:
20
21 1. Redistributions of source code must retain the above copyright notice, this
22 list of conditions and the following disclaimer.
23 2. Redistributions in binary form must reproduce the above copyright notice,
24 this list of conditions and the following disclaimer in the documentation
25 and/or other materials provided with the distribution.
26
27 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
28 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
29 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
30 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
31 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
32 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
33 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
34 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 /**
40 * Chainer class for parsing xCards (XML-encoded vCards).
41 * @see Ezvcard#parseXml(InputStream)
42 * @see Ezvcard#parseXml(Path)
43 * @see Ezvcard#parseXml(Reader)
44 * @author Michael Angstadt
45 */
46 public class ChainingXmlParser<T extends ChainingXmlParser<?>> extends ChainingParser<T> {
47 private Document dom;
48
49 public ChainingXmlParser(String string) {
50 super(string);
51 }
52
53 public ChainingXmlParser(InputStream in) {
54 super(in);
55 }
56
57 public ChainingXmlParser(Path file) {
58 super(file);
59 }
60
61 public ChainingXmlParser(Reader reader) {
62 super(reader);
63 }
64
65 public ChainingXmlParser(Document dom) {
66 this.dom = dom;
67 }
68
69 @Override
70 StreamReader constructReader() throws IOException {
71 if (string != null) {
72 return new XCardReader(string);
73 }
74 if (in != null) {
75 return new XCardReader(in);
76 }
77 if (reader != null) {
78 return new XCardReader(reader);
79 }
80 if (file != null) {
81 return new XCardReader(file);
82 }
83 return new XCardReader(dom);
84 }
85 }