WikiDiffGroovy
/* Groovy Class #* */
import java.util.*
import java.net.URL;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import java.io.*;
import com.xpn.xwiki.doc.XWikiDocument;
import com.xpn.xwiki.api.Document;
class Diff {
def xwiki;
def context;
public setContext(context, xwiki) {
this.xwiki = xwiki
this.context = context
}
public clean1(content) {
return content.replaceAll("\r", "").replaceAll("\n", "").replaceAll("(?s)<attachment>(.*?)<content>(.*?)</content>(.*?)</attachment>", "<attachment>\$1<content></content>\$3</attachment>").replaceAll("(?s)<guid>(.*?)</guid>", "<guid></guid>")
}
public clean2(content) {
return content.replaceAll("\r", "").replaceAll("(?s)<attachment>(.*?)<content>(.*?)</content>(.*?)</attachment>", "<attachment>\$1<content></content>\$3</attachment>").replaceAll("(?s)<guid>(.*?)</guid>", "<guid></guid>")
}
public save(filename, content, bclean) {
FileOutputStream fis = new FileOutputStream(new File("/tmp/${filename}"));
def data = (bclean) ? clean1(content) : content
fis.write(data.getBytes());
fis.close();
}
boolean compare(oldContent, newContent) {
oldContent = clean1(oldContent)
newContent = clean1(newContent)
return !oldContent.equals(newContent);
}
String diff(def oldContent, def newContent) {
oldContent = clean2(oldContent)
newContent = clean2(newContent)
return xwiki.diff.getDifferencesAsHTML(oldContent, newContent, false);
}
public getDocument(content) {
def newdoc = new XWikiDocument();
newdoc.fromXML(content);
return new Document(newdoc, context.getContext());
}
public getXMLFromString(content) {
def newdoc = new XWikiDocument();
newdoc.fromXML(content);
return getXML2(newdoc);
}
public getXML(pagedoc) {
def clonedDoc = pagedoc.document.clone();
return getXML2(clonedDoc);
}
public getXML2(clonedDoc) {
def defaultUser = "XWiki.Admin";
def defaultDate = new Date("01/01/2010");
remove Tag object
if (clonedDoc.getObject("XWiki.TagClass")) {
clonedDoc.removeObject(clonedDoc.getObject("XWiki.TagClass"));
}
if (defaultUser && defaultUser!="") {
clonedDoc.setCreator(defaultUser);
clonedDoc.setContentAuthor(defaultUser);
clonedDoc.setAuthor(defaultUser);
} else {
clonedDoc.setCreator(clonedDoc.getAuthor());
clonedDoc.setContentAuthor(clonedDoc.getAuthor());
}
if (defaultDate && defaultDate!="") {
clonedDoc.setCreationDate(defaultDate);
clonedDoc.setContentUpdateDate(defaultDate);
clonedDoc.setDate(defaultDate);
clonedDoc.setVersion("1.1");
} else {
clonedDoc.setContentUpdateDate(clonedDoc.getDate())
clonedDoc.setCreationDate(clonedDoc.getDate())
clonedDoc.setVersion("1.1");
}
clonedDoc.setComment("");
clonedDoc.setMinorEdit(false);
def c = clonedDoc.toXML(true, false, true, false, context.getContext())
return c.trim().replaceAll("[\r]","");
}
Map<String, String> getZipContent(String url) throws Exception
{
Map<String, String> zipContent = new HashMap<String, String>();
ZipInputStream zis = new ZipInputStream(new URL(url).openStream());
byte[] buffer = new byte[2048];
ZipEntry entry;
while ((entry = zis.getNextEntry()) != null) {
StringBuffer content = new StringBuffer();
int len = 0;
while ((len = zis.read(buffer)) > 0)
{
content.append(new String(buffer, 0, len));
}
zipContent.put(entry.getName(), content.toString());
}
zis.close();
return zipContent;
}
}
/* *# */
Cedric Thomas
Patrick Starck
Mark Weitzel
Alexandre Zapolsky
Round Table1
Gianfranco Boccalon
Thomas Mortagne
Serge Lacourte
Florent Garin
Frederic Aatz
Alfonso Castro
Jamie Marshall
Bernard Boltz
Alexandre Lefebvre
Thomas Debru
Denis Caromel
Daniel Stern
Bruno Dillenseger
Jean-Christophe Vuillot
Jeanne Le Garrec
Sylvain Baubeau
Jean-Marc Menaud
Fabien Hermenier
Christophe Hamerling
Patrick Petit
Marius Preda
Frederic Dang Tran
Pawel Rubach
Eric Debeau
Alban Richard
Andrea Manieri
Ali Ataya
Round Table2
Rani Halimi
Nicolas Aube
Marc Triboulet
Jim Walker
Monica Franceschini
Cedric Carbone
John Mertic
Marc Dutoo
Clement Oudot
Christophe Hamerling
Alexis Portmann
Goulven Le Jeune
Gerard Dupont
Alexandre Lefebvre
Guillaume Sauthier
Clement Escoffier
Christophe Hamerling
Guillaume Sauthier
Williams Lamar
Philippe Bolac
Meng Li
Gabriele Giammatteo
Daniele Gagliardi
Marc Lacoste
Pierre Chatel
Gaurav Parakh
Michel Catan
Cedric Thomas
Follow us on Twitter
Network @ LinkedIn

































