--- /dev/null
+package de.j32.jpim.conduit;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import org.xml.sax.SAXException;
+
+import de.j32.avmfritz.FritzBox;
+import de.j32.util.Util;
+
+public class FritzAddressbookConduit implements Conduit
+{
+ FritzBox fb_;
+
+ public FritzAddressbookConduit() throws ConduitException
+ {
+ try {
+ fb_ = new FritzBox(Config.get("fritzbox-password"), Config.get(
+ "fritzbox-url", "http://fritz.box"));
+ }
+ catch (SAXException e) {
+ throw new ConduitException(e);
+ }
+ catch (IOException e) {
+ throw new ConduitException(e);
+ }
+ }
+
+ @Override
+ public Exporter exporter() throws ConduitException
+ {
+ OutputStream os = null;
+ FritzAddressbookExporter exporter = null;
+ try {
+ os = fb_.importAddressbook();
+ exporter = new FritzAddressbookExporter(os);
+ }
+ catch (IOException e) {
+ throw new ConduitException(e);
+ }
+ finally {
+ if (exporter == null) Util.nothrowClose(os);
+ }
+ return exporter;
+ }
+
+ @Override
+ public Importer importer() throws ConduitException
+ {
+ InputStream is = null;
+ FritzAddressbookImporter importer = null;
+ try {
+ is = fb_.exportAddressbook();
+ importer = new FritzAddressbookImporter(is);
+ }
+ catch (IOException e) {
+ throw new ConduitException(e);
+ }
+ catch (SAXException e) {
+ throw new ConduitException(e);
+ }
+ finally {
+ if (importer == null) Util.nothrowClose(is);
+ }
+ return importer;
+ }
+}