1 package de.j32.pimstuff.conduit;
3 import java.io.IOException;
4 import java.io.OutputStream;
5 import java.io.UnsupportedEncodingException;
7 import org.xml.sax.SAXException;
9 import de.j32.pimstuff.data.Attribute;
10 import de.j32.pimstuff.data.Entry;
11 import de.j32.util.SimpleXmlGenerator;
12 import de.j32.util.Util;
14 public class FritzAddressbookExporter
18 SimpleXmlGenerator gen_;
20 public FritzAddressbookExporter(OutputStream os)
24 gen_ = new SimpleXmlGenerator(os_, "iso-8859-1");
25 gen_.startDocument(); gen_.nl();
26 gen_.start("phonebooks"); gen_.nl();
27 gen_.start("phonebook"); gen_.nl();
29 catch (SAXException e) {
30 throw new AssertionError("Invalid XML/SAX document generated.");
32 catch (UnsupportedEncodingException e) {
33 throw new AssertionError("Unsopported encoding iso-8859-1 ??");
36 Util.nothrowClose(os);
41 public void consume(Entry entry)
44 gen_.start("contact"); gen_.nl();
46 gen_.start("category"); gen_.text("0"); gen_.end(); gen_.nl();
48 gen_.start("person"); gen_.nl();
49 gen_.start("realName"); gen_.text(entry.name()); gen_.end(); gen_.nl();
50 gen_.empty("imageURL"); gen_.nl();
51 gen_.end(); gen_.nl();
53 gen_.start("telephony"); gen_.nl();
54 for (Attribute number : entry.attributes("phone")) {
56 gen_.attribute("prio", number.index > 0 ? "0" : "1")
57 .attribute("type", number.rel)
58 .attribute("vanity", ""));
59 gen_.text(number.value); gen_.end(); gen_.nl();
61 gen_.end(); gen_.nl();
63 Attribute email = Util.first(entry.attributes("email"));
65 gen_.start("services"); gen_.nl();
66 gen_.start("email", gen_.attribute("classifier","private"));
67 gen_.text(email.value); gen_.end(); gen_.nl();
68 gen_.end(); gen_.nl();
71 gen_.empty("services"); gen_.nl();
74 gen_.end(); gen_.nl();
76 catch (SAXException e)
78 throw new AssertionError("Invalid XML/SAX document generated.");
87 gen_.end(); gen_.nl();
93 catch (SAXException e)
95 throw new AssertionError("Invalid XML/SAX document generated.");
99 Util.nothrowClose(os_);