1 package de.j32.jpim.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.jpim.data.Attribute;
10 import de.j32.jpim.data.Entry;
11 import de.j32.util.SimpleXmlGenerator;
12 import de.j32.util.Util;
14 public class FritzAddressbookExporter implements Exporter
17 SimpleXmlGenerator gen_;
20 * Write Addressbook to Fritzbox XML stream
23 * OutputStrea to which the XML data is sent.
24 * <em>After successful</em> construction, the class takes
25 * responsibility for closing the streanm.
27 public FritzAddressbookExporter(OutputStream os)
31 gen_ = new SimpleXmlGenerator(os_, "iso-8859-1");
34 gen_.start("phonebooks");
36 gen_.start("phonebook");
39 catch (SAXException e) {
40 throw new AssertionError("Invalid XML/SAX document generated.");
42 catch (UnsupportedEncodingException e) {
43 throw new AssertionError("Unsopported encoding iso-8859-1 ??");
48 public void consume(Entry entry)
51 gen_.start("contact");
54 gen_.start("category");
61 gen_.start("realName");
62 gen_.text(entry.name());
65 gen_.empty("imageURL");
70 gen_.start("telephony");
72 for (Attribute number : entry.attributes("phone")) {
75 gen_.attribute("prio", number.index > 0 ? "0" : "1")
76 .attribute("type", number.rel)
77 .attribute("vanity", ""));
78 gen_.text(number.value);
85 Attribute email = Util.first(entry.attributes("email"));
87 gen_.start("services");
89 gen_.start("email", gen_.attribute("classifier", "private"));
90 gen_.text(email.value);
97 gen_.empty("services");
104 catch (SAXException e) {
105 throw new AssertionError("Invalid XML/SAX document generated.");
110 public void close() throws IOException
120 catch (SAXException e) {
121 throw new AssertionError("Invalid XML/SAX document generated.");
124 Util.nothrowClose(os_);