Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

implmentation

  • Loading branch information...
commit 9ee2663d1759c2886947b14f6f0aa7c7327232f5 1 parent 6365e22
@hayeah authored
Showing with 65 additions and 0 deletions.
  1. +65 −0 lib/daisydiff.rb
  2. BIN  lib/daisydiff/daisydiff.jar
View
65 lib/daisydiff.rb
@@ -0,0 +1,65 @@
+$:.unshift(File.dirname(__FILE__)) unless $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
+
+raise "Celerity only works on JRuby at the moment." unless RUBY_PLATFORM =~ /java/
+
+require 'java'
+require 'daisydiff/daisydiff.jar'
+
+class DaisyDiff
+
+ import java.util.Locale
+
+ import javax.xml.transform.sax.SAXTransformerFactory
+ import javax.xml.transform.stream.StreamResult
+ import org.xml.sax.InputSource
+ import org.xml.sax.helpers.AttributesImpl
+
+ import org.outerj.daisy.diff
+ import org.outerj.daisy.diff.html
+ import org.outerj.daisy.diff.html.dom
+
+ class << self
+ def strings(str1,str2)
+ in1 = java.io.ByteArrayInputStream.new(str1.to_java_string.getBytes("UTF-8"))
+ in2 = java.io.ByteArrayInputStream.new(str2.to_java_string.getBytes("UTF-8"))
+ out = java.io.ByteArrayOutputStream.new
+ differ = self.new in1, in2, out
+ differ.process!
+ out.toString.to_s
+ end
+ end
+
+ def initialize(in1,in2,out)
+ @in1 = in1
+ @in2 = in2
+ @out = out
+ end
+
+ def process!
+ handler = self.handler(@out)
+ diff_output = HtmlSaxDiffOutput.new(handler,"diff")
+ differ = HTMLDiffer.new(diff_output)
+ handler.startDocument()
+ handler.startElement("","diff","diff",AttributesImpl.new())
+ differ.diff(comparator(@in1),comparator(@in2))
+ handler.endElement("","diff","diff")
+ handler.endDocument()
+ end
+
+ def handler(output)
+ handler = SAXTransformerFactory.newInstance.newTransformerHandler
+ handler.setResult(StreamResult.new(output))
+ handler
+ end
+
+ def comparator(input)
+ builder = DomTreeBuilder.new
+ cleaner = HtmlCleaner.new
+ cleaner.cleanAndParse(InputSource.new(input),builder)
+ TextNodeComparator.new(builder,locale)
+ end
+
+ def locale
+ Locale.getDefault()
+ end
+end
View
BIN  lib/daisydiff/daisydiff.jar
Binary file not shown
Please sign in to comment.
Something went wrong with that request. Please try again.