Author: sdumitriu
Date: 2007-12-12 17:24:03 +0100 (Wed, 12 Dec 2007)
New Revision: 6357

Modified:
   
xwiki-platform/core/branches/xwiki-core-1.2/xwiki-core/src/main/java/com/xpn/xwiki/doc/XWikiDocumentArchive.java
   
xwiki-platform/core/branches/xwiki-core-1.2/xwiki-core/src/main/java/com/xpn/xwiki/doc/rcs/XWikiPatch.java
Log:
XWIKI-1948: XML parsing error after deleting a version from the history
Fixed.
Merged from [EMAIL PROTECTED]


Modified: 
xwiki-platform/core/branches/xwiki-core-1.2/xwiki-core/src/main/java/com/xpn/xwiki/doc/XWikiDocumentArchive.java
===================================================================
--- 
xwiki-platform/core/branches/xwiki-core-1.2/xwiki-core/src/main/java/com/xpn/xwiki/doc/XWikiDocumentArchive.java
    2007-12-12 16:22:45 UTC (rev 6356)
+++ 
xwiki-platform/core/branches/xwiki-core-1.2/xwiki-core/src/main/java/com/xpn/xwiki/doc/XWikiDocumentArchive.java
    2007-12-12 16:24:03 UTC (rev 6357)
@@ -31,10 +31,10 @@
 import java.util.TreeMap;
 import java.util.TreeSet;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.suigeneris.jrcs.rcs.Version;
 import org.suigeneris.jrcs.util.ToString;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 
 import com.xpn.xwiki.XWikiContext;
 import com.xpn.xwiki.XWikiException;
@@ -43,6 +43,7 @@
 import com.xpn.xwiki.doc.rcs.XWikiRCSNodeContent;
 import com.xpn.xwiki.doc.rcs.XWikiRCSNodeId;
 import com.xpn.xwiki.doc.rcs.XWikiRCSNodeInfo;
+import com.xpn.xwiki.plugin.packaging.PackagePlugin;
 
 /**
  * Contains document history.
@@ -190,7 +191,6 @@
             XWikiRCSArchive archive = new XWikiRCSArchive(text);
             resetArchive();
             Collection nodes = archive.getNodes(getId());
-            boolean addNodeInfo = true;
             for (Iterator it = nodes.iterator(); it.hasNext();) {
                 XWikiRCSNodeInfo    nodeInfo    = (XWikiRCSNodeInfo) it.next();
                 XWikiRCSNodeContent nodeContent = (XWikiRCSNodeContent) 
it.next();
@@ -257,24 +257,29 @@
             return;
         }
         if (vfrom1 == null) {
-            // store full version in vto1
-            XWikiDocument docto1 = loadDocument(vto1, context);
+            // Deleting the most recent version.
+            // TODO: update the document to the new "most recent" version.
+            // Store full version in vto1
+            String xmlto1 = getVersionXml(vto1, context);
             XWikiRCSNodeInfo nito1 = getNode(vto1);
             XWikiRCSNodeContent ncto1 = nito1.getContent(context);
-            ncto1.getPatch().setFullVersion(docto1, context);
+            ncto1.getPatch().setFullVersion(xmlto1);
             nito1.setContent(ncto1);
             updateNode(nito1);
             getUpdatedNodeContents().add(ncto1);
         } else if (vto1 != null) {
-            XWikiDocument docfrom1    = loadDocument(vfrom1, context);
-            XWikiDocument docto1      = loadDocument(vto1, context);
+            // We're not deleting from the first version, so we must make a 
new diff jumping over
+            // the deleted versions.
+            String xmlfrom1 = getVersionXml(vfrom1, context);
+            String xmlto1 = getVersionXml(vto1, context);
             XWikiRCSNodeInfo nito1    = getNode(vto1);
             XWikiRCSNodeContent ncto1 = nito1.getContent(context);
-            ncto1.getPatch().setDiffVersion(docfrom1, docto1, context);
+            ncto1.getPatch().setDiffVersion(xmlfrom1, xmlto1, "");
             nito1.setContent(ncto1);
             updateNode(nito1);
             getUpdatedNodeContents().add(ncto1);
-        } // if (vto1==null) => nothing to do, except delete
+        }
+        // if (vto1==null) => nothing to do, except delete
         for (Iterator it = getNodes(vfrom0, vto0).iterator(); it.hasNext();) {
             XWikiRCSNodeInfo ni = (XWikiRCSNodeInfo) it.next();
             fullVersions.remove(ni.getId().getVersion());
@@ -295,20 +300,11 @@
         if (nodeInfo == null) {
             return null;            
         }
-        try {    
-            Version nearestFullVersion = getNearestFullVersion(version);
-            
-            List lstContent = loadRCSNodeContents(nearestFullVersion, version, 
context);
-            List origText = new ArrayList();
-            for (Iterator it = lstContent.iterator(); it.hasNext();) {
-                XWikiRCSNodeContent nodeContent = (XWikiRCSNodeContent) 
it.next();
-                nodeContent.getPatch().patch(origText);
-            }
-            
-            String content = ToString.arrayToString(origText.toArray());
+        try {
+            String content = getVersionXml(version, context);
             XWikiDocument doc = new XWikiDocument();
             doc.fromXML(content);
-            
+
             doc.setRCSVersion(version);
             doc.setComment(nodeInfo.getComment());
             doc.setDate(nodeInfo.getDate());
@@ -325,6 +321,19 @@
                     "Exception while reading document version {1}", e, args);
         }
     }
+    public String getVersionXml(Version version, XWikiContext context) throws 
XWikiException
+    {
+        Version nearestFullVersion = getNearestFullVersion(version);
+
+        List lstContent = loadRCSNodeContents(nearestFullVersion, version, 
context);
+        List origText = new ArrayList();
+        for (Iterator it = lstContent.iterator(); it.hasNext();) {
+            XWikiRCSNodeContent nodeContent = (XWikiRCSNodeContent) it.next();
+            nodeContent.getPatch().patch(origText);
+        }
+
+        return ToString.arrayToString(origText.toArray());
+    }
     /**
      * @return [EMAIL PROTECTED] XWikiRCSNodeInfo} by version. null if none.
      * @param version which version to get

Modified: 
xwiki-platform/core/branches/xwiki-core-1.2/xwiki-core/src/main/java/com/xpn/xwiki/doc/rcs/XWikiPatch.java
===================================================================
--- 
xwiki-platform/core/branches/xwiki-core-1.2/xwiki-core/src/main/java/com/xpn/xwiki/doc/rcs/XWikiPatch.java
  2007-12-12 16:22:45 UTC (rev 6356)
+++ 
xwiki-platform/core/branches/xwiki-core-1.2/xwiki-core/src/main/java/com/xpn/xwiki/doc/rcs/XWikiPatch.java
  2007-12-12 16:24:03 UTC (rev 6357)
@@ -82,50 +82,81 @@
         this.isDiff = isDiff;
     }
     /**
-     * Create full patch for document.
-     * @param doc - document to patch
-     * @param context - used for serialization document to xml
-     * @return self
+     * Store the XML export of the document as the history patch; this will be 
a history milestone.
+     * @param version Document version to store in the history patch.
+     * @param context Needed for serializing documents to xml.
+     * @return Self, with the patch content set to the XML export of the 
document version.
      * @throws XWikiException if any error
      */
-    public XWikiPatch setFullVersion(XWikiDocument doc, XWikiContext context) 
throws XWikiException
+    public XWikiPatch setFullVersion(XWikiDocument version, XWikiContext 
context)
+    throws XWikiException
     {
+        return setFullVersion(version.toXML(context));
+    }
+    /**
+     * Store the XML export of the document as the history patch; this will be 
a history milestone.
+     * @param versionXml Document version to store in the history patch, in 
the XML export format.
+     * @return Self, with the patch content set to the XML export of the 
document version.
+     * @throws XWikiException if any error occurs
+     */
+    public XWikiPatch setFullVersion(String versionXml) throws XWikiException
+    {
         setDiff(false);
-        setContent(doc.toXML(context));
+        setContent(versionXml);
         return this;
     }
     /**
-     * Create difference patch for document curdoc, using origdoc as previous 
version.
-     * @param curDoc  - current document
-     * @param origDoc - original document
-     * @param context - used for serialization documents to xml
-     * @return self
-     * @throws XWikiException if any error
+     * Create history patch between originalVersion and newVersion as 
difference on the XML export
+     * of the two versions. The patch is created between newVersion and 
originalVersion.
+     * @param newVersion Current version of the document.
+     * @param originalVersion Original version of the document document.
+     * @param context Needed for serializing documents to xml.
+     * @return Self, with the patch content set to the generated diff between 
the two version.
+     * @throws XWikiException if any error occurs
      */
-    public XWikiPatch setDiffVersion(XWikiDocument curDoc, XWikiDocument 
origDoc,
+    public XWikiPatch setDiffVersion(XWikiDocument newVersion, XWikiDocument 
originalVersion,
         XWikiContext context) throws XWikiException
     {
-        return setDiffVersion(curDoc, origDoc.toXML(context), context);
+        return setDiffVersion(newVersion.toXML(context), 
originalVersion.toXML(context),
+            newVersion.getFullName());
     }
     /**
-     * Create difference patch for document curdoc, using origdoc as previous 
version.
-     * @param curDoc     - current document
-     * @param origDocXml - xml of original document
-     * @param context    - used for serialization document to xml
-     * @return self
-     * @throws XWikiException if any error
+     * Create history patch between originalVersion and newVersion as 
difference on the XML export
+     * of the two versions. The patch is created between newVersion and 
originalVersion.
+     * @param newVersion Current version of the document.
+     * @param originalVersionXml Original version of the document document, in 
the XML export
+     * format.
+     * @param context Needed for serializing documents to xml.
+     * @return Self, with the patch content set to the generated diff between 
the two version.
+     * @throws XWikiException if any error occurs
      */
-    public XWikiPatch setDiffVersion(XWikiDocument curDoc, String origDocXml,
+    public XWikiPatch setDiffVersion(XWikiDocument newVersion, String 
originalVersionXml,
         XWikiContext context) throws XWikiException
     {
+        return setDiffVersion(newVersion.toXML(context), originalVersionXml,
+            newVersion.getFullName());
+    }
+    /**
+     * Create history patch between originalVersion and newVersion as 
difference on the XML export
+     * of the two versions. The patch is created between newVersion and 
originalVersion.
+     * @param newVersionXml Current version of the document, in the XML export 
format.
+     * @param originalVersionXml Original version of the document document, in 
the XML export
+     * format.
+     * @param docName Needed for the exception report.
+     * @return Self, with the patch content set to the generated diff between 
the two version.
+     * @throws XWikiException if any error occurs
+     */
+    public XWikiPatch setDiffVersion(String newVersionXml, String 
originalVersionXml,
+        String docName) throws XWikiException
+    {
         setDiff(true);
         try {
-            setContent(XWikiPatchUtils.getDiff(curDoc.toXML(context), 
origDocXml));
+            setContent(XWikiPatchUtils.getDiff(newVersionXml, 
originalVersionXml));
         } catch (Exception e) {
-            Object[] args = {curDoc.getFullName()};
+            Object[] args = {docName};
             throw new XWikiException(XWikiException.MODULE_XWIKI_DIFF, 
                 XWikiException.ERROR_XWIKI_DIFF_XML_ERROR, 
-                "Failed to create diff for doc {}", e, args);
+                "Failed to create diff for doc {0}", e, args);
         }
         return this;
     }

_______________________________________________
notifications mailing list
[email protected]
http://lists.xwiki.org/mailman/listinfo/notifications

Reply via email to