X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Fjvcard%2Fremote%2FSync.java;h=4b7a18bdec3c7353f12d4e6f5b0349c8287c2a4c;hb=f06c81000632cfb5f525ca458f719338f55f9f66;hp=996366537c90a1ed55227fb64c494d45a294fedf;hpb=5ad0e17e7fea1c602cb2638a006424af9c7e33e8;p=jvcard.git diff --git a/src/be/nikiroo/jvcard/remote/Sync.java b/src/be/nikiroo/jvcard/remote/Sync.java index 9963665..4b7a18b 100644 --- a/src/be/nikiroo/jvcard/remote/Sync.java +++ b/src/be/nikiroo/jvcard/remote/Sync.java @@ -16,8 +16,6 @@ import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; -import java.util.MissingResourceException; -import java.util.ResourceBundle; import be.nikiroo.jvcard.Card; import be.nikiroo.jvcard.Contact; @@ -26,15 +24,17 @@ import be.nikiroo.jvcard.launcher.CardResult; import be.nikiroo.jvcard.launcher.CardResult.MergeCallback; import be.nikiroo.jvcard.parsers.Format; import be.nikiroo.jvcard.parsers.Vcard21Parser; -import be.nikiroo.jvcard.resources.Bundles; -import be.nikiroo.jvcard.resources.StringUtils; +import be.nikiroo.jvcard.remote.SimpleSocket.BlockAppendable; +import be.nikiroo.jvcard.resources.RemoteBundle; +import be.nikiroo.jvcard.resources.RemotingOption; +import be.nikiroo.utils.StringUtils; /** * This class will synchronise {@link Card}s between a local instance an a * remote jVCard server. * * @author niki - * + * */ public class Sync { /** The time in ms after which we declare that 2 timestamps are different */ @@ -277,7 +277,9 @@ public class Sync { } case POST_CARD: { s.sendCommand(Command.POST_CARD); - s.sendBlock(Vcard21Parser.toStrings(local)); + BlockAppendable app = s.createBlockAppendable(); + Vcard21Parser.write(app, local); + app.close(); local.saveAs(getCache(cacheDirOrig), Format.VCard21); setLastModified(s.receiveLine()); break; @@ -344,7 +346,9 @@ public class Sync { // ...but without starting with original since it is not // true here s.sendCommand(Command.POST_CARD); - s.sendBlock(Vcard21Parser.toStrings(merge)); + BlockAppendable app = s.createBlockAppendable(); + Vcard21Parser.write(app, merge); + app.close(); String serverLastModifTime = s.receiveLine(); // @@ -410,7 +414,9 @@ public class Sync { } for (Contact c : added) { s.sendCommand(Command.POST_CONTACT, c.getId()); - s.sendBlock(Vcard21Parser.toStrings(c, -1)); + BlockAppendable app = s.createBlockAppendable(); + Vcard21Parser.write(app, c, -1); + s.close(); } if (from.size() > 0) { for (int index = 0; index < from.size(); index++) { @@ -426,7 +432,9 @@ public class Sync { } for (Data d : subadded) { s.sendCommand(Command.POST_DATA, d.getContentState(true)); - s.sendBlock(Vcard21Parser.toStrings(d)); + BlockAppendable app = s.createBlockAppendable(); + Vcard21Parser.write(app, d); + app.close(); } s.sendCommand(Command.PUT_CONTACT); } @@ -515,7 +523,7 @@ public class Sync { * * @param dir * the cache to use - * + * * @return the cached {@link File} */ private File getCache(File dir) { @@ -588,10 +596,10 @@ public class Sync { */ static private void config() { String dir = null; - ResourceBundle bundle = Bundles.getBundle("remote"); + RemoteBundle bundle = new RemoteBundle(); try { - dir = bundle.getString("CLIENT_CACHE_DIR").trim(); + dir = bundle.getString(RemotingOption.CLIENT_CACHE_DIR); cacheDir = new File(dir + File.separator + "current"); cacheDir.mkdir(); @@ -605,14 +613,8 @@ public class Sync { + dir); } - String autoStr = bundle.getString("CLIENT_AUTO_SYNC"); - if (autoStr != null && autoStr.trim().equalsIgnoreCase("true")) { - autoSync = true; - } - - } catch (MissingResourceException e) { - throw new InvalidParameterException( - "Cannot access remote.properties configuration file"); + autoSync = bundle + .getBoolean(RemotingOption.CLIENT_AUTO_SYNC, false); } catch (Exception e) { throw new InvalidParameterException( "Cannot open or create cache store at: " + dir);