From adfbb8f8de291a450d592c63e138b280a18a1978 Mon Sep 17 00:00:00 2001 From: Mathew McBride Date: Mon, 24 Mar 2008 17:03:17 +1100 Subject: [PATCH] We now use a modified foundation.6.5.x for contacts (lower case property parsing enabled), plus some fixes for URL parsing --- pom.xml | 150 ++++++++++----------- .../java/net/bionicmessage/groupdav/groupDAV.java | 58 ++++---- .../MultipleSourceICalendarObjectStore.java | 19 ++- .../objects/MultipleSourceVCardObjectStore.java | 47 +++++-- .../MultipleSourceICalendarObjectStoreTest.java | 2 +- 5 files changed, 156 insertions(+), 120 deletions(-) diff --git a/pom.xml b/pom.xml index cf8bf80..98c2189 100644 --- a/pom.xml +++ b/pom.xml @@ -1,76 +1,74 @@ - - - 4.0.0 - bmessage - jgroupdav - jar - 1.2 - jgroupdav - http://bionicmessage.net - - - modularity-releases - Modularity Releases Repository - http://m2.modularity.net.au/releases - - true - - - false - - - - bionicmessage - bionicmessage releases and dependencies - http://latest.bionicmessage.net/maven-repo - - true - - - true - - - - - - net.fortuna - ical4j - 1.0-beta4 - - - smallsql - smallsql - 0.19 - - - funambol - foundation - 3.0.9 - - - xerces - xercesImpl - 2.4.0 - - - junit - junit - 4.4 - test - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - - 1.5 - 1.5 - - - - - + + + 4.0.0 + bmessage + jgroupdav + jar + 1.2 + jgroupdav + http://bionicmessage.net + + + modularity-releases + Modularity Releases Repository + http://m2.modularity.net.au/releases + + + + false + + + + bionicmessage + bionicmessage releases and dependencies + http://latest.bionicmessage.net/maven-repo + + + + + + + + + net.fortuna + ical4j + 1.0-beta4 + + + smallsql + smallsql + 0.19 + + + xerces + xercesImpl + 2.4.0 + + + junit + junit + 4.4 + test + + + funambol + pim-framework + 6.5.8-bm + compile + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.5 + 1.5 + + + + + diff --git a/src/main/java/net/bionicmessage/groupdav/groupDAV.java b/src/main/java/net/bionicmessage/groupdav/groupDAV.java index b649079..72bf9a4 100755 --- a/src/main/java/net/bionicmessage/groupdav/groupDAV.java +++ b/src/main/java/net/bionicmessage/groupdav/groupDAV.java @@ -44,8 +44,6 @@ import org.xml.sax.SAXException; */ public class groupDAV { - private String u = ""; - private String p = ""; private String host = ""; private int po = 2000; private String base64cache = ""; @@ -54,11 +52,6 @@ public class groupDAV { Logger.getLogger(("funambol")); private static ConsoleHandler ch = new ConsoleHandler(); DocumentBuilderFactory fdb = DocumentBuilderFactory.newInstance(); - /* At the moment we only support one set of folders each. */ - private String vtodoloc = ""; - private String vcalloc = ""; - private ArrayList vcallocs = null; - private String vaddrloc = ""; private SocketFactory ssf = null; private boolean ssl = false; private Socket sock = null; @@ -82,6 +75,21 @@ public class groupDAV { */ public groupDAV(String url, String b64cache) { origurl = url; + try { + URL serverURL = new URL(url); + if (serverURL.getProtocol().contains("https")) { + ssl = true; + } + tok = "https://"; + host = serverURL.getHost(); + po = serverURL.getPort(); + if (po == -1) { + po = 80; + } + } catch (MalformedURLException ex) { + Logger.getLogger(groupDAV.class.getName()).log(Level.SEVERE, null, ex); + throw new IllegalArgumentException(ex); + } if (!origurl.substring(origurl.length() - 1).equals("/")) { origurl = url + "/"; } @@ -89,13 +97,6 @@ public class groupDAV { ssl = true; tok = "https://"; } - url = url.replaceAll(tok, ""); // goodbye http:// - String hostname = url.split(":")[0]; - String ports = url.split(":")[1]; // port and url - ports = ports.replace("/", ""); - int port = Integer.valueOf(ports).intValue(); - host = hostname; - po = port; base64cache = "Authorization: Basic " + b64cache; init(); } @@ -108,20 +109,29 @@ public class groupDAV { */ public groupDAV(String url, String user, String pass) { origurl = url; + try { + URL serverURL = new URL(url); + if (serverURL.getProtocol().contains("https")) { + ssl = true; + tok = "https://"; + } + host = serverURL.getHost(); + po = serverURL.getPort(); + if (po == -1) { + po = 80; + } + } catch (MalformedURLException ex) { + Logger.getLogger(groupDAV.class.getName()).log(Level.SEVERE, null, ex); + throw new IllegalArgumentException(ex); + } + if (!origurl.substring(origurl.length() - 1).equals("/")) { + origurl = url + "/"; + } if (url.indexOf("https://") != -1) { ssl = true; tok = "https://"; } - url = url.replaceAll(tok, ""); // goodbye http:// - String hostname = url.split(":")[0]; - String ports = url.split(":")[1]; // port and url - ports = ports.replace("/", ""); - int port = Integer.valueOf(ports).intValue(); - host = hostname; - po = port; - u = user; - p = pass; - base64cache = "Authorization: Basic " + Base64.encodeBytes(new String(u + ":" + p).getBytes()); + base64cache = "Authorization: Basic " + Base64.encodeBytes(new String(user + ":" + pass).getBytes()); init(); } diff --git a/src/main/java/net/bionicmessage/objects/MultipleSourceICalendarObjectStore.java b/src/main/java/net/bionicmessage/objects/MultipleSourceICalendarObjectStore.java index 4ec905c..0ad6aee 100644 --- a/src/main/java/net/bionicmessage/objects/MultipleSourceICalendarObjectStore.java +++ b/src/main/java/net/bionicmessage/objects/MultipleSourceICalendarObjectStore.java @@ -68,7 +68,6 @@ public class MultipleSourceICalendarObjectStore { * Slow sync */ public static int OPTION_TODO = 32; - public static int OPTION_NEWHANDLER = 16; /** Retrieve password from store config file */ public static int OPTION_STOREDPASS = 8; /** Use a single log file */ @@ -87,7 +86,6 @@ public class MultipleSourceICalendarObjectStore { boolean expertmode = false; boolean purgemode = false; boolean todomode = false; - boolean newhandler = false; boolean singlelog = false; MultipleSourceObjectTracking obtrack = null; String obtrackdir = ""; @@ -129,10 +127,6 @@ public class MultipleSourceICalendarObjectStore { // Deprecated todomode = true; } - int newtest = options & OPTION_NEWHANDLER; - if (newtest == OPTION_NEWHANDLER) { - newhandler = true; - } int singletest = options & OPTION_SINGLELOG; if (singletest == OPTION_SINGLELOG) { singlelog = true; @@ -174,6 +168,7 @@ public class MultipleSourceICalendarObjectStore { log.addHandler(fh); fh.setLevel(Level.ALL); log.setLevel(Level.ALL); + logStart(); } catch (SecurityException ex) { ex.printStackTrace(); } catch (IOException ex) { @@ -537,6 +532,17 @@ public class MultipleSourceICalendarObjectStore { obtrack.terminate(); } + protected void logStart() { + log.info(this.getClass().getName() + " started in "+obtrackdir); + log.info("Purge mode="+purgemode); + Iterator it = props.keySet().iterator(); + while(it.hasNext()) { + String prop = (String)it.next(); + String key = props.getProperty(prop); + log.info(prop+"="+key); + } + + } public static void main(String[] args) { String storeloc = ""; if (args.length > 0 && args[0] != null) { @@ -554,4 +560,5 @@ public class MultipleSourceICalendarObjectStore { ex.printStackTrace(); } } + } diff --git a/src/main/java/net/bionicmessage/objects/MultipleSourceVCardObjectStore.java b/src/main/java/net/bionicmessage/objects/MultipleSourceVCardObjectStore.java index 4de7d5c..028d361 100644 --- a/src/main/java/net/bionicmessage/objects/MultipleSourceVCardObjectStore.java +++ b/src/main/java/net/bionicmessage/objects/MultipleSourceVCardObjectStore.java @@ -36,25 +36,25 @@ import net.bionicmessage.groupdav.GroupDAVObject; import net.bionicmessage.groupdav.groupDAV; import net.bionicmessage.utils.HTMLFormatter; -/* import com.funambol.common.pim.contact.*; +import com.funambol.common.pim.contact.*; import com.funambol.common.pim.converter.ContactToVcard; import com.funambol.common.pim.converter.ConverterException; -import com.funambol.common.pim.vcard.VcardParser; */ +import com.funambol.common.pim.vcard.VcardParser; -import com.funambol.foundation.pdi.contact.*; +/* import com.funambol.foundation.pdi.contact.*; import com.funambol.foundation.pdi.converter.*; -import com.funambol.foundation.pdi.parser.VcardParser; +import com.funambol.foundation.pdi.parser.VcardParser; */ import java.io.StringWriter; import java.io.ByteArrayInputStream; import java.io.PrintWriter; import java.util.Iterator; import java.util.List; + /** * * @author matt */ - public class MultipleSourceVCardObjectStore { groupDAV client = null; @@ -73,7 +73,6 @@ public class MultipleSourceVCardObjectStore { public static int OPTION_STOREDPASS = 8; /** Use a single store log file */ public static int OPTION_SINGLELOG = 4; - /** Base property for store location */ public static final String PROPERTY_STORE_LOCATION = "store.location"; /** Properties name for server */ @@ -109,8 +108,8 @@ public class MultipleSourceVCardObjectStore { /* Logger */ Logger log = Logger.getLogger("groupdav.vcardobjectstore"); FileHandler fh = null; - /** Creates a new instance of vCardObjectStore */ + /** Creates a new instance of vCardObjectStore */ public MultipleSourceVCardObjectStore(String storedir, int options) { int ssltest = options & OPTION_SSL; if (ssltest == OPTION_SSL) { @@ -174,6 +173,7 @@ public class MultipleSourceVCardObjectStore { log.addHandler(fh); fh.setLevel(Level.ALL); log.setLevel(Level.ALL); + logStart(); } catch (SecurityException ex) { ex.printStackTrace(); } catch (IOException ex) { @@ -259,6 +259,11 @@ public class MultipleSourceVCardObjectStore { return uid; } + /** Get an object that has been updated on the server + * and update it here + * @param uid + * @throws java.lang.Exception + */ private void updateObjectFromServer(String uid) throws Exception { GroupDAVObject obj = client.getObject(obtrack.getObjectURL(uid)); Contact ct = constructContactObject(obj.getContent()); @@ -266,7 +271,11 @@ public class MultipleSourceVCardObjectStore { objCache.put(uid, ct); obtrack.updateEtag(uid, obj.getEtag()); obtrack.updateObject(uid, obj.getContent()); - obtrack.updateName(uid, name.getDisplayName().getPropertyValueAsString().trim()); + try { + obtrack.updateName(uid, name.getDisplayName().getPropertyValueAsString().trim()); + } catch (Exception e) { + obtrack.updateName(uid, String.format("ERROR %s", uid)); + } updatedInStore.add(uid); } @@ -276,6 +285,7 @@ public class MultipleSourceVCardObjectStore { } /* -> End store/server side */ /* Client->Store->Server side */ + /** Adds an object to the server. * @param sourceName The server source name to add to * @param uid The UID of the object to add @@ -285,7 +295,6 @@ public class MultipleSourceVCardObjectStore { * @param dtend The DTEND of the object in Unix time * @return -1 if error, 0 if added, 1 if replaced,2 if merged. */ - public String addObject(String sourceName, String uid, String name, @@ -307,6 +316,7 @@ public class MultipleSourceVCardObjectStore { addFromServerToStore(sourceName, gbo.getLocation()); return uid; } + /** * Replace a pre-existing object in the store with a new one. * @param uid The UID of the object to replace @@ -317,7 +327,6 @@ public class MultipleSourceVCardObjectStore { * @param dtstart The start time of the object. If dtstart and dtend are 0, dates will not be changed * @param dtend The end time of the object. If dtstart and dtend are 0, dates will not be changed */ - public int replaceObject(String uid, String name, String contents) throws Exception { @@ -358,19 +367,19 @@ public class MultipleSourceVCardObjectStore { } } } + /** * * @param content * @throws java.lang.Exception * @return The UID of the object */ - private Contact constructContactObject(String content) throws Exception { // Fix junk from KAddressBook String ct = content.replace("::", ":"); // Fix lower case begin/end from citadel - ct = ct.replace("begin:vcard", "BEGIN:VCARD"); - ct = ct.replace("end:vcard", "END:VCARD"); + //ct = ct.replace("begin:vcard", "BEGIN:VCARD"); + //ct = ct.replace("end:vcard", "END:VCARD"); ByteArrayInputStream bis = new ByteArrayInputStream(ct.getBytes()); VcardParser vcp = new VcardParser(bis, null, null); return vcp.vCard(); @@ -520,6 +529,7 @@ public class MultipleSourceVCardObjectStore { } public void close() throws Exception { + log.info("Terminating MultipleSourceVCardObjectStore"); fh.close(); obtrack.terminate(); } @@ -546,6 +556,17 @@ public class MultipleSourceVCardObjectStore { props = prop; } + protected void logStart() { + log.info(this.getClass().getName() + " started in "+obtrackdir); + log.info("Purge mode="+purgemode); + Iterator it = props.keySet().iterator(); + while(it.hasNext()) { + String prop = (String)it.next(); + String key = props.getProperty(prop); + log.info(prop+"="+key); + } + + } public static void main(String args[]) { String storeloc = ""; if (args.length > 0 && args[0] != null) { diff --git a/src/test/java/MultipleSourceICalendarObjectStoreTest.java b/src/test/java/MultipleSourceICalendarObjectStoreTest.java index 544eeb1..2718509 100644 --- a/src/test/java/MultipleSourceICalendarObjectStoreTest.java +++ b/src/test/java/MultipleSourceICalendarObjectStoreTest.java @@ -80,7 +80,7 @@ public class MultipleSourceICalendarObjectStoreTest { ico.connect_storedpass(); ico.startSync(); ico.printDebugReport(); - ico.close(); + ico.close(); } /* In the tests below, avoid subsequent test reliance */ @Test -- 2.11.4.GIT