X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=src%2Fde%2Fj32%2Fpimstuff%2FMain.java;h=6214c7fbf95900c6ccaffa3fec4bf3d33b2de418;hb=5ac05364dc652686046f01849b810da6ffef1192;hp=09da5f90a168f898d24c1c444eddd09b17dac4a8;hpb=047cf507ebfb3b790d824845741f169ace317b5f;p=jpim.git diff --git a/src/de/j32/pimstuff/Main.java b/src/de/j32/pimstuff/Main.java index 09da5f9..6214c7f 100644 --- a/src/de/j32/pimstuff/Main.java +++ b/src/de/j32/pimstuff/Main.java @@ -1,96 +1,29 @@ 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.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 abook = new Addressbook(); + Conduit conduit = Registry.get("fritzbox"); + + Data.transfer(conduit, abook); + Data.transfer(abook, conduit); + } + catch (ConduitException e) { + e.printStackTrace(); + } + catch (IOException e) { + e.printStackTrace(); + } + } }