Code formating and whitespace cleanup
[jpim.git] / src / de / j32 / pimstuff / Main.java
index 09da5f9..733b6f3 100644 (file)
@@ -1,96 +1,51 @@
 package de.j32.pimstuff;
 
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
 import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.util.Properties;
 
-import org.xml.sax.SAXException;
-
-import de.j32.avmfritz.FritzBox;
-import de.j32.pimstuff.conduit.FritzAddressbookImporter;
-import de.j32.pimstuff.conduit.FritzAddressbookExporter;
+import de.j32.pimstuff.conduit.Conduit;
+import de.j32.pimstuff.conduit.ConduitException;
+import de.j32.pimstuff.conduit.Exporter;
+import de.j32.pimstuff.conduit.Importer;
+import de.j32.pimstuff.conduit.Registry;
 import de.j32.pimstuff.data.Addressbook;
 import de.j32.util.Util;
 
-public class Main {
-
-       public static void main(String[] args)
-       {       
-               try {
-                       
-                       System.out.println("Launching pimstuff ...");
-                       Properties config = new Properties();
-                       
-                       try {
-                               config.loadFromXML(new FileInputStream("config.xml"));
-                       }
-                       catch (FileNotFoundException e) {
-                               config.setProperty("password", "password");
-                               config.setProperty("url", "http://fritz.box");
-                               
-                               config.storeToXML(new FileOutputStream("config.xml"), null, "UTF-8");
-                       }
-                       
-                       String pw, url;
-
-                       try {
-                               pw = Util.nonnull(config.getProperty("password"));
-                               url = Util.nonnull(config.getProperty("url"));
-                       }
-                       catch (NullPointerException e) {
-                               throw new RuntimeException("Missing configuration parameter");
-                       }
-
-                       Addressbook ab = new Addressbook();
-                       FritzBox fb = new FritzBox(pw, url);
-
-                       System.out.println("loading ...");
-                       // Load Addressbook from FritzBox
-                       InputStream is = null;
-                       FritzAddressbookImporter reader = null;
-                       try {
-                               ab = new Addressbook();
-                               is = fb.exportAddressbook();
-                               reader = new FritzAddressbookImporter(is);
-                               reader.sendTo(ab);
-                               is.close();
-                               is = null;
-                               reader.close();
-                               reader = null;
-                       }
-                       finally {
-                               Util.nothrowClose(is);
-                       }
-                       
-                       System.out.println("saving ...");
-                       // Save Addressbook back to FritzBox
-                       FritzAddressbookExporter writer = null;
-                       OutputStream os = null;
-                       try {
-                               os = fb.importAddressbook();
-                               writer = new FritzAddressbookExporter(os);
-                               ab.sendTo(writer);
-                               writer.close();
-                               writer = null;
-                               os.close();
-                               os = null;
-                       }
-                       finally {
-                               Util.nothrowClose(writer);
-                               Util.nothrowClose(os);
-                       }
-
-               } catch (SAXException e) {
-                       // TODO Auto-generated catch block
-                       e.printStackTrace();
-               } catch (IOException e) {
-                       // TODO Auto-generated catch block
-                       e.printStackTrace();
-               }
-       }
-
+public class Main
+{
+
+    public static void main(String[] args)
+    {
+        try {
+            Addressbook ab = new Addressbook();
+            Conduit conduit = Registry.get("fritzbox");
+
+            Importer i = null;
+            try {
+                i = conduit.importer();
+                i.sendTo(ab);
+                i.close();
+                i = null;
+            }
+            finally {
+                Util.nothrowClose(i);
+            }
+
+            Exporter e = null;
+            try {
+                e = conduit.exporter();
+                ab.sendTo(e);
+                e.close();
+                e = null;
+            }
+            finally {
+                Util.nothrowClose(e);
+            }
+        }
+        catch (ConduitException e) {
+            e.printStackTrace();
+        }
+        catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
 }