1 package de.j32.pimstuff.conduit;
3 import java.io.IOException;
4 import java.io.InputStream;
6 import org.w3c.dom.Document;
7 import org.w3c.dom.Element;
8 import org.xml.sax.SAXException;
10 import de.j32.pimstuff.data.Entry;
11 import de.j32.pimstuff.data.EntryConsumer;
12 import de.j32.util.Util;
13 import de.j32.util.XmlUtil;
15 public class FritzAddressbookImporter
20 public FritzAddressbookImporter(InputStream is)
21 throws SAXException, IOException
24 xml_ = XmlUtil.parse(is);
29 Util.nothrowClose(is);
34 public void sendTo(EntryConsumer consumer)
36 for (Element node : XmlUtil.iterate(xml_.getElementsByTagName("contact"),Element.class)) {
38 * category (unused, always 0)
41 * telephony/number (@prio, @type, @vanity)
45 Entry entry = new Entry();
48 entry.name(node.getElementsByTagName("realName").item(0).getTextContent());
50 for (Element phone : XmlUtil.iterate(node.getElementsByTagName("number"),Element.class)) {
51 entry.attribute("phone", phone.getAttribute("type"), phone.getTextContent());
55 entry.attribute("email", "",
56 node.getElementsByTagName("email").item(0).getTextContent());
58 catch (NullPointerException e) {} // ignore missing optional email
60 catch (NullPointerException e) {
61 // Ignore incomplete entries
66 consumer.consume(entry);