int threadCode = Thread.currentThread().hashCode();
//*-- a. unzip the OpenOffice file
logger.info("Extracting from OpenOffice file " + ifile);
ZipFile zFile;
try
{ zFile = new ZipFile(new File(ifile)); }
catch (IOException e)
{ logger.error("Could not open OpenOffice file " + ifile + " " + e.getMessage() );
return; }
//*-- b. Extract the content.xml file and write to a file
ZipEntry zEntry = zFile.getEntry("content.xml");
InputStream xmlStream = null; PrintWriter outp = null;
BufferedReader iReader = null;
String outfile = "";
try
{
//*-- create an input stream for the XML file
xmlStream = zFile.getInputStream(zEntry);
iReader = new BufferedReader( new InputStreamReader(xmlStream, "UTF-8") );
//*-- generate the output file name and dump the XML contents
String iline; outfile = Constants.OFFICEDIR + File.separator + "TEMP_content_" + threadCode + ".xml";
outp = new PrintWriter(new FileWriter(outfile));
while ( (iline = iReader.readLine()) != null ) { outp.println(iline); }
outp.flush();
}
catch (IOException e)
{ logger.error("Could not read text from OpenOffice file: " + ifile + " " + e.getMessage()); }
finally
{
if (outp != null) outp.close();
try
{ if (iReader != null) iReader.close();
if (xmlStream != null) xmlStream.close();
if (zFile != null) zFile.close();
}
catch (IOException exc) { logger.error("Ignore error"); }
}
//*-- parse the content.xml file with the SAXParser