| 1 | package ezvcard.io.chain; |
| 2 | |
| 3 | import java.io.IOException; |
| 4 | import java.io.UncheckedIOException; |
| 5 | import java.util.List; |
| 6 | |
| 7 | import org.w3c.dom.Document; |
| 8 | |
| 9 | import ezvcard.Ezvcard; |
| 10 | import ezvcard.VCard; |
| 11 | |
| 12 | /* |
| 13 | Copyright (c) 2012-2023, Michael Angstadt |
| 14 | All rights reserved. |
| 15 | |
| 16 | Redistribution and use in source and binary forms, with or without |
| 17 | modification, are permitted provided that the following conditions are met: |
| 18 | |
| 19 | 1. Redistributions of source code must retain the above copyright notice, this |
| 20 | list of conditions and the following disclaimer. |
| 21 | 2. Redistributions in binary form must reproduce the above copyright notice, |
| 22 | this list of conditions and the following disclaimer in the documentation |
| 23 | and/or other materials provided with the distribution. |
| 24 | |
| 25 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
| 26 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 27 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 28 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR |
| 29 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 30 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 31 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 32 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 33 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 34 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 35 | */ |
| 36 | |
| 37 | /** |
| 38 | * Chainer class for parsing xCards (XML-encoded vCards) from strings or DOMs. |
| 39 | * @see Ezvcard#parseXml(String) |
| 40 | * @see Ezvcard#parseXml(Document) |
| 41 | * @author Michael Angstadt |
| 42 | */ |
| 43 | public class ChainingXmlMemoryParser extends ChainingXmlParser<ChainingXmlMemoryParser> { |
| 44 | public ChainingXmlMemoryParser(String xml) { |
| 45 | super(xml); |
| 46 | } |
| 47 | |
| 48 | public ChainingXmlMemoryParser(Document dom) { |
| 49 | super(dom); |
| 50 | } |
| 51 | |
| 52 | @Override |
| 53 | public VCard first() { |
| 54 | try { |
| 55 | return super.first(); |
| 56 | } catch (IOException e) { |
| 57 | //should never be thrown because we're reading from a string |
| 58 | throw new UncheckedIOException(e); |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | @Override |
| 63 | public List<VCard> all() { |
| 64 | try { |
| 65 | return super.all(); |
| 66 | } catch (IOException e) { |
| 67 | //should never be thrown because we're reading from a string |
| 68 | throw new UncheckedIOException(e); |
| 69 | } |
| 70 | } |
| 71 | } |