[Bedework-commit] exchgsynch r53 - in trunk: . common/src/org/bedework/exchgsynch common/src/org/bedework/exchgsynch/diff common/src/org/bedework/exchgsynch/intf common/src/org/bedework/exchgsynch/wsimpl

svnadmin at bedework.org svnadmin at bedework.org
Sat Feb 26 11:59:43 EST 2011


Author: douglm
Date: 2011-02-26 11:59:35 -0500 (Sat, 26 Feb 2011)
New Revision: 53

Removed:
   trunk/common/src/org/bedework/exchgsynch/NsContext.java
Modified:
   trunk/.classpath
   trunk/.project
   trunk/common/src/org/bedework/exchgsynch/ExchangeSynch.java
   trunk/common/src/org/bedework/exchgsynch/XmlIcalConvert.java
   trunk/common/src/org/bedework/exchgsynch/diff/BaseEntityWrapper.java
   trunk/common/src/org/bedework/exchgsynch/diff/BaseWrapper.java
   trunk/common/src/org/bedework/exchgsynch/diff/CompWrapper.java
   trunk/common/src/org/bedework/exchgsynch/diff/PropWrapper.java
   trunk/common/src/org/bedework/exchgsynch/diff/XmlIcalCompare.java
   trunk/common/src/org/bedework/exchgsynch/intf/ExchangeSynchIntf.java
   trunk/common/src/org/bedework/exchgsynch/wsimpl/BwSynchIntfImpl.java
Log:
Many fixes to get updates working.

Moved NsContext class into common library

Modified: trunk/.classpath
===================================================================
--- trunk/.classpath	2011-02-22 18:27:32 UTC (rev 52)
+++ trunk/.classpath	2011-02-26 16:59:35 UTC (rev 53)
@@ -10,7 +10,7 @@
 	<classpathentry kind="lib" path="lib/hibernate-3.3.1.ga.jar"/>
 	<classpathentry kind="lib" path="lib/rpiaccess-3.7.jar"/>
 	<classpathentry kind="lib" path="lib/rpiutil-3.7.jar"/>
-	<classpathentry kind="lib" path="lib/bw-exsynchwsschema-3.7.jar"/>
+	<classpathentry kind="lib" path="lib/bw-exsynchwsschema-3.7.jar" sourcepath="/bwxml"/>
 	<classpathentry kind="lib" path="/bwxml/dist/bw-exchangewsschema-3.7.jar"/>
-	<classpathentry kind="output" path="bin/exchgsynch/eclipse-build"/>
+	<classpathentry kind="output" path="bin/exchgsynch/eclipse-build/exchgsynch"/>
 </classpath>

Modified: trunk/.project
===================================================================
--- trunk/.project	2011-02-22 18:27:32 UTC (rev 52)
+++ trunk/.project	2011-02-26 16:59:35 UTC (rev 53)
@@ -20,5 +20,10 @@
 			<type>2</type>
 			<location>/home/douglm/eclipse-build</location>
 		</link>
+		<link>
+			<name>bin/exchgsynch/eclipse-build/exchgsynch</name>
+			<type>2</type>
+			<location>/home/douglm/eclipse-build/exchgsynch</location>
+		</link>
 	</linkedResources>
 </projectDescription>

Modified: trunk/common/src/org/bedework/exchgsynch/ExchangeSynch.java
===================================================================
--- trunk/common/src/org/bedework/exchgsynch/ExchangeSynch.java	2011-02-22 18:27:32 UTC (rev 52)
+++ trunk/common/src/org/bedework/exchgsynch/ExchangeSynch.java	2011-02-26 16:59:35 UTC (rev 53)
@@ -48,13 +48,14 @@
 
 import edu.rpi.cmt.timezones.Timezones;
 import edu.rpi.sss.util.OptionsI;
+import edu.rpi.sss.util.xml.NsContext;
 
 import net.fortuna.ical4j.model.TimeZone;
 import net.fortuna.ical4j.model.component.CalendarComponent;
 
 import org.apache.log4j.Logger;
 
-import ietf.params.xml.ns.icalendar_2.IcalendarType;
+import ietf.params.xml.ns.icalendar_2.Icalendar;
 import ietf.params.xml.ns.icalendar_2.VcalendarType;
 
 import java.net.Authenticator;
@@ -551,9 +552,9 @@
       return;
     }
 
-    IcalendarType exical = cnv.toXml(ci);
+    Icalendar exical = cnv.toXml(ci);
 
-    IcalendarType rmtical = fir.getIcalendar();
+    Icalendar rmtical = fir.getIcalendar();
 
     /* We expect a single vcalendar for both */
 
@@ -566,7 +567,9 @@
 
     /* Build a diff list from properties and components. */
 
-    XmlIcalCompare comp = new XmlIcalCompare(new NsContext("urn:ietf:params:xml:ns:icalendar-2.0"));
+//    NsContext nsc = new NsContext("urn:ietf:params:xml:ns:icalendar-2.0");
+    NsContext nsc = new NsContext(null);
+    XmlIcalCompare comp = new XmlIcalCompare(nsc);
 
 //    if (!comp.differ(excomp, rmtcomp)) {
     if (!comp.differ(exvcal, rmtvcal)) {
@@ -577,14 +580,14 @@
 
     List<XpathUpdate> updates = comp.getUpdates();
 
-    UpdateItemResponse uir = exintf.updateItem(sub, ci.getUID(), updates);
+    UpdateItemResponse uir = exintf.updateItem(sub, ci.getUID(), updates, nsc);
     if (debug) {
       trace("Update: status=" + uir.getStatus() +
             " msg=" + uir.getMessage());
     }
   }
 
-  private VcalendarType get1vcal(final IcalendarType ical) {
+  private VcalendarType get1vcal(final Icalendar ical) {
     List<VcalendarType> vcals = ical.getVcalendars();
 
     if (vcals.size() != 1) {

Deleted: trunk/common/src/org/bedework/exchgsynch/NsContext.java
===================================================================
--- trunk/common/src/org/bedework/exchgsynch/NsContext.java	2011-02-22 18:27:32 UTC (rev 52)
+++ trunk/common/src/org/bedework/exchgsynch/NsContext.java	2011-02-26 16:59:35 UTC (rev 53)
@@ -1,91 +0,0 @@
-package org.bedework.exchgsynch;
-
-import edu.rpi.sss.util.xml.tagdefs.XcalTags;
-
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-
-import javax.xml.namespace.NamespaceContext;
-import javax.xml.namespace.QName;
-
-/** Class used for diff etc.
- * @author douglm
- *
- */
-public class NsContext implements NamespaceContext {
-  private static Map<String, String> keyPrefix = new HashMap<String, String>();
-  private static Map<String, String> keyUri = new HashMap<String, String>();
-
-  static {
-    addToMap("D", "DAV");
-    addToMap("C", "urn:ietf:params:xml:ns:caldav");
-    addToMap("X", XcalTags.namespace);
-    addToMap("df", "urn:ietf:params:xml:ns:pidf-diff");
-  }
-
-  private String defaultNS;
-
-  /** Constructor
-   *
-   * @param defaultNS
-   */
-  public NsContext(final String defaultNS) {
-    this.defaultNS = defaultNS;
-  }
-
-  /**
-   * @return default ns or null
-   */
-  public String getDefaultNS() {
-    return defaultNS;
-  }
-
-  public String getNamespaceURI(final String prefix) {
-    return keyPrefix.get(prefix);
-  }
-
-  public Iterator getPrefixes(final String val) {
-    return keyPrefix.keySet().iterator();
-  }
-
-  public String getPrefix(final String uri) {
-    if ((defaultNS != null) && uri.equals(defaultNS)) {
-      return null;
-    }
-
-    return keyUri.get(uri);
-  }
-
-  /** Append the name with abbreviated namespace.
-   *
-   * @param sb
-   * @param nm
-   */
-  public void appendNsName(final StringBuilder sb,
-                           final QName nm) {
-    String uri = nm.getNamespaceURI();
-    String abbr;
-
-    if ((defaultNS != null) && uri.equals(defaultNS)) {
-      abbr = null;
-    } else {
-      abbr = keyUri.get(uri);
-      if (abbr == null) {
-        abbr = uri;
-      }
-    }
-
-    if (abbr != null) {
-      sb.append(abbr);
-      sb.append(":");
-    }
-
-    sb.append(nm.getLocalPart());
-  }
-
-  private static void addToMap(final String prefix, final String uri) {
-    keyPrefix.put(prefix, uri);
-    keyUri.put(uri, prefix);
-  }
-}

Modified: trunk/common/src/org/bedework/exchgsynch/XmlIcalConvert.java
===================================================================
--- trunk/common/src/org/bedework/exchgsynch/XmlIcalConvert.java	2011-02-22 18:27:32 UTC (rev 52)
+++ trunk/common/src/org/bedework/exchgsynch/XmlIcalConvert.java	2011-02-26 16:59:35 UTC (rev 53)
@@ -49,7 +49,7 @@
 import ietf.params.xml.ns.icalendar_2.DtendPropType;
 import ietf.params.xml.ns.icalendar_2.DtstartPropType;
 import ietf.params.xml.ns.icalendar_2.DuePropType;
-import ietf.params.xml.ns.icalendar_2.IcalendarType;
+import ietf.params.xml.ns.icalendar_2.Icalendar;
 import ietf.params.xml.ns.icalendar_2.LocationPropType;
 import ietf.params.xml.ns.icalendar_2.ObjectFactory;
 import ietf.params.xml.ns.icalendar_2.OrganizerPropType;
@@ -101,7 +101,7 @@
    * @return Icalendar
    * @throws SynchException
    */
-  public IcalendarType toXml(final CalendarItem cal) throws SynchException {
+  public Icalendar toXml(final CalendarItem cal) throws SynchException {
     /* TODO
      * Transparency - derived from what?
      */
@@ -109,7 +109,7 @@
     String statusVal = null;
 
     debug = getLogger().isDebugEnabled();
-    IcalendarType ical = new IcalendarType();
+    Icalendar ical = new Icalendar();
     VcalendarType vcal = new VcalendarType();
 
     ical.getVcalendars().add(vcal);

Modified: trunk/common/src/org/bedework/exchgsynch/diff/BaseEntityWrapper.java
===================================================================
--- trunk/common/src/org/bedework/exchgsynch/diff/BaseEntityWrapper.java	2011-02-22 18:27:32 UTC (rev 52)
+++ trunk/common/src/org/bedework/exchgsynch/diff/BaseEntityWrapper.java	2011-02-26 16:59:35 UTC (rev 53)
@@ -25,9 +25,8 @@
  */
 package org.bedework.exchgsynch.diff;
 
-import org.bedework.exchgsynch.NsContext;
-
 import edu.rpi.sss.util.Util;
+import edu.rpi.sss.util.xml.NsContext;
 
 import java.util.ArrayList;
 import java.util.Iterator;

Modified: trunk/common/src/org/bedework/exchgsynch/diff/BaseWrapper.java
===================================================================
--- trunk/common/src/org/bedework/exchgsynch/diff/BaseWrapper.java	2011-02-22 18:27:32 UTC (rev 52)
+++ trunk/common/src/org/bedework/exchgsynch/diff/BaseWrapper.java	2011-02-26 16:59:35 UTC (rev 53)
@@ -25,7 +25,7 @@
  */
 package org.bedework.exchgsynch.diff;
 
-import org.bedework.exchgsynch.NsContext;
+import edu.rpi.sss.util.xml.NsContext;
 
 import javax.xml.namespace.QName;
 

Modified: trunk/common/src/org/bedework/exchgsynch/diff/CompWrapper.java
===================================================================
--- trunk/common/src/org/bedework/exchgsynch/diff/CompWrapper.java	2011-02-22 18:27:32 UTC (rev 52)
+++ trunk/common/src/org/bedework/exchgsynch/diff/CompWrapper.java	2011-02-26 16:59:35 UTC (rev 53)
@@ -25,9 +25,9 @@
  */
 package org.bedework.exchgsynch.diff;
 
-import org.bedework.exchgsynch.NsContext;
 import org.bedework.exchgsynch.intf.SynchException;
 
+import edu.rpi.sss.util.xml.NsContext;
 import edu.rpi.sss.util.xml.tagdefs.XcalTags;
 
 import ietf.params.xml.ns.icalendar_2.BaseComponentType;

Modified: trunk/common/src/org/bedework/exchgsynch/diff/PropWrapper.java
===================================================================
--- trunk/common/src/org/bedework/exchgsynch/diff/PropWrapper.java	2011-02-22 18:27:32 UTC (rev 52)
+++ trunk/common/src/org/bedework/exchgsynch/diff/PropWrapper.java	2011-02-26 16:59:35 UTC (rev 53)
@@ -25,9 +25,8 @@
  */
 package org.bedework.exchgsynch.diff;
 
-import org.bedework.exchgsynch.NsContext;
-
 import edu.rpi.sss.util.Util;
+import edu.rpi.sss.util.xml.NsContext;
 import edu.rpi.sss.util.xml.tagdefs.XcalTags;
 
 import ietf.params.xml.ns.icalendar_2.ActionPropType;
@@ -119,13 +118,13 @@
     // Append value element.
 
     ValueType vt = getValue();
-    sb.append("/");
+    sb.append("[");
 
     // XXX This is wrong - just using first element for the moment
     ValueTypeEntry vte = vt.vtes.get(0);
     nsContext.appendNsName(sb, vte.typeElement);
 
-    sb.append("[text()='");
+    sb.append("/text()='");
     sb.append(vte.value);
     sb.append("']");
   }

Modified: trunk/common/src/org/bedework/exchgsynch/diff/XmlIcalCompare.java
===================================================================
--- trunk/common/src/org/bedework/exchgsynch/diff/XmlIcalCompare.java	2011-02-22 18:27:32 UTC (rev 52)
+++ trunk/common/src/org/bedework/exchgsynch/diff/XmlIcalCompare.java	2011-02-26 16:59:35 UTC (rev 53)
@@ -25,9 +25,11 @@
 */
 package org.bedework.exchgsynch.diff;
 
-import org.bedework.exchgsynch.NsContext;
 import org.bedework.exchgsynch.intf.SynchException;
 
+import edu.rpi.sss.util.xml.NsContext;
+import edu.rpi.sss.util.xml.tagdefs.XcalTags;
+
 import org.apache.log4j.Logger;
 
 import ietf.params.xml.ns.icalendar_2.BaseComponentType;
@@ -43,6 +45,8 @@
 import java.util.List;
 import java.util.Stack;
 
+import javax.xml.bind.JAXBElement;
+
 /** This class compares 2 components.
 *
 * @author Mike Douglass
@@ -148,16 +152,16 @@
         if (value instanceof NewValueType) {
           NewValueType nv = (NewValueType)value;
 
-          if (nv.getComponent() != null){
-            sb.append(nv.getComponent());
+          if (nv.getBaseComponent() != null){
+            sb.append(nv.getBaseComponent());
           }
 
-          if (nv.getProperty() != null){
-            sb.append(nv.getProperty());
+          if (nv.getBaseProperty() != null){
+            sb.append(nv.getBaseProperty());
           }
 
-          if (nv.getParameter() != null){
-            sb.append(nv.getParameter());
+          if (nv.getBaseParameter() != null){
+            sb.append(nv.getBaseParameter());
           }
         }
       }
@@ -206,7 +210,8 @@
     }
 
     // Unstack and build path
-    StringBuilder sb = new StringBuilder();
+    StringBuilder sb = new StringBuilder("/");
+    nsContext.appendNsName(sb, XcalTags.icalendar);
 
     while (!els.empty()) {
       b = els.pop();
@@ -256,15 +261,24 @@
       }
 
       if (newEntity instanceof BaseComponentType){
-        nv.setComponent((BaseComponentType)newEntity);
+        JAXBElement<? extends BaseComponentType> el = new JAXBElement(be.getName(),
+                                                                     newEntity.getClass(),
+                                                                     newEntity);
+        nv.setBaseComponent(el);
       }
 
       if (newEntity instanceof BasePropertyType){
-        nv.setProperty((BasePropertyType)newEntity);
+        JAXBElement<? extends BasePropertyType> el = new JAXBElement(be.getName(),
+                                                                     newEntity.getClass(),
+                                                                     newEntity);
+        nv.setBaseProperty(el);
       }
 
       if (newEntity instanceof BaseParameterType){
-        nv.setParameter((BaseParameterType)newEntity);
+        JAXBElement<? extends BaseParameterType> el = new JAXBElement(be.getName(),
+                                                                     newEntity.getClass(),
+                                                                     newEntity);
+        nv.setBaseParameter(el);
       }
     }
 

Modified: trunk/common/src/org/bedework/exchgsynch/intf/ExchangeSynchIntf.java
===================================================================
--- trunk/common/src/org/bedework/exchgsynch/intf/ExchangeSynchIntf.java	2011-02-22 18:27:32 UTC (rev 52)
+++ trunk/common/src/org/bedework/exchgsynch/intf/ExchangeSynchIntf.java	2011-02-26 16:59:35 UTC (rev 53)
@@ -32,7 +32,7 @@
 import org.bedework.exsynch.wsmessages.FetchItemResponse;
 import org.bedework.exsynch.wsmessages.UpdateItemResponse;
 
-import ietf.params.xml.ns.icalendar_2.IcalendarType;
+import ietf.params.xml.ns.icalendar_2.Icalendar;
 
 import java.util.List;
 
@@ -115,7 +115,7 @@
    */
   AddItemResponse addItem(ExchangeSubscription sub,
                           String uid,
-                          IcalendarType val) throws SynchException;
+                          Icalendar val) throws SynchException;
 
   /** Fetch a calendar component
    *
@@ -132,10 +132,12 @@
    * @param sub
    * @param uid of item
    * @param updates
+   * @param nsc - used to set namespaces
    * @return response
    * @throws SynchException
    */
   UpdateItemResponse updateItem(ExchangeSubscription sub,
                                 String uid,
-                                List<XpathUpdate> updates) throws SynchException;
+                                List<XpathUpdate> updates,
+                                edu.rpi.sss.util.xml.NsContext nsc) throws SynchException;
 }

Modified: trunk/common/src/org/bedework/exchgsynch/wsimpl/BwSynchIntfImpl.java
===================================================================
--- trunk/common/src/org/bedework/exchgsynch/wsimpl/BwSynchIntfImpl.java	2011-02-22 18:27:32 UTC (rev 52)
+++ trunk/common/src/org/bedework/exchgsynch/wsimpl/BwSynchIntfImpl.java	2011-02-26 16:59:35 UTC (rev 53)
@@ -33,12 +33,14 @@
 import org.bedework.exchgsynch.intf.SynchException;
 import org.bedework.exsynch.wsmessages.AddItem;
 import org.bedework.exsynch.wsmessages.AddItemResponse;
+import org.bedework.exsynch.wsmessages.ArrayOfNamespaces;
 import org.bedework.exsynch.wsmessages.ArrayOfUpdates;
 import org.bedework.exsynch.wsmessages.ExsynchRemoteService;
 import org.bedework.exsynch.wsmessages.ExsynchRemoteServicePortType;
 import org.bedework.exsynch.wsmessages.FetchItem;
 import org.bedework.exsynch.wsmessages.FetchItemResponse;
 import org.bedework.exsynch.wsmessages.GetSycnchInfo;
+import org.bedework.exsynch.wsmessages.NamespaceType;
 import org.bedework.exsynch.wsmessages.ObjectFactory;
 import org.bedework.exsynch.wsmessages.StartServiceNotification;
 import org.bedework.exsynch.wsmessages.StartServiceResponse;
@@ -51,7 +53,7 @@
 
 import org.apache.log4j.Logger;
 
-import ietf.params.xml.ns.icalendar_2.IcalendarType;
+import ietf.params.xml.ns.icalendar_2.Icalendar;
 import ietf.params.xml.ns.pidf_diff.AddType;
 import ietf.params.xml.ns.pidf_diff.BaseUpdateType;
 import ietf.params.xml.ns.pidf_diff.RemoveType;
@@ -159,7 +161,7 @@
   @Override
   public AddItemResponse addItem(final ExchangeSubscription sub,
                                  final String uid,
-                                 final IcalendarType val) throws SynchException {
+                                 final Icalendar val) throws SynchException {
     AddItem ai = new AddItem();
 
     ai.setCalendarHref(sub.getCalPath());
@@ -185,9 +187,28 @@
 
   public UpdateItemResponse updateItem(final ExchangeSubscription sub,
                                        final String uid,
-                                       final List<XpathUpdate> updates) throws SynchException {
+                                       final List<XpathUpdate> updates,
+                                       final edu.rpi.sss.util.xml.NsContext nsc) throws SynchException {
     UpdateItem upd = new UpdateItem();
 
+    ArrayOfNamespaces aon = new ArrayOfNamespaces();
+    String defaultNs = nsc.getDefaultNS();
+
+    for (String pfx: nsc.getPrefixes()) {
+      String uri = nsc.getNamespaceURI(pfx);
+
+      NamespaceType ns = new NamespaceType();
+      if ((defaultNs == null) || !defaultNs.equals(uri)) {
+        ns.setPrefix(pfx);
+      }
+
+      ns.setUri(uri);
+
+      aon.getNamespaces().add(ns);
+    }
+
+    upd.setNamespaces(aon);
+
     upd.setCalendarHref(sub.getCalPath());
     upd.setPrincipalHref(sub.getprincipalHref());
     upd.setSynchToken(curToken);



More information about the Bedework-commit mailing list