Implement spring Conduit bean registry and lots of cleanup
[jpim.git] / src / de / j32 / pimstuff / conduit / FritzAddressbookConduit.java
diff --git a/src/de/j32/pimstuff/conduit/FritzAddressbookConduit.java b/src/de/j32/pimstuff/conduit/FritzAddressbookConduit.java
new file mode 100644 (file)
index 0000000..d894ae0
--- /dev/null
@@ -0,0 +1,53 @@
+package de.j32.pimstuff.conduit;
+
+import java.io.IOException;
+
+import org.xml.sax.SAXException;
+
+import de.j32.avmfritz.FritzBox;
+
+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
+       {
+               try {
+                       return new FritzAddressbookExporter(fb_.importAddressbook());
+               }
+               catch (IOException e) {
+                       throw new ConduitException(e);
+               }
+       }
+
+       @Override
+       public Importer importer()
+               throws ConduitException
+       {
+               try {
+                       return new FritzAddressbookImporter(fb_.exportAddressbook());
+               }
+               catch (IOException e) {
+                       throw new ConduitException(e);
+               } catch (SAXException e) {
+                       throw new ConduitException(e);
+               }
+       }
+}