X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=src%2Fde%2Fj32%2Fpimstuff%2FMain.java;h=089eee9185c812a5acd2b2b18f47705ce7c900c7;hb=aeb7d91db3d650d30a9191cbe84192d6b3b23df7;hp=173df38942ef16b3e48ce4b5995f5da1899fabe1;hpb=4095790c7943e91462bce2072234fe53f610f95b;p=jpim.git diff --git a/src/de/j32/pimstuff/Main.java b/src/de/j32/pimstuff/Main.java index 173df38..089eee9 100644 --- a/src/de/j32/pimstuff/Main.java +++ b/src/de/j32/pimstuff/Main.java @@ -1,18 +1,12 @@ 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.FritzAddressbookReader; -import de.j32.pimstuff.conduit.FritzAddressbookWriter; +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; @@ -21,76 +15,36 @@ 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); + Conduit conduit = Registry.get("fritzbox"); - System.out.println("loading ..."); - // Load Addressbook from FritzBox - InputStream is = null; - FritzAddressbookReader reader = null; + Importer i = null; try { - ab = new Addressbook(); - is = fb.exportAddressbook(); - reader = new FritzAddressbookReader(is); - reader.sendTo(ab); - is.close(); - is = null; - reader.close(); - reader = null; + i = conduit.importer(); + i.sendTo(ab); + i.close(); + i = null; } finally { - Util.nothrowClose(is); + Util.nothrowClose(i); } - System.out.println("saving ..."); - // Save Addressbook back to FritzBox - FritzAddressbookWriter writer = null; - OutputStream os = null; + Exporter e = null; try { - os = fb.importAddressbook(); - writer = new FritzAddressbookWriter(os); - ab.sendTo(writer); - writer.close(); - writer = null; - os.close(); - os = null; + e = conduit.exporter(); + ab.sendTo(e); + e.close(); + e = null; } finally { - Util.nothrowClose(writer); - Util.nothrowClose(os); + Util.nothrowClose(e); } - - } catch (SAXException e) { - // TODO Auto-generated catch block + } + catch (ConduitException e) { e.printStackTrace(); - } catch (IOException e) { - // TODO Auto-generated catch block + } + catch (IOException e) { e.printStackTrace(); } } - }