CompareHTMLComponent : JAR to compare two HTML fragments
After my initial post yesterday CFX_CompareHTML ColdFusion HTML diff custom tag I got quite a bit of feedback and one of the items raised was that some people dont like CFX tags and I should use JavaLoader to use the JAR file from within ColdFusion. (Thanks Dan Vega)
I have uploaded a JAR file called CompareHTMLComponent which allows you to do this.
To call the diff component use the following:
<cfset paths = arrayNew(1)>
<cfset paths[1] = expandPath("CompareHTMLComponent.jar")>
<cfset loader = createObject("component", "javaloader.JavaLoader").init(paths)>
<cfset compareComponent = loader.create("CompareHTMLComponent")>
<cfset diff = compareComponent.init()>

As always, feedback is most appreciated so hit me with your thoughts in the comments!
The JAR file and examples can be downloaded from here :
Requires Java 1.5 JRE to be installed or it will throw an exception! ColdFusion 8 & Railo 3 should have this but CFMX7 may not.
Comments
Boy your quick!
If you get CompareHTMLComponent (Unsupported major.minor version 50.0) then the JRE is 1.4 and DaisyDiff requires 1.5. Railo and CF8 should be fine but CFMX7 and 6 may not.
I'll try and get a 1.4 version going...
thanks for this great function. Always waited for something like that. I have problems with special characters. My page is utf-8 encoded but everything passed to the function returns unwanted characters. Du you have any ideas for that?
If your using cffile to load the contents, specify the charset attribute of cffile.
Let me know how you get on,
Dan.
#diff.compare('with utf-8 german special characters are no problem: ? ? ? ? ?','with utf-8 german special characters are no problem: ? ? ? ? ?')#
ExceptionType: org.xml.sax.SAXException
Message: java.io.FileNotFoundException: /tmpb361d82f-7b11-4fdc-b031-4610dc878253.tmp (Permission denied)
Maybe you should check for a ending slash in the temp folder (java.io.tmpdir) in CompareHTMLComponent.java?
The only workaround (whitout source) right now could be to alter the temp path in the java args: $JAVA_HOME/bin/java -Djava.io.tmpdir=/var/tmp/alt/
Doh! i'll fix this and post up a new version. I have a newer one available that fixes UTF-8 chars so I'll add in a fix for this.
Dan.
String fileSeparator = System.getProperty("file.separator");
/* Add separator for Linux and Mac:
http://rationalpi.wordpress.com/2007/01/26/javaiotmpdir-inconsitency/ */
if (!outputFile.endsWith(fileSeparator)) outputFile = outputFile fileSeparator;
outputFile = outputFile uid ".tmp";
Great job.
Any chance of releasing the new version? I also have UTF-8 problems.
btw - Is it necessary to write temporary files?
javax.xml.transform.TransformerFactoryConfigurationError: Provider org.apache.xalan.processor.TransformerFactoryImpl not found
Thanks!