[xwiki-notifications] r96 - in wysiwyg: . src/main src/main/java/com/xpn/xwiki/wysiwyg/client src/main/java/com/xpn/xwiki/wysiwyg/client/diff src/main/java/com/xpn/xwiki/wysiwyg/client/diff/myers src/main/java/com/xpn/xwiki/wysiwyg/client/ui
ludovic (SVN)
notifications at xwiki.org
Mon Mar 3 09:28:56 CET 2008
Author: ludovic
Date: 2008-03-03 09:28:56 +0100 (Mon, 03 Mar 2008)
New Revision: 96
Added:
wysiwyg/src/main/java/com/xpn/xwiki/wysiwyg/client/diff/
wysiwyg/src/main/java/com/xpn/xwiki/wysiwyg/client/diff/AddDelta.java
wysiwyg/src/main/java/com/xpn/xwiki/wysiwyg/client/diff/ChangeDelta.java
wysiwyg/src/main/java/com/xpn/xwiki/wysiwyg/client/diff/Chunk.java
wysiwyg/src/main/java/com/xpn/xwiki/wysiwyg/client/diff/DeleteDelta.java
wysiwyg/src/main/java/com/xpn/xwiki/wysiwyg/client/diff/Delta.java
wysiwyg/src/main/java/com/xpn/xwiki/wysiwyg/client/diff/Diff.java
wysiwyg/src/main/java/com/xpn/xwiki/wysiwyg/client/diff/DiffAlgorithm.java
wysiwyg/src/main/java/com/xpn/xwiki/wysiwyg/client/diff/DiffException.java
wysiwyg/src/main/java/com/xpn/xwiki/wysiwyg/client/diff/DifferentiationFailedException.java
wysiwyg/src/main/java/com/xpn/xwiki/wysiwyg/client/diff/PatchFailedException.java
wysiwyg/src/main/java/com/xpn/xwiki/wysiwyg/client/diff/Revision.java
wysiwyg/src/main/java/com/xpn/xwiki/wysiwyg/client/diff/RevisionVisitor.java
wysiwyg/src/main/java/com/xpn/xwiki/wysiwyg/client/diff/SimpleDiff.java
wysiwyg/src/main/java/com/xpn/xwiki/wysiwyg/client/diff/ToString.java
wysiwyg/src/main/java/com/xpn/xwiki/wysiwyg/client/diff/myers/
wysiwyg/src/main/java/com/xpn/xwiki/wysiwyg/client/diff/myers/DiffNode.java
wysiwyg/src/main/java/com/xpn/xwiki/wysiwyg/client/diff/myers/MyersDiff.java
wysiwyg/src/main/java/com/xpn/xwiki/wysiwyg/client/diff/myers/PathNode.java
wysiwyg/src/main/java/com/xpn/xwiki/wysiwyg/client/diff/myers/Snake.java
wysiwyg/src/main/resources/
Modified:
wysiwyg/pom.xml
wysiwyg/src/main/java/com/xpn/xwiki/wysiwyg/client/Wysiwyg.java
wysiwyg/src/main/java/com/xpn/xwiki/wysiwyg/client/ui/EditorWidget.java
wysiwyg/standard.pom.xml
wysiwyg/web.pom.xml
Log:
More experimental code for the Wysiwyg with diff and merge code
Modified: wysiwyg/pom.xml
===================================================================
--- wysiwyg/pom.xml 2008-02-29 17:38:00 UTC (rev 95)
+++ wysiwyg/pom.xml 2008-03-03 08:28:56 UTC (rev 96)
@@ -3,13 +3,13 @@
<parent>
<groupId>com.xpn.xwiki.products</groupId>
<artifactId>xwiki-web</artifactId>
- <version>1.3-SNAPSHOT</version>
+ <version>1.4-SNAPSHOT</version>
</parent>
<artifactId>xwiki-web-wysiwyg</artifactId>
<name>XWiki - Wysiwyg - GWT</name>
<packaging>pom</packaging>
<description>XWiki Wysiwyg - GWT</description>
- <version>1.3-SNAPSHOT</version>
+ <version>1.4-SNAPSHOT</version>
<properties>
<gwtVersion>1.4.61</gwtVersion>
</properties>
Modified: wysiwyg/src/main/java/com/xpn/xwiki/wysiwyg/client/Wysiwyg.java
===================================================================
--- wysiwyg/src/main/java/com/xpn/xwiki/wysiwyg/client/Wysiwyg.java 2008-02-29 17:38:00 UTC (rev 95)
+++ wysiwyg/src/main/java/com/xpn/xwiki/wysiwyg/client/Wysiwyg.java 2008-03-03 08:28:56 UTC (rev 96)
@@ -146,6 +146,7 @@
RootPanel.get("Wysiwyg").add(userInterface);
// Load the feed list and other info
+ /*
config.refreshConfig(new XWikiAsyncCallback(this) {
public void onSuccess(Object object) {
super.onSuccess(object);
@@ -154,6 +155,7 @@
userInterface.resizeWindow();
}
});
+ */
dataManager.convertXWiki2Html(getProperty("page"), new XWikiAsyncCallback(this) {
public void onSuccess(Object result) {
Added: wysiwyg/src/main/java/com/xpn/xwiki/wysiwyg/client/diff/AddDelta.java
===================================================================
--- wysiwyg/src/main/java/com/xpn/xwiki/wysiwyg/client/diff/AddDelta.java (rev 0)
+++ wysiwyg/src/main/java/com/xpn/xwiki/wysiwyg/client/diff/AddDelta.java 2008-03-03 08:28:56 UTC (rev 96)
@@ -0,0 +1,125 @@
+/*
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 1999-2003 The Apache Software Foundation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ * any, must include the following acknowledgement:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgement may appear in the software itself,
+ * if and wherever such third-party acknowledgements normally appear.
+ *
+ * 4. The names "The Jakarta Project", "Commons", and "Apache Software
+ * Foundation" must not be used to endorse or promote products derived
+ * from this software without prior written permission. For written
+ * permission, please contact apache at apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache"
+ * nor may "Apache" appear in their names without prior written
+ * permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package com.xpn.xwiki.wysiwyg.client.diff;
+
+import java.util.List;
+
+/**
+ * Holds an add-delta between to revisions of a text.
+ *
+ * @version $Id: AddDelta.java,v 1.1 2006/03/12 00:24:21 juanca Exp $
+ * @author <a href="mailto:juanco at suigeneris.org">Juanco Anez</a>
+ * @see Delta
+ * @see Diff
+ * @see Chunk
+ */
+public class AddDelta extends Delta
+{
+
+ AddDelta()
+ {
+ super();
+ }
+
+ public AddDelta(int origpos, Chunk rev)
+ {
+ init(new Chunk(origpos, 0), rev);
+ }
+
+ public void verify(List target) throws PatchFailedException
+ {
+ if (original.first() > target.size())
+ {
+ throw new PatchFailedException("original.first() > target.size()");
+ }
+ }
+
+ public void applyTo(List target)
+ {
+ revised.applyAdd(original.first(), target);
+ }
+
+ public void toString(StringBuffer s)
+ {
+ s.append(original.anchor());
+ s.append("a");
+ s.append(revised.rangeString());
+ s.append(Diff.NL);
+ revised.toString(s, "> ", Diff.NL);
+ }
+
+ public void toRCSString(StringBuffer s, String EOL)
+ {
+ s.append("a");
+ s.append(original.anchor());
+ s.append(" ");
+ s.append(revised.size());
+ s.append(EOL);
+ revised.toString(s, "", EOL);
+ }
+
+ public void Accept(RevisionVisitor visitor)
+ {
+ visitor.visit(this);
+ }
+
+ public void accept(RevisionVisitor visitor)
+ {
+ visitor.visit(this);
+ }
+}
Added: wysiwyg/src/main/java/com/xpn/xwiki/wysiwyg/client/diff/ChangeDelta.java
===================================================================
--- wysiwyg/src/main/java/com/xpn/xwiki/wysiwyg/client/diff/ChangeDelta.java (rev 0)
+++ wysiwyg/src/main/java/com/xpn/xwiki/wysiwyg/client/diff/ChangeDelta.java 2008-03-03 08:28:56 UTC (rev 96)
@@ -0,0 +1,133 @@
+/*
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 1999-2003 The Apache Software Foundation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ * any, must include the following acknowledgement:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgement may appear in the software itself,
+ * if and wherever such third-party acknowledgements normally appear.
+ *
+ * 4. The names "The Jakarta Project", "Commons", and "Apache Software
+ * Foundation" must not be used to endorse or promote products derived
+ * from this software without prior written permission. For written
+ * permission, please contact apache at apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache"
+ * nor may "Apache" appear in their names without prior written
+ * permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package com.xpn.xwiki.wysiwyg.client.diff;
+
+import java.util.List;
+
+/**
+ * Holds an change-delta between to revisions of a text.
+ *
+ * @version $Id: ChangeDelta.java,v 1.1 2006/03/12 00:24:21 juanca Exp $
+ * @author <a href="mailto:juanco at suigeneris.org">Juanco Anez</a>
+ * @see Delta
+ * @see Diff
+ * @see Chunk
+ */
+public class ChangeDelta extends Delta
+{
+
+ ChangeDelta()
+ {
+ super();
+ }
+
+ public ChangeDelta(Chunk orig, Chunk rev)
+ {
+ init(orig, rev);
+ }
+
+ public void verify(List target) throws PatchFailedException
+ {
+ if (!original.verify(target))
+ {
+ throw new PatchFailedException();
+ }
+ if (original.first() > target.size())
+ {
+ throw new PatchFailedException("original.first() > target.size()");
+ }
+ }
+
+ public void applyTo(List target)
+ {
+ original.applyDelete(target);
+ revised.applyAdd(original.first(), target);
+ }
+
+ public void toString(StringBuffer s)
+ {
+ original.rangeString(s);
+ s.append("c");
+ revised.rangeString(s);
+ s.append(Diff.NL);
+ original.toString(s, "< ", "\n");
+ s.append("---");
+ s.append(Diff.NL);
+ revised.toString(s, "> ", "\n");
+ }
+
+ public void toRCSString(StringBuffer s, String EOL)
+ {
+ s.append("d");
+ s.append(original.rcsfrom());
+ s.append(" ");
+ s.append(original.size());
+ s.append(EOL);
+ s.append("a");
+ s.append(original.rcsto());
+ s.append(" ");
+ s.append(revised.size());
+ s.append(EOL);
+ revised.toString(s, "", EOL);
+ }
+
+ public void accept(RevisionVisitor visitor)
+ {
+ visitor.visit(this);
+ }
+}
Added: wysiwyg/src/main/java/com/xpn/xwiki/wysiwyg/client/diff/Chunk.java
===================================================================
--- wysiwyg/src/main/java/com/xpn/xwiki/wysiwyg/client/diff/Chunk.java (rev 0)
+++ wysiwyg/src/main/java/com/xpn/xwiki/wysiwyg/client/diff/Chunk.java 2008-03-03 08:28:56 UTC (rev 96)
@@ -0,0 +1,410 @@
+/*
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 1999-2003 The Apache Software Foundation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ * any, must include the following acknowledgement:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgement may appear in the software itself,
+ * if and wherever such third-party acknowledgements normally appear.
+ *
+ * 4. The names "The Jakarta Project", "Commons", and "Apache Software
+ * Foundation" must not be used to endorse or promote products derived
+ * from this software without prior written permission. For written
+ * permission, please contact apache at apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache"
+ * nor may "Apache" appear in their names without prior written
+ * permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package com.xpn.xwiki.wysiwyg.client.diff;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * Holds a information about a parrt of the text involved in a differencing or
+ * patching operation.
+ *
+ * @version $Id: Chunk.java,v 1.1 2006/03/12 00:24:21 juanca Exp $
+ * @author <a href="mailto:juanco at suigeneris.org">Juanco Anez</a>
+ * @see Diff
+ * @see Delta
+ */
+public class Chunk extends ToString
+{
+
+ protected int anchor;
+
+ protected int count;
+
+ protected List chunk;
+
+ /**
+ * Creates a chunk that doesn't copy the original text.
+ *
+ * @param pos
+ * the start position in the text.
+ * @param count
+ * the size of the chunk.
+ */
+ public Chunk(int pos, int count)
+ {
+ this.anchor = pos;
+ this.count = (count >= 0 ? count : 0);
+ }
+
+ /**
+ * Creates a chunk and saves a copy the original chunk's text.
+ *
+ * @param iseq
+ * the original text.
+ * @param pos
+ * the start position in the text.
+ * @param count
+ * the size of the chunk.
+ */
+ public Chunk(Object[] iseq, int pos, int count)
+ {
+ this(pos, count);
+ chunk = slice(iseq, pos, count);
+ }
+
+ /**
+ * Creates a chunk that will be displaced in the resulting text, and saves a
+ * copy the original chunk's text.
+ *
+ * @param iseq
+ * the original text.
+ * @param pos
+ * the start position in the text.
+ * @param count
+ * the size of the chunk.
+ * @param offset
+ * the position the chunk should have in the resulting text.
+ */
+ public Chunk(Object[] iseq, int pos, int count, int offset)
+ {
+ this(offset, count);
+ chunk = slice(iseq, pos, count);
+ }
+
+ /**
+ * Creates a chunk and saves a copy the original chunk's text.
+ *
+ * @param iseq
+ * the original text.
+ * @param pos
+ * the start position in the text.
+ * @param count
+ * the size of the chunk.
+ */
+ public Chunk(List iseq, int pos, int count)
+ {
+ this(pos, count);
+ chunk = slice(iseq, pos, count);
+ }
+
+ /**
+ * Creates a chunk that will be displaced in the resulting text, and saves a
+ * copy the original chunk's text.
+ *
+ * @param iseq
+ * the original text.
+ * @param pos
+ * the start position in the text.
+ * @param count
+ * the size of the chunk.
+ * @param offset
+ * the position the chunk should have in the resulting text.
+ */
+ public Chunk(List iseq, int pos, int count, int offset)
+ {
+ this(offset, count);
+ chunk = slice(iseq, pos, count);
+ }
+
+ /**
+ * Returns the anchor position of the chunk.
+ *
+ * @return the anchor position.
+ */
+ public int anchor()
+ {
+ return anchor;
+ }
+
+ /**
+ * Returns the size of the chunk.
+ *
+ * @return the size.
+ */
+ public int size()
+ {
+ return count;
+ }
+
+ /**
+ * Returns the index of the first line of the chunk.
+ */
+ public int first()
+ {
+ return anchor();
+ }
+
+ /**
+ * Returns the index of the last line of the chunk.
+ */
+ public int last()
+ {
+ return anchor() + size() - 1;
+ }
+
+ /**
+ * Returns the <i>from</i> index of the chunk in RCS terms.
+ */
+ public int rcsfrom()
+ {
+ return anchor + 1;
+ }
+
+ /**
+ * Returns the <i>to</i> index of the chunk in RCS terms.
+ */
+ public int rcsto()
+ {
+ return anchor + count;
+ }
+
+ /**
+ * Returns the text saved for this chunk.
+ *
+ * @return the text.
+ */
+ public List chunk()
+ {
+ return chunk;
+ }
+
+ /**
+ * Verifies that this chunk's saved text matches the corresponding text in
+ * the given sequence.
+ *
+ * @param target
+ * the sequence to verify against.
+ * @return true if the texts match.
+ */
+ public boolean verify(List target)
+ {
+ if (chunk == null)
+ {
+ return true;
+ }
+ if (last() > target.size())
+ {
+ return false;
+ }
+ for (int i = 0; i < count; i++)
+ {
+ if (!target.get(anchor + i).equals(chunk.get(i)))
+ {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Delete this chunk from he given text.
+ *
+ * @param target
+ * the text to delete from.
+ */
+ public void applyDelete(List target)
+ {
+ for (int i = last(); i >= first(); i--)
+ {
+ target.remove(i);
+ }
+ }
+
+ /**
+ * Add the text of this chunk to the target at the given position.
+ *
+ * @param start
+ * where to add the text.
+ * @param target
+ * the text to add to.
+ */
+ public void applyAdd(int start, List target)
+ {
+ Iterator i = chunk.iterator();
+ while (i.hasNext())
+ {
+ target.add(start++, i.next());
+ }
+ }
+
+ /**
+ * Provide a string image of the chunk using the an empty prefix and
+ * postfix.
+ */
+ public void toString(StringBuffer s)
+ {
+ toString(s, "", "");
+ }
+
+ /**
+ * Provide a string image of the chunk using the given prefix and postfix.
+ *
+ * @param s
+ * where the string image should be appended.
+ * @param prefix
+ * the text thatshould prefix each line.
+ * @param postfix
+ * the text that should end each line.
+ */
+ public StringBuffer toString(StringBuffer s, String prefix, String postfix)
+ {
+ if (chunk != null)
+ {
+ Iterator i = chunk.iterator();
+ while (i.hasNext())
+ {
+ s.append(prefix);
+ s.append(i.next());
+ s.append(postfix);
+ }
+ }
+ return s;
+ }
+
+ /**
+ * Retreives the specified part from a {@link List List}.
+ *
+ * @param seq
+ * the list to retreive a slice from.
+ * @param pos
+ * the start position.
+ * @param count
+ * the number of items in the slice.
+ * @return a {@link List List} containing the specified items.
+ */
+ public static List slice(List seq, int pos, int count)
+ {
+ ArrayList list = new ArrayList();
+ if (count <= 0)
+ {
+ if (pos<seq.size())
+ list.add(seq.get(pos));
+ return list;
+ }
+ else
+ {
+ for (int i=pos;i<pos+count;i++) {
+ if (i<seq.size())
+ list.add(seq.get(i));
+ }
+ return list;
+ }
+ }
+
+ /**
+ * Retrieves a slice from an {@link Object Object} array.
+ *
+ * @param seq
+ * the list to retreive a slice from.
+ * @param pos
+ * the start position.
+ * @param count
+ * the number of items in the slice.
+ * @return a {@link List List} containing the specified items.
+ */
+ public static List slice(Object[] seq, int pos, int count)
+ {
+ return slice(Arrays.asList(seq), pos, count);
+ }
+
+ /**
+ * Provide a string representation of the numeric range of this chunk.
+ */
+ public String rangeString()
+ {
+ StringBuffer result = new StringBuffer();
+ rangeString(result);
+ return result.toString();
+ }
+
+ /**
+ * Provide a string representation of the numeric range of this chunk.
+ *
+ * @param s
+ * where the string representation should be appended.
+ */
+ public void rangeString(StringBuffer s)
+ {
+ rangeString(s, ",");
+ }
+
+ /**
+ * Provide a string representation of the numeric range of this chunk.
+ *
+ * @param s
+ * where the string representation should be appended.
+ * @param separ
+ * what to use as line separator.
+ */
+ public void rangeString(StringBuffer s, String separ)
+ {
+ if (size() <= 1)
+ {
+ s.append(Integer.toString(rcsfrom()));
+ }
+ else
+ {
+ s.append(Integer.toString(rcsfrom()));
+ s.append(separ);
+ s.append(Integer.toString(rcsto()));
+ }
+ }
+}
\ No newline at end of file
Added: wysiwyg/src/main/java/com/xpn/xwiki/wysiwyg/client/diff/DeleteDelta.java
===================================================================
--- wysiwyg/src/main/java/com/xpn/xwiki/wysiwyg/client/diff/DeleteDelta.java (rev 0)
+++ wysiwyg/src/main/java/com/xpn/xwiki/wysiwyg/client/diff/DeleteDelta.java 2008-03-03 08:28:56 UTC (rev 96)
@@ -0,0 +1,119 @@
+/*
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 1999-2003 The Apache Software Foundation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ * any, must include the following acknowledgement:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgement may appear in the software itself,
+ * if and wherever such third-party acknowledgements normally appear.
+ *
+ * 4. The names "The Jakarta Project", "Commons", and "Apache Software
+ * Foundation" must not be used to endorse or promote products derived
+ * from this software without prior written permission. For written
+ * permission, please contact apache at apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache"
+ * nor may "Apache" appear in their names without prior written
+ * permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package com.xpn.xwiki.wysiwyg.client.diff;
+
+import java.util.List;
+
+/**
+ * Holds a delete-delta between to revisions of a text.
+ *
+ * @version $Id: DeleteDelta.java,v 1.1 2006/03/12 00:24:21 juanca Exp $
+ * @author <a href="mailto:juanco at suigeneris.org">Juanco Anez</a>
+ * @see Delta
+ * @see Diff
+ * @see Chunk
+ */
+public class DeleteDelta extends Delta
+{
+
+ DeleteDelta()
+ {
+ super();
+ }
+
+ public DeleteDelta(Chunk orig)
+ {
+ init(orig, null);
+ }
+
+ public void verify(List target) throws PatchFailedException
+ {
+ if (!original.verify(target))
+ {
+ throw new PatchFailedException();
+ }
+ }
+
+ public void applyTo(List target)
+ {
+ original.applyDelete(target);
+ }
+
+ public void toString(StringBuffer s)
+ {
+ s.append(original.rangeString());
+ s.append("d");
+ s.append(revised.rcsto());
+ s.append(Diff.NL);
+ original.toString(s, "< ", Diff.NL);
+ }
+
+ public void toRCSString(StringBuffer s, String EOL)
+ {
+ s.append("d");
+ s.append(original.rcsfrom());
+ s.append(" ");
+ s.append(original.size());
+ s.append(EOL);
+ }
+
+ public void accept(RevisionVisitor visitor)
+ {
+ visitor.visit(this);
+ }
+}
\ No newline at end of file
Added: wysiwyg/src/main/java/com/xpn/xwiki/wysiwyg/client/diff/Delta.java
===================================================================
--- wysiwyg/src/main/java/com/xpn/xwiki/wysiwyg/client/diff/Delta.java (rev 0)
+++ wysiwyg/src/main/java/com/xpn/xwiki/wysiwyg/client/diff/Delta.java 2008-03-03 08:28:56 UTC (rev 96)
@@ -0,0 +1,257 @@
+/*
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 1999-2003 The Apache Software Foundation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ * any, must include the following acknowledgement:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgement may appear in the software itself,
+ * if and wherever such third-party acknowledgements normally appear.
+ *
+ * 4. The names "The Jakarta Project", "Commons", and "Apache Software
+ * Foundation" must not be used to endorse or promote products derived
+ * from this software without prior written permission. For written
+ * permission, please contact apache at apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache"
+ * nor may "Apache" appear in their names without prior written
+ * permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package com.xpn.xwiki.wysiwyg.client.diff;
+
+import java.util.List;
+
+/**
+ * Holds a "delta" difference between to revisions of a text.
+ *
+ * @version $Revision: 1.1 $ $Date: 2006/03/12 00:24:21 $
+ *
+ * @author <a href="mailto:juanco at suigeneris.org">Juanco Anez</a>
+ * @author <a href="mailto:bwm at hplb.hpl.hp.com">Brian McBride</a>
+ * @see Diff
+ * @see Chunk
+ * @see Revision
+ *
+ * modifications
+ *
+ * 27 Apr 2003 bwm
+ *
+ * Added getOriginal() and getRevised() accessor methods Added visitor pattern
+ * accept() method
+ */
+
+public abstract class Delta extends ToString
+{
+
+ protected Chunk original;
+
+ protected Chunk revised;
+
+
+ /**
+ * Returns a Delta that corresponds to the given chunks in the original and
+ * revised text respectively.
+ *
+ * @param orig
+ * the chunk in the original text.
+ * @param rev
+ * the chunk in the revised text.
+ */
+ public static Delta newDelta(Chunk orig, Chunk rev)
+ {
+ Delta result;
+ if ((orig.size()>0)&&(rev.size()>0))
+ result = new ChangeDelta();
+ else if ((orig.size()==0)&&(rev.size()==0))
+ result = new ChangeDelta();
+ else if ((orig.size()>0)&&(rev.size()==0))
+ result = new DeleteDelta();
+ else if ((orig.size()==0)&&(rev.size()>0))
+ result = new AddDelta();
+ else
+ return null;
+
+ result.init(orig, rev);
+ return result;
+ }
+
+ /**
+ * Creates an uninitialized delta.
+ */
+ protected Delta()
+ {
+ }
+
+ /**
+ * Creates a delta object with the given chunks from the original and
+ * revised texts.
+ */
+ protected Delta(Chunk orig, Chunk rev)
+ {
+ init(orig, rev);
+ }
+
+ /**
+ * Initializaes the delta with the given chunks from the original and
+ * revised texts.
+ */
+ protected void init(Chunk orig, Chunk rev)
+ {
+ original = orig;
+ revised = rev;
+ }
+
+ /**
+ * Verifies that this delta can be used to patch the given text.
+ *
+ * @param target
+ * the text to patch.
+ * @throws PatchFailedException
+ * if the patch cannot be applied.
+ */
+ public abstract void verify(List target) throws PatchFailedException;
+
+ /**
+ * Applies this delta as a patch to the given text.
+ *
+ * @param target
+ * the text to patch.
+ * @throws PatchFailedException
+ * if the patch cannot be applied.
+ */
+ public final void patch(List target) throws PatchFailedException
+ {
+ verify(target);
+ try
+ {
+ applyTo(target);
+ }
+ catch (Exception e)
+ {
+ throw new PatchFailedException(e.getMessage());
+ }
+ }
+
+ /**
+ * Applies this delta as a patch to the given text.
+ *
+ * @param target
+ * the text to patch.
+ * @throws PatchFailedException
+ * if the patch cannot be applied.
+ */
+ public abstract void applyTo(List target);
+
+ /**
+ * Converts this delta into its Unix diff style string representation.
+ *
+ * @param s
+ * a {@link StringBuffer StringBuffer} to which the string
+ * representation will be appended.
+ */
+ public void toString(StringBuffer s)
+ {
+ original.rangeString(s);
+ s.append("x");
+ revised.rangeString(s);
+ s.append(Diff.NL);
+ original.toString(s, "> ", "\n");
+ s.append("---");
+ s.append(Diff.NL);
+ revised.toString(s, "< ", "\n");
+ }
+
+ /**
+ * Converts this delta into its RCS style string representation.
+ *
+ * @param s
+ * a {@link StringBuffer StringBuffer} to which the string
+ * representation will be appended.
+ * @param EOL
+ * the string to use as line separator.
+ */
+ public abstract void toRCSString(StringBuffer s, String EOL);
+
+ /**
+ * Converts this delta into its RCS style string representation.
+ *
+ * @param EOL
+ * the string to use as line separator.
+ */
+ public String toRCSString(String EOL)
+ {
+ StringBuffer s = new StringBuffer();
+ toRCSString(s, EOL);
+ return s.toString();
+ }
+
+ /**
+ * Accessor method to return the chunk representing the original sequence of
+ * items
+ *
+ * @return the original sequence
+ */
+ public Chunk getOriginal()
+ {
+ return original;
+ }
+
+ /**
+ * Accessor method to return the chunk representing the updated sequence of
+ * items.
+ *
+ * @return the updated sequence
+ */
+ public Chunk getRevised()
+ {
+ return revised;
+ }
+
+ /**
+ * Accepts a visitor.
+ * <p>
+ * See the Visitor pattern in "Design Patterns" by the GOF4.
+ *
+ * @param visitor
+ * The visitor.
+ */
+ public abstract void accept(RevisionVisitor visitor);
+}
Added: wysiwyg/src/main/java/com/xpn/xwiki/wysiwyg/client/diff/Diff.java
===================================================================
--- wysiwyg/src/main/java/com/xpn/xwiki/wysiwyg/client/diff/Diff.java (rev 0)
+++ wysiwyg/src/main/java/com/xpn/xwiki/wysiwyg/client/diff/Diff.java 2008-03-03 08:28:56 UTC (rev 96)
@@ -0,0 +1,380 @@
+/*
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 1999-2003 The Apache Software Foundation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ * any, must include the following acknowledgement:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgement may appear in the software itself,
+ * if and wherever such third-party acknowledgements normally appear.
+ *
+ * 4. The names "The Jakarta Project", "Commons", and "Apache Software
+ * Foundation" must not be used to endorse or promote products derived
+ * from this software without prior written permission. For written
+ * permission, please contact apache at apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache"
+ * nor may "Apache" appear in their names without prior written
+ * permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package com.xpn.xwiki.wysiwyg.client.diff;
+
+import java.util.*;
+
+import com.xpn.xwiki.wysiwyg.client.diff.myers.MyersDiff;
+
+/**
+ * Implements a differencing engine that works on arrays of
+ * {@link Object Object}.
+ *
+ * <p>
+ * Within this library, the word <i>text</i> means a unit of information
+ * subject to version control.
+ *
+ * <p>
+ * Text is represented as <code>Object[]</code> because the diff engine is
+ * capable of handling more than plain ascci. In fact, arrays of any type that
+ * implements {@link java.lang.Object#hashCode hashCode()} and
+ * {@link java.lang.Object#equals equals()} correctly can be subject to
+ * differencing using this library.
+ * </p>
+ *
+ * <p>
+ * This library provides a framework in which different differencing algorithms
+ * may be used. If no algorithm is specififed, a default algorithm is used.
+ * </p>
+ *
+ * @version $Revision: 1.1 $ $Date: 2006/03/12 00:24:21 $
+ * @author <a href="mailto:juanco at suigeneris.org">Juanco Anez</a>
+ * @see Delta
+ * @see DiffAlgorithm
+ *
+ * modifications:
+ *
+ * 27 Apr 2003 bwm
+ *
+ * Added some comments whilst trying to figure out the algorithm
+ *
+ * 03 May 2003 bwm
+ *
+ * Factored out the algorithm implementation into a separate difference
+ * algorithm class to allow pluggable algorithms.
+ */
+
+public class Diff extends ToString
+{
+ /** The standard line separator. */
+ public static final String NL = " "; // System.getProperty("line.separator");
+
+ /** The line separator to use in RCS format output. */
+ public static final String RCS_EOL = " ";
+
+ /** The original sequence. */
+ protected final Object[] orig;
+
+ /** The differencing algorithm to use. */
+ protected DiffAlgorithm algorithm;
+
+ /**
+ * Create a differencing object using the default algorithm
+ *
+ * @param original
+ * original text that will be compared
+ */
+ public Diff(Object[] original)
+ {
+ this(original, null);
+ }
+
+ /**
+ * Create a differencing object using the given algorithm
+ *
+ * @param original
+ * the original text which will be compared against
+ * @param algorithm
+ * the difference algorithm to use.
+ */
+ public Diff(Object[] original, DiffAlgorithm algorithm)
+ {
+ if (original == null)
+ {
+ throw new IllegalArgumentException();
+ }
+
+ this.orig = original;
+ if (algorithm != null)
+ this.algorithm = algorithm;
+ else
+ this.algorithm = defaultAlgorithm();
+ }
+
+ protected DiffAlgorithm defaultAlgorithm()
+ {
+ return new MyersDiff();
+ }
+
+ /**
+ * compute the difference between an original and a revision.
+ *
+ * @param orig
+ * the original
+ * @param rev
+ * the revision to compare with the original.
+ * @return a Revision describing the differences
+ */
+ public static Revision diff(Object[] orig, Object[] rev)
+ throws DifferentiationFailedException
+ {
+ if (orig == null || rev == null)
+ {
+ throw new IllegalArgumentException();
+ }
+
+ return diff(orig, rev, null);
+ }
+
+ /**
+ * compute the difference between an original and a revision.
+ *
+ * @param orig
+ * the original
+ * @param rev
+ * the revision to compare with the original.
+ * @param algorithm
+ * the difference algorithm to use
+ * @return a Revision describing the differences
+ */
+ public static Revision diff(Object[] orig, Object[] rev,
+ DiffAlgorithm algorithm) throws DifferentiationFailedException
+ {
+ if (orig == null || rev == null)
+ {
+ throw new IllegalArgumentException();
+ }
+
+ return new Diff(orig, algorithm).diff(rev);
+ }
+
+ /**
+ * compute the difference between the original and a revision.
+ *
+ * @param rev
+ * the revision to compare with the original.
+ * @return a Revision describing the differences
+ */
+ public Revision diff(Object[] rev) throws DifferentiationFailedException
+ {
+ if (orig.length == 0 && rev.length == 0)
+ return new Revision();
+ else
+ return algorithm.diff(orig, rev);
+ }
+
+ /**
+ * Compares the two input sequences.
+ *
+ * @param orig
+ * The original sequence.
+ * @param rev
+ * The revised sequence.
+ * @return true if the sequences are identical. False otherwise.
+ */
+ public static boolean compare(Object[] orig, Object[] rev)
+ {
+ if (orig.length != rev.length)
+ {
+ return false;
+ }
+ else
+ {
+ for (int i = 0; i < orig.length; i++)
+ {
+ if (!orig[i].equals(rev[i]))
+ {
+ return false;
+ }
+ }
+ return true;
+ }
+ }
+
+ /**
+ * Converts an array of {@link Object Object} to a string using
+ * {@link Diff#NL Diff.NL} as the line separator.
+ *
+ * @param o
+ * the array of objects.
+ */
+ public static String arrayToString(Object[] o)
+ {
+ return arrayToString(o, Diff.NL);
+ }
+
+ /**
+ * Edits all of the items in the input sequence.
+ *
+ * @param text
+ * The input sequence.
+ * @return A sequence of the same length with all the lines differing from
+ * the corresponding ones in the input.
+ */
+ public static Object[] editAll(Object[] text)
+ {
+ Object[] result = new String[text.length];
+
+ for (int i = 0; i < text.length; i++)
+ result[i] = text[i] + " <edited>";
+
+ return result;
+ }
+
+ /**
+ * Performs random edits on the input sequence. Useful for testing.
+ *
+ * @param text
+ * The input sequence.
+ * @return The sequence with random edits performed.
+ */
+ public static Object[] randomEdit(Object[] text)
+ {
+ return randomEdit(text, text.length);
+ }
+
+ /**
+ * Performs random edits on the input sequence. Useful for testing.
+ *
+ * @param text
+ * The input sequence.
+ * @param seed
+ * A seed value for the randomizer.
+ * @return The sequence with random edits performed.
+ */
+ public static Object[] randomEdit(Object[] text, long seed)
+ {
+ /* List result = new ArrayList(Arrays.asList(text));
+ Random r = new Random(seed);
+ int nops = r.nextInt(10);
+ for (int i = 0; i < nops; i++)
+ {
+ boolean del = r.nextBoolean();
+ int pos = r.nextInt(result.size() + 1);
+ int len = Math.min(result.size() - pos, 1 + r.nextInt(4));
+ if (del && result.size() > 0)
+ { // delete
+ result.subList(pos, pos + len).clear();
+ }
+ else
+ {
+ for (int k = 0; k < len; k++, pos++)
+ {
+ result.add(pos, "[" + i + "] random edit[" + i + "][" + i
+ + "]");
+ }
+ }
+ }
+ return result.toArray();
+ */
+ return text;
+ }
+
+ /**
+ * Shuffles around the items in the input sequence.
+ *
+ * @param text
+ * The input sequence.
+ * @return The shuffled sequence.
+ */
+ public static Object[] shuffle(Object[] text)
+ {
+ return shuffle(text, text.length);
+ }
+
+ /**
+ * Shuffles around the items in the input sequence.
+ *
+ * @param text
+ * The input sequence.
+ * @param seed
+ * A seed value for randomizing the suffle.
+ * @return The shuffled sequence.
+ */
+ public static Object[] shuffle(Object[] text, long seed)
+ {
+ List result = new ArrayList(Arrays.asList(text));
+ // Collections.shuffle(result);
+ return result.toArray();
+ }
+
+ /**
+ * Generate a random sequence of the given size.
+ *
+ * @param The
+ * size of the sequence to generate.
+ * @return The generated sequence.
+ */
+ /*
+ public static Object[] randomSequence(int size)
+ {
+ return randomSequence(size, size);
+ } */
+
+ /**
+ * Generate a random sequence of the given size.
+ *
+ * @param The
+ * size of the sequence to generate.
+ * @param seed
+ * A seed value for randomizing the generation.
+ * @return The generated sequence.
+ */
+ /*
+ public static Object[] randomSequence(int size, long seed)
+ {
+ Integer[] result = new Integer[size];
+ Random r = new Random(seed);
+ for (int i = 0; i < result.length; i++)
+ {
+ result[i] = new Integer(r.nextInt(size));
+ }
+ return result;
+ } */
+
+}
\ No newline at end of file
Added: wysiwyg/src/main/java/com/xpn/xwiki/wysiwyg/client/diff/DiffAlgorithm.java
===================================================================
--- wysiwyg/src/main/java/com/xpn/xwiki/wysiwyg/client/diff/DiffAlgorithm.java (rev 0)
+++ wysiwyg/src/main/java/com/xpn/xwiki/wysiwyg/client/diff/DiffAlgorithm.java 2008-03-03 08:28:56 UTC (rev 96)
@@ -0,0 +1,85 @@
+/*
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 1999-2003 The Apache Software Foundation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ * any, must include the following acknowledgement:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgement may appear in the software itself,
+ * if and wherever such third-party acknowledgements normally appear.
+ *
+ * 4. The names "The Jakarta Project", "Commons", and "Apache Software
+ * Foundation" must not be used to endorse or promote products derived
+ * from this software without prior written permission. For written
+ * permission, please contact apache at apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache"
+ * nor may "Apache" appear in their names without prior written
+ * permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package com.xpn.xwiki.wysiwyg.client.diff;
+
+/**
+ * A simple interface for implementations of differencing algorithms.
+ *
+ * @version $Revision: 1.1 $ $Date: 2006/03/12 00:24:21 $
+ *
+ * @author <a href="mailto:bwm at hplb.hpl.hp.com">Brian McBride</a>
+ */
+public interface DiffAlgorithm
+{
+ /**
+ * Computes the difference between the original sequence and the revised
+ * sequence and returns it as a
+ * {@link com.xpn.xwiki.wysiwyg.client.diff.Revision Revision} object.
+ * <p>
+ * The revision can be used to construct the revised sequence from the
+ * original sequence.
+ *
+ * @param rev
+ * the revised text
+ * @return the revision script.
+ * @throws DifferentiationFailedException
+ * if the diff could not be computed.
+ */
+ public abstract Revision diff(Object[] orig, Object[] rev)
+ throws DifferentiationFailedException;
+}
\ No newline at end of file
Added: wysiwyg/src/main/java/com/xpn/xwiki/wysiwyg/client/diff/DiffException.java
===================================================================
--- wysiwyg/src/main/java/com/xpn/xwiki/wysiwyg/client/diff/DiffException.java (rev 0)
+++ wysiwyg/src/main/java/com/xpn/xwiki/wysiwyg/client/diff/DiffException.java 2008-03-03 08:28:56 UTC (rev 96)
@@ -0,0 +1,78 @@
+/*
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 1999-2003 The Apache Software Foundation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ * any, must include the following acknowledgement:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgement may appear in the software itself,
+ * if and wherever such third-party acknowledgements normally appear.
+ *
+ * 4. The names "The Jakarta Project", "Commons", and "Apache Software
+ * Foundation" must not be used to endorse or promote products derived
+ * from this software without prior written permission. For written
+ * permission, please contact apache at apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache"
+ * nor may "Apache" appear in their names without prior written
+ * permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package com.xpn.xwiki.wysiwyg.client.diff;
+
+/**
+ * Base class for all exceptions emanating from this package.
+ *
+ * @version $Revision: 1.1 $ $Date: 2006/03/12 00:24:21 $
+ *
+ * @author <a href="mailto:juanco at suigeneris.org">Juanco Anez</a>
+ */
+public class DiffException extends Exception
+{
+
+ public DiffException()
+ {
+ }
+
+ public DiffException(String msg)
+ {
+ super(msg);
+ }
+}
Added: wysiwyg/src/main/java/com/xpn/xwiki/wysiwyg/client/diff/DifferentiationFailedException.java
===================================================================
--- wysiwyg/src/main/java/com/xpn/xwiki/wysiwyg/client/diff/DifferentiationFailedException.java (rev 0)
+++ wysiwyg/src/main/java/com/xpn/xwiki/wysiwyg/client/diff/DifferentiationFailedException.java 2008-03-03 08:28:56 UTC (rev 96)
@@ -0,0 +1,81 @@
+/*
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 1999-2003 The Apache Software Foundation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ * any, must include the following acknowledgement:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgement may appear in the software itself,
+ * if and wherever such third-party acknowledgements normally appear.
+ *
+ * 4. The names "The Jakarta Project", "Commons", and "Apache Software
+ * Foundation" must not be used to endorse or promote products derived
+ * from this software without prior written permission. For written
+ * permission, please contact apache at apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache"
+ * nor may "Apache" appear in their names without prior written
+ * permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package com.xpn.xwiki.wysiwyg.client.diff;
+
+/**
+ * Thrown whenever the differencing engine cannot produce the differences
+ * between two revisions of ta text.
+ *
+ * @version $Revision: 1.1 $ $Date: 2006/03/12 00:24:21 $
+ *
+ * @author <a href="mailto:juanco at suigeneris.org">Juanco Anez</a>
+ * @see Diff
+ * @see DiffAlgorithm
+ */
+public class DifferentiationFailedException extends DiffException
+{
+
+ public DifferentiationFailedException()
+ {
+ }
+
+ public DifferentiationFailedException(String msg)
+ {
+ super(msg);
+ }
+}
Added: wysiwyg/src/main/java/com/xpn/xwiki/wysiwyg/client/diff/PatchFailedException.java
===================================================================
--- wysiwyg/src/main/java/com/xpn/xwiki/wysiwyg/client/diff/PatchFailedException.java (rev 0)
+++ wysiwyg/src/main/java/com/xpn/xwiki/wysiwyg/client/diff/PatchFailedException.java 2008-03-03 08:28:56 UTC (rev 96)
@@ -0,0 +1,79 @@
+/*
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 1999-2003 The Apache Software Foundation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ * any, must include the following acknowledgement:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgement may appear in the software itself,
+ * if and wherever such third-party acknowledgements normally appear.
+ *
+ * 4. The names "The Jakarta Project", "Commons", and "Apache Software
+ * Foundation" must not be used to endorse or promote products derived
+ * from this software without prior written permission. For written
+ * permission, please contact apache at apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache"
+ * nor may "Apache" appear in their names without prior written
+ * permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package com.xpn.xwiki.wysiwyg.client.diff;
+
+/**
+ * Thrown whenever a delta cannot be applied as a patch to a given text.
+ *
+ * @version $Revision: 1.1 $ $Date: 2006/03/12 00:24:21 $
+ * @author <a href="mailto:juanco at suigeneris.org">Juanco Anez</a>
+ * @see Delta
+ * @see Diff
+ */
+public class PatchFailedException extends DiffException
+{
+
+ public PatchFailedException()
+ {
+ }
+
+ public PatchFailedException(String msg)
+ {
+ super(msg);
+ }
+}
Added: wysiwyg/src/main/java/com/xpn/xwiki/wysiwyg/client/diff/Revision.java
===================================================================
--- wysiwyg/src/main/java/com/xpn/xwiki/wysiwyg/client/diff/Revision.java (rev 0)
+++ wysiwyg/src/main/java/com/xpn/xwiki/wysiwyg/client/diff/Revision.java 2008-03-03 08:28:56 UTC (rev 96)
@@ -0,0 +1,269 @@
+/*
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 1999-2003 The Apache Software Foundation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ * any, must include the following acknowledgement:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgement may appear in the software itself,
+ * if and wherever such third-party acknowledgements normally appear.
+ *
+ * 4. The names "The Jakarta Project", "Commons", and "Apache Software
+ * Foundation" must not be used to endorse or promote products derived
+ * from this software without prior written permission. For written
+ * permission, please contact apache at apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache"
+ * nor may "Apache" appear in their names without prior written
+ * permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package com.xpn.xwiki.wysiwyg.client.diff;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+import java.util.ListIterator;
+
+/**
+ * A Revision holds the series of deltas that describe the differences between
+ * two sequences.
+ *
+ * @version $Revision: 1.1 $ $Date: 2006/03/12 00:24:21 $
+ *
+ * @author <a href="mailto:juanco at suigeneris.org">Juanco Anez</a>
+ * @author <a href="mailto:bwm at hplb.hpl.hp.com">Brian McBride</a>
+ *
+ * @see Delta
+ * @see Diff
+ * @see Chunk
+ * @see Revision
+ *
+ * modifications 27 Apr 2003 bwm
+ *
+ * Added visitor pattern Visitor interface and accept() method.
+ */
+
+public class Revision extends ToString
+{
+
+ List deltas_ = new ArrayList();
+
+ /**
+ * Creates an empty Revision.
+ */
+ public Revision()
+ {
+ }
+
+ /**
+ * Adds a delta to this revision.
+ *
+ * @param delta
+ * the {@link Delta Delta} to add.
+ */
+ public synchronized void addDelta(Delta delta)
+ {
+ if (delta == null)
+ {
+ throw new IllegalArgumentException("new delta is null");
+ }
+ deltas_.add(delta);
+ }
+
+ /**
+ * Adds a delta to the start of this revision.
+ *
+ * @param delta
+ * the {@link Delta Delta} to add.
+ */
+ public synchronized void insertDelta(Delta delta)
+ {
+ if (delta == null)
+ {
+ throw new IllegalArgumentException("new delta is null");
+ }
+ deltas_.add(0, delta);
+ }
+
+ /**
+ * Retrieves a delta from this revision by position.
+ *
+ * @param i
+ * the position of the delta to retrieve.
+ * @return the specified delta
+ */
+ public Delta getDelta(int i)
+ {
+ return (Delta) deltas_.get(i);
+ }
+
+ /**
+ * Returns the number of deltas in this revision.
+ *
+ * @return the number of deltas.
+ */
+ public int size()
+ {
+ return deltas_.size();
+ }
+
+ /**
+ * Applies the series of deltas in this revision as patches to the given
+ * text.
+ *
+ * @param src
+ * the text to patch, which the method doesn't change.
+ * @return the resulting text after the patches have been applied.
+ * @throws PatchFailedException
+ * if any of the patches cannot be applied.
+ */
+ public Object[] patch(Object[] src) throws PatchFailedException
+ {
+ List target = new ArrayList(Arrays.asList(src));
+ applyTo(target);
+ return target.toArray();
+ }
+
+ /**
+ * Applies the series of deltas in this revision as patches to the given
+ * text.
+ *
+ * @param target
+ * the text to patch.
+ * @throws PatchFailedException
+ * if any of the patches cannot be applied.
+ */
+ public synchronized void applyTo(List target) throws PatchFailedException
+ {
+ ListIterator i = deltas_.listIterator(deltas_.size());
+ while (i.hasPrevious())
+ {
+ Delta delta = (Delta) i.previous();
+ delta.patch(target);
+ }
+ }
+
+ /**
+ * Converts this revision into its Unix diff style string representation.
+ *
+ * @param s
+ * a {@link StringBuffer StringBuffer} to which the string
+ * representation will be appended.
+ */
+ public synchronized void toString(StringBuffer s)
+ {
+ Iterator i = deltas_.iterator();
+ while (i.hasNext())
+ {
+ ((Delta) i.next()).toString(s);
+ }
+ }
+
+ /**
+ * Converts this revision into its RCS style string representation.
+ *
+ * @param s
+ * a {@link StringBuffer StringBuffer} to which the string
+ * representation will be appended.
+ * @param EOL
+ * the string to use as line separator.
+ */
+ public synchronized void toRCSString(StringBuffer s, String EOL)
+ {
+ Iterator i = deltas_.iterator();
+ while (i.hasNext())
+ {
+ ((Delta) i.next()).toRCSString(s, EOL);
+ }
+ }
+
+ /**
+ * Converts this revision into its RCS style string representation.
+ *
+ * @param s
+ * a {@link StringBuffer StringBuffer} to which the string
+ * representation will be appended.
+ */
+ public void toRCSString(StringBuffer s)
+ {
+ toRCSString(s, Diff.NL);
+ }
+
+ /**
+ * Converts this delta into its RCS style string representation.
+ *
+ * @param EOL
+ * the string to use as line separator.
+ */
+ public String toRCSString(String EOL)
+ {
+ StringBuffer s = new StringBuffer();
+ toRCSString(s, EOL);
+ return s.toString();
+ }
+
+ /**
+ * Converts this delta into its RCS style string representation using the
+ * default line separator.
+ */
+ public String toRCSString()
+ {
+ return toRCSString(Diff.NL);
+ }
+
+ /**
+ * Accepts a visitor.
+ *
+ * @param visitor
+ * the visitor visiting this instance
+ */
+ public void accept(RevisionVisitor visitor)
+ {
+ visitor.visit(this);
+ Iterator iter = deltas_.iterator();
+ while (iter.hasNext())
+ {
+ ((Delta) iter.next()).accept(visitor);
+ }
+ }
+
+}
Added: wysiwyg/src/main/java/com/xpn/xwiki/wysiwyg/client/diff/RevisionVisitor.java
===================================================================
--- wysiwyg/src/main/java/com/xpn/xwiki/wysiwyg/client/diff/RevisionVisitor.java (rev 0)
+++ wysiwyg/src/main/java/com/xpn/xwiki/wysiwyg/client/diff/RevisionVisitor.java 2008-03-03 08:28:56 UTC (rev 96)
@@ -0,0 +1,73 @@
+/*
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 1999-2003 The Apache Software Foundation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ * any, must include the following acknowledgement:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgement may appear in the software itself,
+ * if and wherever such third-party acknowledgements normally appear.
+ *
+ * 4. The names "The Jakarta Project", "Commons", and "Apache Software
+ * Foundation" must not be used to endorse or promote products derived
+ * from this software without prior written permission. For written
+ * permission, please contact apache at apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache"
+ * nor may "Apache" appear in their names without prior written
+ * permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package com.xpn.xwiki.wysiwyg.client.diff;
+
+/**
+ * Definition of a Visitor interface for {@link Revision Revisions} See "Design
+ * Patterns" by the Gang of Four
+ */
+public interface RevisionVisitor
+{
+ public void visit(Revision revision);
+
+ public void visit(DeleteDelta delta);
+
+ public void visit(ChangeDelta delta);
+
+ public void visit(AddDelta delta);
+}
\ No newline at end of file
Added: wysiwyg/src/main/java/com/xpn/xwiki/wysiwyg/client/diff/SimpleDiff.java
===================================================================
--- wysiwyg/src/main/java/com/xpn/xwiki/wysiwyg/client/diff/SimpleDiff.java (rev 0)
+++ wysiwyg/src/main/java/com/xpn/xwiki/wysiwyg/client/diff/SimpleDiff.java 2008-03-03 08:28:56 UTC (rev 96)
@@ -0,0 +1,335 @@
+/*
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 1999-2003 The Apache Software Foundation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ * any, must include the following acknowledgement:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgement may appear in the software itself,
+ * if and wherever such third-party acknowledgements normally appear.
+ *
+ * 4. The names "The Jakarta Project", "Commons", and "Apache Software
+ * Foundation" must not be used to endorse or promote products derived
+ * from this software without prior written permission. For written
+ * permission, please contact apache at apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache"
+ * nor may "Apache" appear in their names without prior written
+ * permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package com.xpn.xwiki.wysiwyg.client.diff;
+
+import java.util.*;
+
+/**
+ * Implements a simple differencing algortithm.
+ * <p>
+ *
+ * @date $Date: 2006/03/12 00:24:21 $
+ * @version $Revision: 1.1 $
+ * @author <a href="mailto:juanco at suigeneris.org">Juanco Anez</a>
+ *
+ * <p>
+ * <b>Overview of Algorithm</b>
+ * </p>
+ *
+ * <p>
+ * <i>by <a href='http://www.topmeadow.net/bwm'> bwm</a>
+ * </p>
+ *
+ * <p>
+ * The algorithm is optimised for situations where the input sequences have few
+ * repeated objects. If it is given input with many repeated objects it will
+ * report sub-optimal changes. However, given appropriate input, it is fast, and
+ * linear in memory usage.
+ * </p>
+ *
+ * <p>
+ * The algorithm consists of the following steps:
+ * </p>
+ * <ul>
+ * <li>compute an equivalence set for the input data</li>
+ * <li>translate each element of the orginal and revised input sequences to a
+ * member of the equivalence set </li>
+ * <li>match the the input sequences to determine the deltas, i.e. the
+ * differences between the original and revised sequences.</li>
+ * </ul>
+ *
+ * <p>
+ * The first step is to compute a an equivalence set for the input data. The
+ * equivalence set is computed from objects that are in the original input
+ * sequence
+ * </p>
+ *
+ * <pre>
+ * eq(x) = the index of the first occurence of x in the original sequence.
+ * </pre>
+ *
+ * <p>
+ * With this equivalence function, the algorithm can compare integers rather
+ * than strings, which is considerably more efficient.
+ * </p>
+ *
+ * <p>
+ * The second step is to compute the datastructure on which the algorithm will
+ * operate. Having computed the equivalence function in the previous step, we
+ * can compute two arrays where indx[i] = eqs(orig[i]) and jndx[i] =
+ * eqs(rev[i]). The algorithm can now operate on indx and jndx instead of orig
+ * and rev. Thus, comparisons are then on O(int == int) instead of
+ * O(Object.equals(Object)).
+ * </p>
+ *
+ * <p>
+ * The algorithm now matches indx and jndx. Whilst indx[i] == jndx[i] it skips
+ * matching objects in the sequence. In seeking to match objects in the input
+ * sequence it assumes that each object is likely to be unique. It uses the
+ * known characteristics of the unique equivalence function. It can tell from
+ * the eq value if this object appeared in the other sequence at all. If it did
+ * not, there is no point in searching for a match.
+ * </p>
+ *
+ * <p>
+ * Recall that the eq function value is the index earliest occurrence in the
+ * orig sequence. This information is used to search efficiently for the next
+ * match. The algorithm is perfect when all input objects are unique, but
+ * degrades when input objects are not unique. When input objects are not unique
+ * an optimal match may not be found, but a correct match will be.
+ * </p>
+ *
+ * <p>
+ * Having identified common matching objects in the orig and revised sequences,
+ * the differences between them are easily computed.
+ * </p>
+ *
+ * @see Delta
+ * @see Revision Modifications:
+ *
+ * 27/Apr/2003 bwm Added some comments whilst trying to figure out the algorithm
+ *
+ * 03 May 2003 bwm Created this implementation class by refactoring it out of
+ * the Diff class to enable plug in difference algorithms
+ *
+ */
+public class SimpleDiff implements DiffAlgorithm
+{
+
+ static final int NOT_FOUND_i = -2;
+ static final int NOT_FOUND_j = -1;
+ static final int EOS = Integer.MAX_VALUE;
+
+ public SimpleDiff()
+ {
+ }
+
+ protected int scan(int[] ndx, int i, int target)
+ {
+ while (ndx[i] < target)
+ {
+ i++;
+ }
+ return i;
+ }
+
+ /**
+ * Compute the difference between original and revised sequences.
+ *
+ * @param orig
+ * The original sequence.
+ * @param rev
+ * The revised sequence to be compared with the original.
+ * @return A Revision object describing the differences.
+ * @throws DifferenciationFailedException
+ * if the diff could not be computed.
+ */
+ public Revision diff(Object[] orig, Object[] rev)
+ throws DifferentiationFailedException
+ {
+ // create map eqs, such that for each item in both orig and rev
+ // eqs(item) = firstOccurrence(item, orig);
+ Map eqs = buildEqSet(orig, rev);
+
+ // create an array such that
+ // indx[i] = NOT_FOUND_i if orig[i] is not in rev
+ // indx[i] = firstOccurrence(orig[i], orig)
+ int[] indx = buildIndex(eqs, orig, NOT_FOUND_i);
+
+ // create an array such that
+ // jndx[j] = NOT_FOUND_j if orig[j] is not in rev
+ // jndx[j] = firstOccurrence(rev[j], orig)
+ int[] jndx = buildIndex(eqs, rev, NOT_FOUND_j);
+
+ // what in effect has been done is to build a unique hash
+ // for each item that is in both orig and rev
+ // and to label each item in orig and new with that hash value
+ // or a marker that the item is not common to both.
+
+ eqs = null; // let gc know we're done with this
+
+ Revision deltas = new Revision(); // !!! new Revision()
+ int i = 0;
+ int j = 0;
+
+ // skip matching
+ // skip leading items that are equal
+ // could be written
+ // for (i=0; indx[i] != EOS && indx[i] == jndx[i]; i++);
+ // j = i;
+ for (; indx[i] != EOS && indx[i] == jndx[j]; i++, j++)
+ {
+ /* void */
+ }
+
+ while (indx[i] != jndx[j])
+ { // only equal if both == EOS
+ // they are different
+ int ia = i;
+ int ja = j;
+
+ // size of this delta
+ do
+ {
+ // look down rev for a match
+ // stop at a match
+ // or if the FO(rev[j]) > FO(orig[i])
+ // or at the end
+ while (jndx[j] < 0 || jndx[j] < indx[i])
+ {
+ j++;
+ }
+ // look down orig for a match
+ // stop at a match
+ // or if the FO(orig[i]) > FO(rev[j])
+ // or at the end
+ while (indx[i] < 0 || indx[i] < jndx[j])
+ {
+ i++;
+ }
+
+ // this doesn't do a compare each line with each other line
+ // so it won't find all matching lines
+ }
+ while (indx[i] != jndx[j]);
+
+ // on exit we have a match
+
+ // they are equal, reverse any exedent matches
+ // it is possible to overshoot, so count back matching items
+ while (i > ia && j > ja && indx[i - 1] == jndx[j - 1])
+ {
+ --i;
+ --j;
+ }
+
+ deltas.addDelta(Delta.newDelta(new Chunk(orig, ia, i - ia),
+ new Chunk(rev, ja, j - ja)));
+ // skip matching
+ for (; indx[i] != EOS && indx[i] == jndx[j]; i++, j++)
+ {
+ /* void */
+ }
+ }
+ return deltas;
+ }
+
+ /**
+ * create a <code>Map</code> from each common item in orig and rev to the
+ * index of its first occurrence in orig
+ *
+ * @param orig
+ * the original sequence of items
+ * @param rev
+ * the revised sequence of items
+ */
+ protected Map buildEqSet(Object[] orig, Object[] rev)
+ {
+ // construct a set of the objects that orig and rev have in common
+
+ // first construct a set containing all the elements in orig
+ Set items = new HashSet(Arrays.asList(orig));
+
+ // then remove all those not in rev
+ items.retainAll(Arrays.asList(rev));
+
+ Map eqs = new HashMap();
+ for (int i = 0; i < orig.length; i++)
+ {
+ // if its a common item and hasn't been found before
+ if (items.contains(orig[i]))
+ {
+ // add it to the map
+ eqs.put(orig[i], new Integer(i));
+ // and make sure its not considered again
+ items.remove(orig[i]);
+ }
+ }
+ return eqs;
+ }
+
+ /**
+ * build a an array such each a[i] = eqs([i]) or NF if eqs([i]) undefined
+ *
+ * @param eqs
+ * a mapping from Object to Integer
+ * @param seq
+ * a sequence of objects
+ * @param NF
+ * the not found marker
+ */
+ protected int[] buildIndex(Map eqs, Object[] seq, int NF)
+ {
+ int[] result = new int[seq.length + 1];
+ for (int i = 0; i < seq.length; i++)
+ {
+ Integer value = (Integer) eqs.get(seq[i]);
+ if (value == null || value.intValue() < 0)
+ {
+ result[i] = NF;
+ }
+ else
+ {
+ result[i] = value.intValue();
+ }
+ }
+ result[seq.length] = EOS;
+ return result;
+ }
+
+}
Added: wysiwyg/src/main/java/com/xpn/xwiki/wysiwyg/client/diff/ToString.java
===================================================================
--- wysiwyg/src/main/java/com/xpn/xwiki/wysiwyg/client/diff/ToString.java (rev 0)
+++ wysiwyg/src/main/java/com/xpn/xwiki/wysiwyg/client/diff/ToString.java 2008-03-03 08:28:56 UTC (rev 96)
@@ -0,0 +1,184 @@
+/*
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 1999-2003 The Apache Software Foundation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ * any, must include the following acknowledgement:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgement may appear in the software itself,
+ * if and wherever such third-party acknowledgements normally appear.
+ *
+ * 4. The names "The Jakarta Project", "Commons", and "Apache Software
+ * Foundation" must not be used to endorse or promote products derived
+ * from this software without prior written permission. For written
+ * permission, please contact apache at apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache"
+ * nor may "Apache" appear in their names without prior written
+ * permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package com.xpn.xwiki.wysiwyg.client.diff;
+
+import java.util.ArrayList;
+
+/**
+ * This class delegates handling of the to a StringBuffer based version.
+ *
+ * @version $Revision: 1.1 $ $Date: 2006/03/12 00:24:21 $
+ * @author <a href="mailto:juanco at suigeneris.org">Juanco Anez</a>
+ */
+public class ToString
+{
+ public ToString()
+ {
+ }
+
+ /**
+ * Default implementation of the
+ * {@link java.lang.Object#toString toString() } method that delegates work
+ * to a {@link java.lang.StringBuffer StringBuffer} base version.
+ */
+ public String toString()
+ {
+ StringBuffer s = new StringBuffer();
+ toString(s);
+ return s.toString();
+ }
+
+ /**
+ * Place a string image of the object in a StringBuffer.
+ *
+ * @param s
+ * the string buffer.
+ */
+ public void toString(StringBuffer s)
+ {
+ s.append(super.toString());
+ }
+
+ /**
+ * Breaks a string into an array of strings. Use the value of the
+ * <code>line.separator</code> system property as the linebreak character.
+ *
+ * @param value
+ * the string to convert.
+ */
+ public static String[] stringToArray(String value)
+ {
+ ArrayList list = new ArrayList();
+ String[] lines = value.split("\n");
+ for (int i=0;i<lines.length;i++) {
+ splitLine(list, lines[i]);
+ }
+ String[] result = new String[list.size()];
+ for (int i=0;i<list.size();i++) {
+ result[i] = (String) list.get(i);
+ }
+ return result;
+
+ }
+
+ public static void splitLine(ArrayList list, String line) {
+ boolean isTag = false;
+ StringBuffer currentToken = new StringBuffer();
+ for (int i=0;i<line.length();i++) {
+ char c = line.charAt(i);
+ if (!isTag) {
+ if (c=='<') {
+ list.add(currentToken.toString());
+ currentToken = new StringBuffer();
+ currentToken.append(c);
+ isTag = true;
+ } else if (c==' ') {
+ list.add(currentToken.toString());
+ list.add(" ");
+ currentToken = new StringBuffer();
+ } else {
+ currentToken.append(c);
+ }
+ } else if (isTag && (c == '>')) {
+ currentToken.append(c);
+ list.add(currentToken.toString());
+ currentToken = new StringBuffer();
+ isTag = false;
+ } else {
+ currentToken.append(c);
+ }
+ }
+ if (currentToken.length()>0) {
+ list.add(currentToken.toString());
+ }
+ list.add("\n");
+ }
+
+ /**
+ * Converts an array of {@link Object Object} to a string Use the value of
+ * the <code>line.separator</code> system property the line separator.
+ *
+ * @param o
+ * the array of objects.
+ */
+ public static String arrayToString(Object[] o)
+ {
+ return arrayToString(o, "");
+ }
+
+ /**
+ * Converts an array of {@link Object Object} to a string using the given
+ * line separator.
+ *
+ * @param o
+ * the array of objects.
+ * @param EOL
+ * the string to use as line separator.
+ */
+ public static String arrayToString(Object[] o, String EOL)
+ {
+ StringBuffer buf = new StringBuffer();
+ for (int i = 0; i < o.length - 1; i++)
+ {
+ buf.append(o[i]);
+ buf.append(EOL);
+ }
+ buf.append(o[o.length - 1]);
+ return buf.toString();
+ }
+}
Added: wysiwyg/src/main/java/com/xpn/xwiki/wysiwyg/client/diff/myers/DiffNode.java
===================================================================
--- wysiwyg/src/main/java/com/xpn/xwiki/wysiwyg/client/diff/myers/DiffNode.java (rev 0)
+++ wysiwyg/src/main/java/com/xpn/xwiki/wysiwyg/client/diff/myers/DiffNode.java 2008-03-03 08:28:56 UTC (rev 96)
@@ -0,0 +1,59 @@
+package com.xpn.xwiki.wysiwyg.client.diff.myers;
+
+/**
+ * <p>Title: </p>
+ * <p>Description: </p>
+ * <p>Copyright: Copyright (c) 2002</p>
+ * <p>Company: </p>
+ * @author not attributable
+ * @version 1.0
+ */
+
+/**
+ * A diffnode in a diffpath.
+ * <p>
+ * A DiffNode and its previous node mark a delta between two input sequences,
+ * that is, two differing subsequences between (possibly zero length) matching
+ * sequences.
+ *
+ * {@link DiffNode DiffNodes} and {@link Snake Snakes} allow for compression of
+ * diffpaths, as each snake is represented by a single {@link Snake Snake} node
+ * and each contiguous series of insertions and deletions is represented by a
+ * single {@link DiffNode DiffNodes}.
+ *
+ * @version $Revision: 1.1 $ $Date: 2006/03/12 00:24:21 $
+ * @author <a href="mailto:juanco at suigeneris.org">Juanco Anez</a>
+ *
+ */
+public final class DiffNode extends PathNode
+{
+ /**
+ * Constructs a DiffNode.
+ * <p>
+ * DiffNodes are compressed. That means that the path pointed to by the
+ * <code>prev</code> parameter will be followed using
+ * {@link PathNode#previousSnake} until a non-diff node is found.
+ *
+ * @param the
+ * position in the original sequence
+ * @param the
+ * position in the revised sequence
+ * @param prev
+ * the previous node in the path.
+ */
+ public DiffNode(int i, int j, PathNode prev)
+ {
+ super(i, j, (prev == null ? null : prev.previousSnake()));
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @return false, always
+ */
+ public boolean isSnake()
+ {
+ return false;
+ }
+
+}
\ No newline at end of file
Added: wysiwyg/src/main/java/com/xpn/xwiki/wysiwyg/client/diff/myers/MyersDiff.java
===================================================================
--- wysiwyg/src/main/java/com/xpn/xwiki/wysiwyg/client/diff/myers/MyersDiff.java (rev 0)
+++ wysiwyg/src/main/java/com/xpn/xwiki/wysiwyg/client/diff/myers/MyersDiff.java 2008-03-03 08:28:56 UTC (rev 96)
@@ -0,0 +1,227 @@
+/*
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 1999-2003 The Apache Software Foundation. All rights
+ * reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ * any, must include the following acknowledgement:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgement may appear in the software itself,
+ * if and wherever such third-party acknowledgements normally appear.
+ *
+ * 4. The names "The Jakarta Project", "Commons", and "Apache Software
+ * Foundation" must not be used to endorse or promote products derived
+ * from this software without prior written permission. For written
+ * permission, please contact apache at apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache"
+ * nor may "Apache" appear in their names without prior written
+ * permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package com.xpn.xwiki.wysiwyg.client.diff.myers;
+
+import com.xpn.xwiki.wysiwyg.client.diff.*;
+
+/**
+ * A clean-room implementation of <a
+ * href="http://www.cs.arizona.edu/people/gene/"> Eugene Myers</a> differencing
+ * algorithm.
+ * <p>
+ * See the paper at <a
+ * href="http://www.cs.arizona.edu/people/gene/PAPERS/diff.ps">
+ * http://www.cs.arizona.edu/people/gene/PAPERS/diff.ps</a>
+ *
+ * @version $Revision: 1.1 $ $Date: 2006/03/12 00:24:21 $
+ * @author <a href="mailto:juanco at suigeneris.org">Juanco Anez</a>
+ * @see Delta
+ * @see Revision
+ * @see Diff
+ */
+public class MyersDiff implements DiffAlgorithm
+{
+ /**
+ * Constructs an instance of the Myers differencing algorithm.
+ */
+ public MyersDiff()
+ {
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Revision diff(Object[] orig, Object[] rev)
+ throws DifferentiationFailedException
+ {
+ PathNode path = buildPath(orig, rev);
+ return buildRevision(path, orig, rev);
+ }
+
+ /**
+ * Computes the minimum diffpath that expresses de differences between the
+ * original and revised sequences, according to Gene Myers differencing
+ * algorithm.
+ *
+ * @param orig
+ * The original sequence.
+ * @param rev
+ * The revised sequence.
+ * @return A minimum {@link PathNode Path} accross the differences graph.
+ * @throws DifferentiationFailedException
+ * if a diff path could not be found.
+ */
+ public static PathNode buildPath(Object[] orig, Object[] rev)
+ throws DifferentiationFailedException
+ {
+ if (orig == null)
+ throw new IllegalArgumentException("original sequence is null");
+ if (rev == null)
+ throw new IllegalArgumentException("revised sequence is null");
+
+ // these are local constants
+ final int N = orig.length;
+ final int M = rev.length;
+
+ final int MAX = N + M + 1;
+ final int size = 1 + 2 * MAX;
+ final int middle = (size + 1) / 2;
+ final PathNode diagonal[] = new PathNode[size];
+
+ diagonal[middle + 1] = new Snake(0, -1, null);
+ for (int d = 0; d < MAX; d++)
+ {
+ for (int k = -d; k <= d; k += 2)
+ {
+ final int kmiddle = middle + k;
+ final int kplus = kmiddle + 1;
+ final int kminus = kmiddle - 1;
+ PathNode prev = null;
+
+ int i;
+ if ((k == -d)
+ || (k != d && diagonal[kminus].i < diagonal[kplus].i))
+ {
+ i = diagonal[kplus].i;
+ prev = diagonal[kplus];
+ }
+ else
+ {
+ i = diagonal[kminus].i + 1;
+ prev = diagonal[kminus];
+ }
+
+ diagonal[kminus] = null; // no longer used
+
+ int j = i - k;
+
+ PathNode node = new DiffNode(i, j, prev);
+
+ // orig and rev are zero-based
+ // but the algorithm is one-based
+ // that's why there's no +1 when indexing the sequences
+ while (i < N && j < M && orig[i].equals(rev[j]))
+ {
+ i++;
+ j++;
+ }
+ if (i > node.i)
+ node = new Snake(i, j, node);
+
+ diagonal[kmiddle] = node;
+
+ if (i >= N && j >= M)
+ {
+ return diagonal[kmiddle];
+ }
+ }
+ diagonal[middle + d - 1] = null;
+
+ }
+ // According to Myers, this cannot happen
+ throw new DifferentiationFailedException("could not find a diff path");
+ }
+
+ /**
+ * Constructs a {@link Revision} from a difference path.
+ *
+ * @param path
+ * The path.
+ * @param orig
+ * The original sequence.
+ * @param rev
+ * The revised sequence.
+ * @return A {@link Revision} script corresponding to the path.
+ * @throws DifferentiationFailedException
+ * if a {@link Revision} could not be built from the given path.
+ */
+ public static Revision buildRevision(PathNode path, Object[] orig,
+ Object[] rev)
+ {
+ if (path == null)
+ throw new IllegalArgumentException("path is null");
+ if (orig == null)
+ throw new IllegalArgumentException("original sequence is null");
+ if (rev == null)
+ throw new IllegalArgumentException("revised sequence is null");
+
+ Revision revision = new Revision();
+ if (path.isSnake())
+ path = path.prev;
+ while (path != null && path.prev != null && path.prev.j >= 0)
+ {
+ if (path.isSnake())
+ throw new IllegalStateException(
+ "bad diffpath: found snake when looking for diff");
+ int i = path.i;
+ int j = path.j;
+
+ path = path.prev;
+ int ianchor = path.i;
+ int janchor = path.j;
+
+ Delta delta = Delta.newDelta(new Chunk(orig, ianchor, i - ianchor),
+ new Chunk(rev, janchor, j - janchor));
+ revision.insertDelta(delta);
+ if (path.isSnake())
+ path = path.prev;
+ }
+ return revision;
+ }
+
+}
Added: wysiwyg/src/main/java/com/xpn/xwiki/wysiwyg/client/diff/myers/PathNode.java
===================================================================
--- wysiwyg/src/main/java/com/xpn/xwiki/wysiwyg/client/diff/myers/PathNode.java (rev 0)
+++ wysiwyg/src/main/java/com/xpn/xwiki/wysiwyg/client/diff/myers/PathNode.java 2008-03-03 08:28:56 UTC (rev 96)
@@ -0,0 +1,150 @@
+/*
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 1999-2003 The Apache Software Foundation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ * any, must include the following acknowledgement:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgement may appear in the software itself,
+ * if and wherever such third-party acknowledgements normally appear.
+ *
+ * 4. The names "The Jakarta Project", "Commons", and "Apache Software
+ * Foundation" must not be used to endorse or promote products derived
+ * from this software without prior written permission. For written
+ * permission, please contact apache at apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache"
+ * nor may "Apache" appear in their names without prior written
+ * permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package com.xpn.xwiki.wysiwyg.client.diff.myers;
+
+/**
+ * A node in a diffpath.
+ *
+ * @version $Revision: 1.1 $ $Date: 2006/03/12 00:24:21 $
+ * @author <a href="mailto:juanco at suigeneris.org">Juanco Anez</a>
+ *
+ * @see DiffNode
+ * @see Snake
+ *
+ */
+public abstract class PathNode
+{
+ /** Position in the original sequence. */
+ public final int i;
+ /** Position in the revised sequence. */
+ public final int j;
+ /** The previous node in the path. */
+ public final PathNode prev;
+
+ /**
+ * Concatenates a new path node with an existing diffpath.
+ *
+ * @param i
+ * The position in the original sequence for the new node.
+ * @param j
+ * The position in the revised sequence for the new node.
+ * @param prev
+ * The previous node in the path.
+ */
+ public PathNode(int i, int j, PathNode prev)
+ {
+ this.i = i;
+ this.j = j;
+ this.prev = prev;
+ }
+
+ /**
+ * Is this node a {@link Snake Snake node}?
+ *
+ * @return true if this is a {@link Snake Snake node}
+ */
+ public abstract boolean isSnake();
+
+ /**
+ * Is this a bootstrap node?
+ * <p>
+ * In bottstrap nodes one of the two corrdinates is less than zero.
+ *
+ * @return tru if this is a bootstrap node.
+ */
+ public boolean isBootstrap()
+ {
+ return i < 0 || j < 0;
+ }
+
+ /**
+ * Skips sequences of {@link DiffNode DiffNodes} until a {@link Snake} or
+ * bootstrap node is found, or the end of the path is reached.
+ *
+ * @return The next first {@link Snake} or bootstrap node in the path, or
+ * <code>null</code> if none found.
+ */
+ public final PathNode previousSnake()
+ {
+ if (isBootstrap())
+ return null;
+ if (!isSnake() && prev != null)
+ return prev.previousSnake();
+ return this;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String toString()
+ {
+ StringBuffer buf = new StringBuffer("[");
+ PathNode node = this;
+ while (node != null)
+ {
+ buf.append("(");
+ buf.append(Integer.toString(node.i));
+ buf.append(",");
+ buf.append(Integer.toString(node.j));
+ buf.append(")");
+ node = node.prev;
+ }
+ buf.append("]");
+ return buf.toString();
+ }
+}
\ No newline at end of file
Added: wysiwyg/src/main/java/com/xpn/xwiki/wysiwyg/client/diff/myers/Snake.java
===================================================================
--- wysiwyg/src/main/java/com/xpn/xwiki/wysiwyg/client/diff/myers/Snake.java (rev 0)
+++ wysiwyg/src/main/java/com/xpn/xwiki/wysiwyg/client/diff/myers/Snake.java 2008-03-03 08:28:56 UTC (rev 96)
@@ -0,0 +1,100 @@
+/*
+ * ====================================================================
+ *
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 1999-2003 The Apache Software Foundation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if
+ * any, must include the following acknowledgement:
+ * "This product includes software developed by the
+ * Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgement may appear in the software itself,
+ * if and wherever such third-party acknowledgements normally appear.
+ *
+ * 4. The names "The Jakarta Project", "Commons", and "Apache Software
+ * Foundation" must not be used to endorse or promote products derived
+ * from this software without prior written permission. For written
+ * permission, please contact apache at apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache"
+ * nor may "Apache" appear in their names without prior written
+ * permission of the Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package com.xpn.xwiki.wysiwyg.client.diff.myers;
+
+/**
+ * Represents a snake in a diffpath.
+ * <p>
+ *
+ * {@link DiffNode DiffNodes} and {@link Snake Snakes} allow for compression of
+ * diffpaths, as each snake is represented by a single {@link Snake Snake} node
+ * and each contiguous series of insertions and deletions is represented by a
+ * single {@link DiffNode DiffNodes}.
+ *
+ * @version $Revision: 1.1 $ $Date: 2006/03/12 00:24:21 $
+ * @author <a href="mailto:juanco at suigeneris.org">Juanco Anez</a>
+ *
+ */
+public final class Snake extends PathNode
+{
+ /**
+ * Constructs a snake node.
+ *
+ * @param the
+ * position in the original sequence
+ * @param the
+ * position in the revised sequence
+ * @param prev
+ * the previous node in the path.
+ */
+ public Snake(int i, int j, PathNode prev)
+ {
+ super(i, j, prev);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @return true always
+ */
+ public boolean isSnake()
+ {
+ return true;
+ }
+
+}
\ No newline at end of file
Modified: wysiwyg/src/main/java/com/xpn/xwiki/wysiwyg/client/ui/EditorWidget.java
===================================================================
--- wysiwyg/src/main/java/com/xpn/xwiki/wysiwyg/client/ui/EditorWidget.java 2008-02-29 17:38:00 UTC (rev 95)
+++ wysiwyg/src/main/java/com/xpn/xwiki/wysiwyg/client/ui/EditorWidget.java 2008-03-03 08:28:56 UTC (rev 96)
@@ -3,8 +3,10 @@
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.RichTextArea;
import com.google.gwt.user.client.ui.TextArea;
+import com.google.gwt.user.client.Window;
import com.xpn.xwiki.wysiwyg.client.Wysiwyg;
import com.xpn.xwiki.gwt.api.client.app.XWikiAsyncCallback;
+import com.xpn.xwiki.wysiwyg.client.diff.*;
/**
* Copyright 2006,XpertNet SARL,and individual contributors as indicated
@@ -31,6 +33,8 @@
public class EditorWidget extends WysiwygWidget {
protected RichTextArea rta;
protected RichTextToolbar toolbar;
+ protected RichTextArea rta2;
+ protected RichTextToolbar toolbar2;
protected TextArea wikiTextArea;
protected TextArea convertedTextArea;
@@ -51,10 +55,44 @@
public void refreshData() {
super.refreshData();
+
+ String newData = rta.getHTML();
+ Window.alert("New Data is " + newData);
+ String oldData = convertedTextArea.getText();
+ Window.alert("Old data is " + oldData);
+
+ convertedTextArea.setText(newData);
+ Window.alert("New Data in converted box is " + convertedTextArea.getText());
+
+ Revision rev;
+ try {
+ rev = Diff.diff(ToString.stringToArray(oldData), ToString.stringToArray(newData));
+ Window.alert(rev.toRCSString());
+ for (int i=0;i<rev.size();i++) {
+ Delta delta = rev.getDelta(i);
+ Chunk orig = delta.getOriginal();
+ Chunk revised = delta.getRevised();
+
+ Window.alert("Orig chunk: " + orig.toString());
+ Window.alert("Revised chunk: " + revised.toString());
+ }
+
+ // Trying to apply change to right box
+ String rta2Html = rta2.getHTML();
+ Window.alert("Text to patch: " + rta2Html);
+ String newRta2Html = ToString.arrayToString(rev.patch(ToString.stringToArray(rta2Html)));
+ rta2.setHTML(newRta2Html);
+ Window.alert("Date is second html box is " + rta2.getHTML());
+ } catch (Exception e) {
+ e.printStackTrace();
+ Window.alert(e.getMessage());
+ }
+
+
wysiwyg.getDataManager().convertHtml2XWiki(rta.getHTML(), Wysiwyg.getProperty("name"), new XWikiAsyncCallback(wysiwyg) {
public void onSuccess(Object result) {
super.onSuccess(result);
- convertedTextArea.setText((String) result);
+ wikiTextArea.setText((String) result);
}
});
}
@@ -64,21 +102,34 @@
panel.setWidth("100%");
rta = new RichTextArea();
rta.setHTML(wysiwyg.getConfig().getHtmlContent());
- rta.setWidth("100%");
+ rta.setWidth("400px");
rta.setHeight("400px");
toolbar = new RichTextToolbar(wysiwyg, rta);
- toolbar.setWidth("100%");
+ toolbar.setWidth("400px");
panel.add(toolbar);
panel.add(rta);
+
+ rta2 = new RichTextArea();
+ rta2.setHTML(wysiwyg.getConfig().getHtmlContent());
+ rta2.setWidth("400px");
+ rta2.setHeight("400px");
+ toolbar2 = new RichTextToolbar(wysiwyg, rta2);
+ toolbar2.setWidth("400px");
+ panel.add(toolbar2);
+ panel.add(rta2);
+
wiki