catch(NumberFormatException nfe)
{
// Do nothing. Use the default value of 20 instead.
}
OpenOfficeConnection connection = new SocketOpenOfficeConnection(8100);
//------------------------
// Setup the output files
//------------------------
String fileName = aDocFile.getName().substring(0, aDocFile.getName().indexOf("."));
int idIndex = fileName.indexOf("_");
String digitalAssetPath = CmsPropertyHandler.getDigitalAssetPath();
String folderName = "";
if(idIndex > -1)
{
String fileIdString = fileName.substring(0, idIndex);
int fileId = Integer.parseInt(fileIdString);
folderName = "" + (fileId / 1000);
digitalAssetPath = digitalAssetPath + File.separator + folderName;
}
//----------------------------------------
// Add the name of the folder to the path
//----------------------------------------
digitalAssetPath = digitalAssetPath + File.separator + fileName;
logger.info("Directory to write files to: " + digitalAssetPath);
//-------------------------------------------------
// Add a folder where the files are to be written.
//-------------------------------------------------
String newFilePath = digitalAssetPath + File.separator + fileName;
File pdfFile = new File(newFilePath + ".pdf");
File odtFile = new File(newFilePath + ".odt");
File htmlFile = new File(newFilePath + ".html");
File contentXmlFile = new File(digitalAssetPath + File.separator + "content.xml");;
//----------------------------------------------
// Check if the doc has already been converted.
// If it has, we don't need another conversion.
//----------------------------------------------
File documentDir = new File(digitalAssetPath);
if (!documentDir.exists() || rewrite.equals("true"))
{
logger.info("The directory " + digitalAssetPath + " does not exist. Creating it.");
documentDir.mkdir();
logger.info("The directory " + digitalAssetPath + " was successfully created.");
logger.info("Connecting to server...");
connection.connect();
logger.info("Connection ok");
logger.info("Conversion START");
convertDocument(aDocFile, htmlFile, connection);
if(!aDocFile.getName().substring(aDocFile.getName().indexOf(".") + 1).equalsIgnoreCase("odt"))
{
convertDocument(aDocFile, odtFile, connection);
}
else
{
odtFile = aDocFile;
}
convertDocument(aDocFile, pdfFile, connection);
connection.disconnect();
logger.info("Conversion END");
//------------------------------------------------
// Extract the content.xml file from the ODT file