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)
31 throw new AssertionError("Invalid XML/SAX document generated.");
32 } catch (UnsupportedEncodingException e) {
33 throw new AssertionError("Unsopported encoding iso-8859-1 ??");
38 public void consume(Entry entry)
41 gen_.start("contact"); gen_.nl();
43 gen_.start("category"); gen_.text("0"); gen_.end(); gen_.nl();
45 gen_.start("person"); gen_.nl();
46 gen_.start("realName"); gen_.text(entry.name()); gen_.end(); gen_.nl();
47 gen_.empty("imageURL"); gen_.nl();
48 gen_.end(); gen_.nl();
50 gen_.start("telephony"); gen_.nl();
51 for (Attribute number : entry.attributes("phone")) {
53 gen_.attribute("prio", number.index > 0 ? "0" : "1")
54 .attribute("type", number.rel)
55 .attribute("vanity", ""));
56 gen_.text(number.value); gen_.end(); gen_.nl();
58 gen_.end(); gen_.nl();
60 Attribute email = Util.first(entry.attributes("email"));
62 gen_.start("services"); gen_.nl();
63 gen_.start("email", gen_.attribute("classifier","private"));
64 gen_.text(email.value); gen_.end(); gen_.nl();
65 gen_.end(); gen_.nl();
68 gen_.empty("services"); gen_.nl();
71 gen_.end(); gen_.nl();
73 catch (SAXException e)
75 throw new AssertionError("Invalid XML/SAX document generated.");
84 gen_.end(); gen_.nl();
88 catch (SAXException e)
90 throw new AssertionError("Invalid XML/SAX document generated.");