Giter Site home page Giter Site logo

Comments (4)

GoogleCodeExporter avatar GoogleCodeExporter commented on June 3, 2024
Thanks for reporting.

The code works for me when I change the first lines to
        String contentOld = "<html><body>festive 8</body></html>";
        String contentNew = "<html><body>What was your highlight of 8?</body></html>";

Keep in mind that DaisyDiff was created to compare XHTML and that the behaviour 
for
other input is undefined.

Does this help you or do you believe DaisyDiff should support plain text?

Original comment by [email protected] on 17 Feb 2009 at 4:43

  • Changed state: WontFix

from daisydiff.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 3, 2024
This is not the ideal solution I was looking for. Padding texts with html tags 
should 
not be mandatory. 

Although DaisyDiff was created to compare XHTML, I think it should be extended 
to 
handle textual inputs too (just a suggestion). A classic case where this can 
come in 
handy is where you have two different stories to compare and you use this 
library 
from a custom tag to compare the author, created date, title, summary etc. of 
the two 
stories.

Original comment by [email protected] on 17 Feb 2009 at 5:09

from daisydiff.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 3, 2024
BTW, I got it to work using the following piece of code.

<code>
    String contentOld = "festive 8";
    String contentNew = "What was your highlight of 8?";
    getDiffForHTMLInput(contentOld, contentNew);

    private String getDiffForHTMLInput ( String contentOld, String contentNew ) 
throws Exception
    {
        contentOld = contentOld == null ? "" : contentOld;
        contentNew = contentNew == null ? "" : contentNew;
        StringWriter writer = new StringWriter(contentNew.length() + 
contentOld.length());
        List styleList = new ArrayList();
        styleList.add("/static/js/difftag/css/difftag.css");

        SAXTransformerFactory tf = (SAXTransformerFactory) 
TransformerFactory.newInstance();
        TransformerHandler result = tf.newTransformerHandler();
        result.setResult(new StreamResult(writer));

        ContentHandler postProcess = result;
        Locale locale = Locale.getDefault();
        String prefix = "diff";
        HtmlCleaner cleaner = new HtmlCleaner();
        InputSource oldSource = new InputSource(new 
ByteArrayInputStream(contentOld.getBytes("UTF-8")));
        InputSource newSource = new InputSource(new 
ByteArrayInputStream(contentNew.getBytes("UTF-8")));
        DomTreeBuilder oldHandler = new DomTreeBuilder();
        cleaner.cleanAndParse(oldSource, oldHandler);
        TextNodeComparator leftComparator = new TextNodeComparator(oldHandler, 
locale);
        DomTreeBuilder newHandler = new DomTreeBuilder();
        cleaner.cleanAndParse(newSource, newHandler);
        TextNodeComparator rightComparator = new TextNodeComparator(newHandler, 
locale);
        postProcess.startDocument();
        postProcess.startElement("", "diffreport", "diffreport", new 
AttributesImpl());
        attachStyleSheets(styleList, postProcess);
        postProcess.startElement("", "diff", "diff", new AttributesImpl());
        HtmlSaxDiffOutput output = new HtmlSaxDiffOutput(postProcess, prefix);
        HTMLDiffer differ = new HTMLDiffer(output);
        differ.diff(leftComparator, rightComparator);
        postProcess.endElement("", "diff", "diff");
        postProcess.endElement("", "diffreport", "diffreport");
        postProcess.endDocument();
        return writer.getBuffer().toString();
    }


    private void attachStyleSheets ( List styles, ContentHandler handler ) throws 
SAXException
    {
        handler.startElement("", "css", "css", new AttributesImpl());
        for (Iterator i = styles.iterator(); i.hasNext(); handler.endElement("", 
"link", "link"))
        {
            String cssLink = (String) i.next();
            AttributesImpl attr = new AttributesImpl();
            attr.addAttribute("", "href", "href", "CDATA", cssLink);
            attr.addAttribute("", "type", "type", "CDATA", "text/css");
            attr.addAttribute("", "rel", "rel", "CDATA", "stylesheet");
            handler.startElement("", "link", "link", attr);
        }
    }

</code>

Original comment by [email protected] on 17 Feb 2009 at 5:12

from daisydiff.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 3, 2024
Btw, if you want to diff plain text then I can recommend
http://code.google.com/p/google-diff-match-patch/ . If you have the time I'd be 
very
happy to accept patches that add support for plain text.

Valid XML should have a single root element (like <html>) so anything else is 
not
valid input and you should indeed wrap your snippets.

Original comment by [email protected] on 17 Feb 2009 at 5:31

from daisydiff.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.