Search in sources :

Example 1 with DifferentiationFailedException

use of org.suigeneris.jrcs.diff.DifferentiationFailedException in project xwiki-platform by xwiki.

the class XWikiDocument method getLastChanges.

public List<Delta> getLastChanges(XWikiContext context) throws XWikiException, DifferentiationFailedException {
    Version version = getRCSVersion();
    try {
        String prev = getDocumentArchive(context).getPrevVersion(version).toString();
        XWikiDocument prevDoc = context.getWiki().getDocument(this, prev, context);
        return getDeltas(Diff.diff(ToString.stringToArray(prevDoc.getContent()), ToString.stringToArray(getContent())));
    } catch (Exception ex) {
        LOGGER.debug("Exception getting differences from previous version: " + ex.getMessage());
    }
    return new ArrayList<Delta>();
}
Also used : Version(org.suigeneris.jrcs.rcs.Version) ArrayList(java.util.ArrayList) ToString(org.suigeneris.jrcs.util.ToString) XWikiException(com.xpn.xwiki.XWikiException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) DifferentiationFailedException(org.suigeneris.jrcs.diff.DifferentiationFailedException) ExecutionContextException(org.xwiki.context.ExecutionContextException) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) MissingParserException(org.xwiki.rendering.parser.MissingParserException) IOException(java.io.IOException) ParseException(org.xwiki.rendering.parser.ParseException) TransformationException(org.xwiki.rendering.transformation.TransformationException) QueryException(org.xwiki.query.QueryException)

Example 2 with DifferentiationFailedException

use of org.suigeneris.jrcs.diff.DifferentiationFailedException in project jspwiki by apache.

the class TraditionalDiffProvider method makeDiffHtml.

/**
 * Makes a diff using the BMSI utility package. We use our own diff printer,
 * which makes things easier.
 *
 * @param ctx The WikiContext in which the diff should be made.
 * @param p1 The first string
 * @param p2 The second string.
 *
 * @return Full HTML diff.
 */
public String makeDiffHtml(WikiContext ctx, String p1, String p2) {
    String diffResult = "";
    try {
        String[] first = Diff.stringToArray(TextUtil.replaceEntities(p1));
        String[] second = Diff.stringToArray(TextUtil.replaceEntities(p2));
        Revision rev = Diff.diff(first, second, new MyersDiff());
        if (rev == null || rev.size() == 0) {
            return "";
        }
        // Guessing how big it will become...
        StringBuffer ret = new StringBuffer(rev.size() * 20);
        ret.append("<table class=\"diff\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n");
        rev.accept(new RevisionPrint(ctx, ret));
        ret.append("</table>\n");
        return ret.toString();
    } catch (DifferentiationFailedException e) {
        diffResult = "makeDiff failed with DifferentiationFailedException";
        log.error(diffResult, e);
    }
    return diffResult;
}
Also used : DifferentiationFailedException(org.suigeneris.jrcs.diff.DifferentiationFailedException) Revision(org.suigeneris.jrcs.diff.Revision) MyersDiff(org.suigeneris.jrcs.diff.myers.MyersDiff)

Example 3 with DifferentiationFailedException

use of org.suigeneris.jrcs.diff.DifferentiationFailedException in project jspwiki by apache.

the class ContextualDiffProvider method makeDiffHtml.

/**
 * Do a colored diff of the two regions. This. is. serious. fun. ;-)
 *
 * @see org.apache.wiki.diff.DiffProvider#makeDiffHtml(WikiContext, String, String)
 *
 * {@inheritDoc}
 */
public synchronized String makeDiffHtml(WikiContext ctx, String wikiOld, String wikiNew) {
    // 
    // Sequencing handles lineterminator to <br /> and every-other consequtive space to a &nbsp;
    // 
    String[] alpha = sequence(TextUtil.replaceEntities(wikiOld));
    String[] beta = sequence(TextUtil.replaceEntities(wikiNew));
    Revision rev = null;
    try {
        rev = Diff.diff(alpha, beta, new MyersDiff());
    } catch (DifferentiationFailedException dfe) {
        log.error("Diff generation failed", dfe);
        return "Error while creating version diff.";
    }
    int revSize = rev.size();
    StringBuffer sb = new StringBuffer();
    sb.append(m_diffStart);
    // 
    // The MyersDiff is a bit dumb by converting a single line multi-word diff into a series
    // of Changes. The ChangeMerger pulls them together again...
    // 
    ChangeMerger cm = new ChangeMerger(sb, alpha, revSize);
    rev.accept(cm);
    cm.shutdown();
    sb.append(m_diffEnd);
    return sb.toString();
}
Also used : DifferentiationFailedException(org.suigeneris.jrcs.diff.DifferentiationFailedException) Revision(org.suigeneris.jrcs.diff.Revision) MyersDiff(org.suigeneris.jrcs.diff.myers.MyersDiff)

Example 4 with DifferentiationFailedException

use of org.suigeneris.jrcs.diff.DifferentiationFailedException in project jspwiki by apache.

the class SpamFilter method getChange.

/**
 *  Creates a simple text string describing the added content.
 *
 *  @param context
 *  @param newText
 *  @return Empty string, if there is no change.
 */
private static Change getChange(WikiContext context, String newText) {
    WikiPage page = context.getPage();
    StringBuffer change = new StringBuffer();
    WikiEngine engine = context.getEngine();
    // Get current page version
    Change ch = new Change();
    try {
        String oldText = engine.getPureText(page.getName(), WikiProvider.LATEST_VERSION);
        String[] first = Diff.stringToArray(oldText);
        String[] second = Diff.stringToArray(newText);
        Revision rev = Diff.diff(first, second, new MyersDiff());
        if (rev == null || rev.size() == 0) {
            return ch;
        }
        for (int i = 0; i < rev.size(); i++) {
            Delta d = rev.getDelta(i);
            if (d instanceof AddDelta) {
                d.getRevised().toString(change, "", "\r\n");
                ch.m_adds++;
            } else if (d instanceof ChangeDelta) {
                d.getRevised().toString(change, "", "\r\n");
                ch.m_adds++;
            } else if (d instanceof DeleteDelta) {
                ch.m_removals++;
            }
        }
    } catch (DifferentiationFailedException e) {
        log.error("Diff failed", e);
    }
    // 
    // Don't forget to include the change note, too
    // 
    String changeNote = (String) page.getAttribute(WikiPage.CHANGENOTE);
    if (changeNote != null) {
        change.append("\r\n");
        change.append(changeNote);
    }
    // 
    if (page.getAuthor() != null) {
        change.append("\r\n" + page.getAuthor());
    }
    ch.m_change = change.toString();
    return ch;
}
Also used : ChangeDelta(org.suigeneris.jrcs.diff.delta.ChangeDelta) DifferentiationFailedException(org.suigeneris.jrcs.diff.DifferentiationFailedException) DeleteDelta(org.suigeneris.jrcs.diff.delta.DeleteDelta) WikiPage(org.apache.wiki.WikiPage) MyersDiff(org.suigeneris.jrcs.diff.myers.MyersDiff) Revision(org.suigeneris.jrcs.diff.Revision) DeleteDelta(org.suigeneris.jrcs.diff.delta.DeleteDelta) Delta(org.suigeneris.jrcs.diff.delta.Delta) AddDelta(org.suigeneris.jrcs.diff.delta.AddDelta) ChangeDelta(org.suigeneris.jrcs.diff.delta.ChangeDelta) AddDelta(org.suigeneris.jrcs.diff.delta.AddDelta) WikiEngine(org.apache.wiki.WikiEngine)

Aggregations

DifferentiationFailedException (org.suigeneris.jrcs.diff.DifferentiationFailedException)4 Revision (org.suigeneris.jrcs.diff.Revision)3 MyersDiff (org.suigeneris.jrcs.diff.myers.MyersDiff)3 XWikiException (com.xpn.xwiki.XWikiException)1 IOException (java.io.IOException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 ArrayList (java.util.ArrayList)1 WikiEngine (org.apache.wiki.WikiEngine)1 WikiPage (org.apache.wiki.WikiPage)1 AddDelta (org.suigeneris.jrcs.diff.delta.AddDelta)1 ChangeDelta (org.suigeneris.jrcs.diff.delta.ChangeDelta)1 DeleteDelta (org.suigeneris.jrcs.diff.delta.DeleteDelta)1 Delta (org.suigeneris.jrcs.diff.delta.Delta)1 Version (org.suigeneris.jrcs.rcs.Version)1 ToString (org.suigeneris.jrcs.util.ToString)1 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)1 ExecutionContextException (org.xwiki.context.ExecutionContextException)1 QueryException (org.xwiki.query.QueryException)1 MissingParserException (org.xwiki.rendering.parser.MissingParserException)1 ParseException (org.xwiki.rendering.parser.ParseException)1