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.XmlUtil;
14 public class FritzAddressbookImporter implements Importer
19 * Importer reading Addressbook from Fritzbox XML file
21 * @param is InputStream providing the XML data. <em>After successful</em>
22 * construction, the class takes responsibility for closing the
24 * @throws SAXException
27 public FritzAddressbookImporter(InputStream is) throws SAXException,
30 // It does not make sens to try / finally here, at least conceptually:
32 // the base-class constructor might throw we would never get a chance to
33 // properly close is. Thus I deem it safer to only take responsibility
35 // when the constructor does NOT throw and place the try / finally into
38 xml_ = XmlUtil.parse(is);
43 public void sendTo(EntryConsumer consumer)
45 for (Element node : XmlUtil.iterate(
46 xml_.getElementsByTagName("contact"), Element.class)) {
48 * subnodes: category (unused, always 0) person/realName
49 * person/imageURL telephony/number (@prio, @type, @vanity)
50 * services/email mod_time
52 Entry entry = new Entry();
55 entry.name(node.getElementsByTagName("realName").item(0)
58 for (Element phone : XmlUtil.iterate(
59 node.getElementsByTagName("number"), Element.class)) {
60 entry.attribute("phone", phone.getAttribute("type"),
61 phone.getTextContent());
65 entry.attribute("email", "",
66 node.getElementsByTagName("email").item(0)
69 catch (NullPointerException e) {} // ignore missing optional
72 catch (NullPointerException e) {
73 // Ignore incomplete entries
77 if (entry != null) consumer.consume(entry);
82 public void close() throws IOException