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 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;
- FritzAddressbookImporter reader = null;
+ Importer i = null;
try {
- ab = new Addressbook();
- is = fb.exportAddressbook();
- reader = new FritzAddressbookImporter(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
- FritzAddressbookExporter writer = null;
- OutputStream os = null;
+ Exporter e = null;
try {
- os = fb.importAddressbook();
- writer = new FritzAddressbookExporter(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();
}
}
-
}