Index: src/test/java/com/xpn/xwiki/doc/XWikiDocumentArchiveTest.java =================================================================== --- src/test/java/com/xpn/xwiki/doc/XWikiDocumentArchiveTest.java (revision 3951) +++ src/test/java/com/xpn/xwiki/doc/XWikiDocumentArchiveTest.java (working copy) @@ -19,6 +19,10 @@ */ package com.xpn.xwiki.doc; +import java.util.Arrays; + +import com.xpn.xwiki.XWikiException; + import junit.framework.TestCase; /** @@ -37,117 +41,6 @@ */ public void testUpdateArchiveWhenSpaceInUsername() throws Exception { - String originalText = "\"\\n\\n" - + "\\nKnowledgeBase\\nWebHome\\n" - + "\\nen\\n0\\n" - + "Main.Notes\\nXWiki.Admin\\nXWiki.Admin" - + "\\n\\nXWiki.Admin\\n" - + "1165874272000\\n1172011434000\\n" - + "1172011434000\\n1.8\\n" - + "\\n\\n\\n" - + "\\n\\n\\nXWiki.TagClass" - + "\\n\\n\\n" - + "\\n\\n" - + "\\n\\n" - + "\\n\\ntags\\nTags\\n" - + "0\\n1\\n" - + "input\\n1\\n30\\n" - + " \\n ,|\\n\\n" - + "1\\ncom.xpn.xwiki.objects.classes.StaticListClass" - + "\\n\\n\\nKnowledgeBase.WebHome\\n" - + "0\\nXWiki.TagClass\\n\\n\\n" - + "\\n\\n1 Wiki Knowledge Base\\r\\n\\r\\nThis is the " - + "Wiki Knowledge Base, where you can start writing about your favorite subjects.\\r\\n" - + "\\r\\nTo create new pages, click edit button and write links using brackets around " - + "words.\\r\\n\\r\\n* [Example Link 1]\\r\\n* [Example Link 2]\\n" - + "\\n\""; - - String originalArchive = "head\t1.1;\n" + - "access;\n" + - "symbols;\n" + - "locks; strict;\n" + - "comment\t@# @;\n" + - "\n" + - "\n" + - "1.1\n" + - "date\t2007.02.14.14.01.57;\tauthor vmassol;\tstate Exp;\n" + - "branches;\n" + - "next\t;\n" + - "\n" + - "\n" + - "desc\n" + - "@@\n" + - "\n" + - "\n" + - "1.1\n" + - "log\n" + - "@KnowledgeBase.WebHome\n" + - "@\n" + - "text\n" + - "@\n" + - "\n" + - "\n" + - "KnowledgeBase\n" + - "WebHome\n" + - "\n" + - "en\n" + - "0\n" + - "Main.Notes\n" + - "XWiki.Admin\n" + - "XWiki.Admin\n" + - "\n" + - "XWiki.Admin\n" + - "1165874272000\n" + - "1166177448000\n" + - "1171458116000\n" + - "1.1\n" + - "\n" + - "\n" + - "\n" + - "\n" + - "\n" + - "\n" + - "XWiki.TagClass\n" + - "\n" + - "\n" + - "\n" + - "\n" + - "\n" + - "\n" + - "\n" + - "\n" + - "tags\n" + - "Tags\n" + - "0\n" + - "1\n" + - "checkbox\n" + - "1\n" + - "30\n" + - " \n" + - " ,|\n" + - "\n" + - "1\n" + - "com.xpn.xwiki.objects.classes.StaticListClass\n" + - "\n" + - "\n" + - "KnowledgeBase.WebHome\n" + - "0\n" + - "XWiki.TagClass\n" + - "\n" + - "\n" + - "\n" + - "\n" + - "1 Wiki Knowledge Base\n" + - "\n" + - "This is the Wiki Knowledge Base, where you can start writing about your favorite subjects.\n" + - "\n" + - "To create new pages, click edit button and write links using brackets around words.\n" + - "\n" + - "* [Example Link 1]\n" + - "* [Example Link 2]\n" + - "\n" + - "@"; - XWikiDocumentArchive archive = new XWikiDocumentArchive(123456789L); archive.setArchive(originalArchive); @@ -161,4 +54,133 @@ // with a space works. new XWikiDocumentArchive(123456789L).setArchive(archive.getArchive()); } + + public void testSetNodeDiffs() throws XWikiException { + XWikiDocumentArchive archive = new XWikiDocumentArchive(123456789L); + XWikiDocumentArchive archive2 = new XWikiDocumentArchive(123456789L); + archive.setArchive(originalArchive); + archive2.setDiffs(archive.getDiffs()); + assertEquals(archive.getArchive(), archive2.getArchive()); + assertTrue(Arrays.equals(archive.getDiffs(), archive2.getDiffs())); + + archive.updateArchive("Main.WebHome", originalText); + archive2.updateArchive("Main.WebHome", originalText); + assertEquals(archive.getArchive(), archive2.getArchive()); + assertTrue(Arrays.equals(archive.getDiffs(), archive2.getDiffs())); + + archive2.setDiffs(archive.getDiffs()); + assertEquals(archive.getArchive(), archive2.getArchive()); + assertTrue(Arrays.equals(archive.getDiffs(), archive2.getDiffs())); + } + + String originalText = "\"\\n\\n" + + "\\nKnowledgeBase\\nWebHome\\n" + + "\\nen\\n0\\n" + + "Main.Notes\\nXWiki.Admin\\nXWiki.Admin" + + "\\n\\nXWiki.Admin\\n" + + "1165874272000\\n1172011434000\\n" + + "1172011434000\\n1.8\\n" + + "\\n\\n\\n" + + "\\n\\n\\nXWiki.TagClass" + + "\\n\\n\\n" + + "\\n\\n" + + "\\n\\n" + + "\\n\\ntags\\nTags\\n" + + "0\\n1\\n" + + "input\\n1\\n30\\n" + + " \\n ,|\\n\\n" + + "1\\ncom.xpn.xwiki.objects.classes.StaticListClass" + + "\\n\\n\\nKnowledgeBase.WebHome\\n" + + "0\\nXWiki.TagClass\\n\\n\\n" + + "\\n\\n1 Wiki Knowledge Base\\r\\n\\r\\nThis is the " + + "Wiki Knowledge Base, where you can start writing about your favorite subjects.\\r\\n" + + "\\r\\nTo create new pages, click edit button and write links using brackets around " + + "words.\\r\\n\\r\\n* [Example Link 1]\\r\\n* [Example Link 2]\\n" + + "\\n\""; + + String originalArchive = "head\t1.1;\n" + + "access;\n" + + "symbols;\n" + + "locks; strict;\n" + + "comment\t@# @;\n" + + "\n" + + "\n" + + "1.1\n" + + "date\t2007.02.14.14.01.57;\tauthor vmassol;\tstate Exp;\n" + + "branches;\n" + + "next\t;\n" + + "\n" + + "\n" + + "desc\n" + + "@@\n" + + "\n" + + "\n" + + "1.1\n" + + "log\n" + + "@KnowledgeBase.WebHome\n" + + "@\n" + + "text\n" + + "@\n" + + "\n" + + "\n" + + "KnowledgeBase\n" + + "WebHome\n" + + "\n" + + "en\n" + + "0\n" + + "Main.Notes\n" + + "XWiki.Admin\n" + + "XWiki.Admin\n" + + "\n" + + "XWiki.Admin\n" + + "1165874272000\n" + + "1166177448000\n" + + "1171458116000\n" + + "1.1\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "XWiki.TagClass\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "tags\n" + + "Tags\n" + + "0\n" + + "1\n" + + "checkbox\n" + + "1\n" + + "30\n" + + " \n" + + " ,|\n" + + "\n" + + "1\n" + + "com.xpn.xwiki.objects.classes.StaticListClass\n" + + "\n" + + "\n" + + "KnowledgeBase.WebHome\n" + + "0\n" + + "XWiki.TagClass\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "1 Wiki Knowledge Base\n" + + "\n" + + "This is the Wiki Knowledge Base, where you can start writing about your favorite subjects.\n" + + "\n" + + "To create new pages, click edit button and write links using brackets around words.\n" + + "\n" + + "* [Example Link 1]\n" + + "* [Example Link 2]\n" + + "\n" + + "@"; } Index: src/main/java/com/xpn/xwiki/store/XWikiHibernateVersioningStore.java =================================================================== --- src/main/java/com/xpn/xwiki/store/XWikiHibernateVersioningStore.java (revision 3951) +++ src/main/java/com/xpn/xwiki/store/XWikiHibernateVersioningStore.java (working copy) @@ -1,18 +1,27 @@ package com.xpn.xwiki.store; +import java.util.List; + import com.xpn.xwiki.XWiki; import com.xpn.xwiki.XWikiContext; import com.xpn.xwiki.XWikiException; import com.xpn.xwiki.doc.XWikiDocument; import com.xpn.xwiki.doc.XWikiDocumentArchive; +import com.xpn.xwiki.doc.rcs.XWikiRCSArchive; +import com.xpn.xwiki.doc.rcs.XWikiRCSNode; +import com.xpn.xwiki.doc.rcs.XWikiRCSStoreNode; import com.xpn.xwiki.monitor.api.MonitorPlugin; import com.xpn.xwiki.util.Util; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.hibernate.Criteria; +import org.hibernate.HibernateException; +import org.hibernate.LockMode; import org.hibernate.ObjectNotFoundException; import org.hibernate.Session; +import org.hibernate.criterion.Restrictions; import org.suigeneris.jrcs.rcs.Archive; -import org.suigeneris.jrcs.rcs.Node; +import org.suigeneris.jrcs.rcs.impl.Node; import org.suigeneris.jrcs.rcs.Version; /** @@ -48,7 +57,7 @@ public Version[] getXWikiDocVersions(XWikiDocument doc, XWikiContext context) throws XWikiException { try { - Archive archive = getXWikiDocumentArchive(doc, context).getRCSArchive(); + XWikiRCSArchive archive = getXWikiDocumentArchive(doc, context).getRCSArchive(); if (archive==null) return new Version[0]; @@ -107,13 +116,21 @@ bTransaction = beginTransaction(false, context); } Session session = getSession(context); - - try { - session.load(archivedoc, new Long(archivedoc.getId())); + + List diffs = session.createCriteria(XWikiRCSStoreNode.class) + .add(Restrictions.eq("id", Long.valueOf(archivedoc.getId()))) + .list(); + if (diffs.size()>0) { + XWikiRCSNode[] nodes = new XWikiRCSNode[diffs.size()]; + for (int i=0; i>> 32)); + result = prime * result + ((version == null) ? 0 : version.hashCode()); + return result; + } + + public boolean equals(Object obj) + { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + final XWikiRCSStoreNode other = (XWikiRCSStoreNode) obj; + if (delta == null) { + if (other.delta != null) + return false; + } else if (!delta.equals(other.delta)) + return false; + if (docId != other.docId) + return false; + if (version == null) { + if (other.version != null) + return false; + } else if (!version.equals(other.version)) + return false; + return true; + } +} Property changes on: src/main/java/com/xpn/xwiki/doc/rcs/XWikiRCSStoreNode.java ___________________________________________________________________ Name: svn:eol-style + native Index: src/main/java/com/xpn/xwiki/doc/rcs/XWikiRCSNode.java =================================================================== --- src/main/java/com/xpn/xwiki/doc/rcs/XWikiRCSNode.java (revision 0) +++ src/main/java/com/xpn/xwiki/doc/rcs/XWikiRCSNode.java (revision 0) @@ -0,0 +1,37 @@ +package com.xpn.xwiki.doc.rcs; + +import org.suigeneris.jrcs.rcs.InvalidTrunkVersionNumberException; +import org.suigeneris.jrcs.rcs.Version; +import org.suigeneris.jrcs.rcs.impl.TrunkNode; + +public class XWikiRCSNode extends TrunkNode +{ + public XWikiRCSNode(Version vernum, TrunkNode next) throws InvalidTrunkVersionNumberException + { + super(vernum, next); + } + + public String getDelta() { + return text; + } + + XWikiRCSStoreNode storeNode; + public XWikiRCSStoreNode getStoreNode() + { + return storeNode; + } + + public void setStoreNode(XWikiRCSStoreNode storeNode) + { + this.storeNode = storeNode; + } + + public boolean equals(Object obj) + { + if (obj instanceof XWikiRCSNode) { + XWikiRCSNode node = (XWikiRCSNode) obj; + return getVersion().equals( node.getVersion() ) + && getDelta().equals( node.getDelta() ); + } else return false; + } +} Property changes on: src/main/java/com/xpn/xwiki/doc/rcs/XWikiRCSNode.java ___________________________________________________________________ Name: svn:eol-style + native Index: src/main/java/com/xpn/xwiki/doc/XWikiDocument.java =================================================================== --- src/main/java/com/xpn/xwiki/doc/XWikiDocument.java (revision 3951) +++ src/main/java/com/xpn/xwiki/doc/XWikiDocument.java (working copy) @@ -54,7 +54,6 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.ecs.filter.CharacterFilter; -import org.apache.oro.text.regex.MalformedPatternException; import org.apache.velocity.VelocityContext; import org.apache.velocity.app.tools.VelocityFormatter; import org.dom4j.Document; Index: src/main/java/com/xpn/xwiki/doc/XWikiDocumentArchive.java =================================================================== --- src/main/java/com/xpn/xwiki/doc/XWikiDocumentArchive.java (revision 3951) +++ src/main/java/com/xpn/xwiki/doc/XWikiDocumentArchive.java (working copy) @@ -1,17 +1,20 @@ package com.xpn.xwiki.doc; import com.xpn.xwiki.XWikiException; +import com.xpn.xwiki.doc.rcs.XWikiRCSArchive; +import com.xpn.xwiki.doc.rcs.XWikiRCSNode; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.tools.ant.filters.StringInputStream; -import org.suigeneris.jrcs.rcs.Archive; +import org.suigeneris.jrcs.rcs.impl.Node; import org.suigeneris.jrcs.util.ToString; public class XWikiDocumentArchive { private static final Log log = LogFactory.getLog(XWikiDocumentArchive.class); private long id; - private Archive archive; + private XWikiRCSArchive archive; public XWikiDocumentArchive() { } @@ -28,11 +31,11 @@ this.id = id; } - public Archive getRCSArchive() { + public XWikiRCSArchive getRCSArchive() { return archive; } - public void setRCSArchive(Archive archive) { + public void setRCSArchive(XWikiRCSArchive archive) { this.archive = archive; } @@ -45,22 +48,21 @@ return buffer.toString(); } } - public void setArchive(String text) throws XWikiException { try { if ((text!=null)&&(!text.trim().equals(""))) { StringInputStream is = new StringInputStream(text); - archive = new Archive("", is); + archive = new XWikiRCSArchive("", is); } else if (text == null){ Object[] lines = new Object[1]; lines[0] = ""; - archive = new Archive(lines, "", "1.0"); + archive = new XWikiRCSArchive(lines, "", "1.0"); } else { Object[] lines = ToString.stringToArray(text); - archive = new Archive(lines, "", "1.0"); + archive = new XWikiRCSArchive(lines, "", "1.0"); } } catch (Exception e) { @@ -90,7 +92,7 @@ if (archive != null) archive.addRevision(lines, ""); else - archive = new Archive(lines, docname, "1.0"); + archive = new XWikiRCSArchive(lines, docname, "1.0"); } catch (Exception e) { Object[] args = { docname }; @@ -134,7 +136,7 @@ public void resetArchive(String docname, String text, String version) throws XWikiException { Object[] lines = ToString.stringToArray(text); - archive = new Archive(lines, docname, version); + archive = new XWikiRCSArchive(lines, docname, version); } /** @@ -146,4 +148,15 @@ return "id = [" + getId() + "], archive = [" + (getRCSArchive() == null ? "null" : getRCSArchive().toString()) + "]"; } + + public void setDiffs(XWikiRCSNode[] diffs) { + archive = new XWikiRCSArchive(diffs); + } + public XWikiRCSNode[] getDiffs() { + Node[] changelog = getRCSArchive().changeLog(); + XWikiRCSNode[] diffs = new XWikiRCSNode[changelog.length]; + for (int i=0; i + + + + + + + + + + Index: pom.xml =================================================================== --- pom.xml (revision 3951) +++ pom.xml (working copy) @@ -83,14 +83,12 @@ org.suigeneris jrcs.diff - 0.3.0 - xwiki + 0.4.1 org.suigeneris jrcs.rcs - 0.3.0 - xwiki + 0.4.1