[xwiki-dev] Difference Engine Refactoring and Improvements

Vincent Massol vincent at massol.net
Wed May 2 08:52:35 CEST 2007


On May 1, 2007, at 3:22 PM, Ludovic Dubost wrote:

>
> I have the need to show a better diff page for a page containing an  
> object.

Yes I agree we really need this. Personally I'd like to set up the  
email plugin on xwiki.org and send the diff of the modifications to  
the dev list whenever someone makes a change.

> Since there is no generic diff for objects, I'd like to write a  
> Diff plugin allowing to make a nice diff of any two strings passed.

Are you talking about Object diffs or String diffs here? Or do you  
mean XML diff?

I think we have 2 options:
- Diff of Objects: Difference getDifferences(Object o1, Object o2). I  
guess the diff could then be the difference of object fields. This  
would need to be implemented for each XWiki Object.
- XML difference. This is the XML representation of XWiki Objects. I  
don't think there are any good/simple XML diff frameworks so we would  
also need to implement that.

I think it's better to do an Object diff as otherwise the xml diff  
would need to be transformed to be presented to the user and this  
will require extra parsing. Better to operate on Object as we already  
have them in our java code.

> At the same time I'd like to start a refactoring of the current  
> diff in the same plugin.

> Currently I see the following APIs:
>
> DiffPlugin
>  // returns a list of org.suigeneris.jrcs.diff.Delta (which  
> representd differences)
>  getLineDiffAsList(String content1, String content2)
>  // returns a list of org.suigeneris.jrcs.diff.Delta (which  
> representd differences)
>  getWordDiffAsList(String content1, String content2)
>
>  // returns an HTML view of differences
>  getLineDiffAsList(String content1, String content2)
>  // returns an HTML view of differences
>  getWordDiffAsList(String content1, String content2)
>
>  // returns an Text view of differences
>  getLineDiffAsList(String content1, String content2)
>  // returns an Text view of differences
>  getWordDiffAsList(String content1, String content2)
>

I don't understand. I would have used something like:

List<Difference> getDifferences(XWikiDocument, XWikiDocument)
List<Difference> getDifferences(XObject, XObject)
List<Difference> getDifferences(String, String)

Also, I think it's critical that in an API we should only use our own  
classes/interfaces and no external ones, so I think we should have  
our own Difference class and not use JRCS'. It could possibly wrap it  
if necessary.

> Other APIs could be a function to get a complete diff of an  
> XWikiDocument (includes objects, attachements), however the  
> implementation itself should probably reside in an velocity template.

The implementation of a document difference should in the plugin I  
think. The plugin should only do backend stuff though and return a  
list of named differences. I agree it would be up to the vm files to  
do the presentation of it (be if for the wiki, for an email to be  
sent, etc).

> There is an interesting discussion to have about how the  
> representation of the Text and HTML views should be.

Yes, that's hard. I'd like to see a wiki markup diff in addition to  
the current HTML diff we have as I find our current diff not very  
good. I think we need both.

> Any ideas ?
>
> Another question is wether it is a good idea to put this as a  
> plugin. I think yes since it could be use for other things than the  
> wiki content.

A plugin would be good I think as it means the implementation becomes  
pluggable. In the future it would be transformed into a component but  
that's the same idea.

Thanks
-Vincent





More information about the devs mailing list