Example usage for org.apache.commons.jrcs.diff Revision accept

List of usage examples for org.apache.commons.jrcs.diff Revision accept

Introduction

In this page you can find the example usage for org.apache.commons.jrcs.diff Revision accept.

Prototype

public void accept(RevisionVisitor visitor) 

Source Link

Document

Accepts a visitor.

Usage

From source file:com.ecyrd.jspwiki.diff.TraditionalDiffProvider.java

/**
 * Makes a diff using the BMSI utility package. We use our own diff printer,
 * which makes things easier.//w  w  w.  j a v a2s . c  om
 * 
 * @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) {
            // No difference

            return "";
        }

        StringBuffer ret = new StringBuffer(rev.size() * 20); // Guessing how big it will become...

        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;
}

From source file:cn.vlabs.duckling.vwb.service.diff.impl.TraditionalDiffProvider.java

/**
 * Makes a diff using the BMSI utility package. We use our own diff printer,
 * which makes things easier.//from ww  w . j  av  a 2  s .c o m
 */
public String makeDiffHtml(VWBContext 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) {
            // No difference

            return "";
        }

        StringBuffer ret = new StringBuffer(rev.size() * 20); // Guessing
        // how big
        // it will
        // become...

        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;
}

From source file:com.ecyrd.jspwiki.diff.ContextualDiffProvider.java

/**
 * Do a colored diff of the two regions. This. is. serious. fun. ;-)
 *
 * @see com.ecyrd.jspwiki.diff.DiffProvider#makeDiffHtml(WikiContext, String, String)
 * /*from   w w  w  . j a  va2 s . co m*/
 * {@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();
}

From source file:org.apache.wiki.diff.FlowchartDiffProvider.java

private String createTextDiff(WikiContext ctx, String p1, String p2, StringBuffer buffy)
        throws DifferentiationFailedException {
    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) {
        // No difference

        return "";
    }//from ww  w.  j  a v a  2s .  c  o m

    // first version is empty page. Diff is called when article is created
    if (p1.equals("")) {
        return "";
    }

    // how big
    // it will
    // become...

    buffy.append("<table class=\"diff\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n");
    rev.accept(new RevisionPrint(ctx, buffy));
    buffy.append("</table>\n");

    return buffy.toString();
}