Package COM. syni. im800.kb. common. util; import Java. io. file; import Java. io. fileoutputstream; import Java. io. ioexception; import Java. io. inputstream; import Java. io. outputstream; import java.net. connectexception; import Java. text. simpledateformat; import Java. util. date; import Org. apache. commons. logging. log; import Org. apache. commons. logging. logfactory; import COM. artofsolving. jodconverter. documentconverter; Im Port COM. artofsolving. jodconverter. openOffice. connection. openofficeconnection; import COM. artofsolving. jodconverter. openOffice. connection. socketopenofficeconnection; import COM. artofsolving. jodconverter. openOffice. converter. openofficedocumentconverter; import COM. syni. im800.kb. config. appconfig;/*** use jodconverter (based on the OpenOffice service) to convert the Word file (*. doc) is converted to HTML format. * check whether the OpenOffice service is enabled before use. * OpenOffice process name: So Ffice.exe | soffice. bin * @ author linshutao **/public class doc2htmlutil {log = logfactory. getlog (getclass (); Private Static doc2htmlutil doc2htmlutil;/*** get doc2htmlutil instance **/public static synchronized doc2htmlutil Merge () {If (doc2htmlutil = NULL) {doc2htmlutil = new doc2htmlutil ();} return doc2htmlutil;}/*** conversion file * @ Param fromfileinputstream: **/Public String doc2html (in Putstream fromfileinputstream, file tofilefolder) {string soffice_host = appconfig. getproperty (appconfig. soffice_host_key); string soffice_port = appconfig. getproperty (appconfig. soffice_port_key); log. debug ("soffice_host:" + soffice_host + ", soffice_port:" + soffice_port); Date = new date (); simpledateformat SDF = new simpledateformat ("yyyymmddhhmmss "); string timesuffix = SDF. format (date); string htmfilen Ame = "htmlfile" + timesuffix + ". html "; string docfilename =" docfile "+ timesuffix + ". doc "; file htmloutputfile = new file (tofilefolder. tostring () + file. separatorchar + htmfilename); file docinputfile = new file (tofilefolder. tostring () + file. separatorchar + docfilename); log. debug ("######## htmloutputfile:" + tofilefolder. tostring () + file. pathseparator + htmfilename);/*** build the input file by fromfileinputstream **/try {outputstr Eam OS = new fileoutputstream (docinputfile); int bytesread = 0; byte [] buffer = new byte [1024*8]; while (bytesread = fromfileinputstream. Read (buffer ))! =-1) {OS. write (buffer, 0, bytesread);} OS. close (); fromfileinputstream. close ();} catch (ioexception e) {log. error (E. getmessage (), e);} openofficeconnection connection = new socketopenofficeconnection (soffice_host, integer. parseint (soffice_port); try {connection. connect ();} catch (connectexception e) {system. err. println ("file conversion error. Check whether the OpenOffice service is enabled. "); Log. error (E. getmessage (), e);} // convertdocumentconverter converter = new openofficedocumentconverter (connection); converter. convert (docinputfile, htmloutputfile); connection. disconnect ();/* file htmloutputfile_rn = new file (htmloutputfile. getabsolutepath (). substring (0, htmloutputfile. getabsolutepath (). lastindexof (". ") + ". htm "); htmloutputfile. renameto (htmloutputfile_rn); Return htmloutputfile_rn.getname (); * // After conversion, delete the word file docinputfile. delete (); log. debug ("delete Upload File:" + docinputfile. getname (); Return htmfilename ;}}