songFile = new File(path + File.separator + name + ".song");
}
// Create song object
Song song = new Song();
song.setTitle(name);
song.setFilePath(songFile.getAbsolutePath());
song.setTemplate(DisplayControlConfig.getInstance().getDefaultTemplateSong());
// If needed, convert the file to ODP
File processFile = officeFile;
if (officeFile.getName().toLowerCase().endsWith("ppt") ||
officeFile.getName().toLowerCase().endsWith("pptx")){
OpenofficeHelper helper = new OpenofficeHelper();
String convFile = helper.convertToODP(officeFile);
processFile = new File(convFile);
if (!processFile.exists()){
throw new IOException(java.util.ResourceBundle.getBundle("datasoul/internationalize").getString("UNABLE TO CONVERT DOCUMENT: ")+officeFile.getName());
}
helper.dispose();
}
// Extract text from Office file
StringBuffer sb = new StringBuffer();
convertPresentationToText(processFile, sb);
song.setText(sb.toString());
// If needed, cleanup converted ODP file
if (processFile != officeFile){
processFile.delete();
}
// Write the file
try{
Node node = song.writeObject(null);
Document doc = node.getOwnerDocument();
doc.appendChild( node); // Add Root to Document
FileOutputStream fos = new FileOutputStream(song.getFilePath());
Source source = new DOMSource(doc);
// Prepare the output file
Result result = new StreamResult(fos);
// Write the DOM document to the file
Transformer xformer = TransformerFactory.newInstance().newTransformer();
xformer.setOutputProperty(OutputKeys.INDENT, "yes");
xformer.transform(source, result);
fos.close();
} catch(Exception e){
ShowDialog.showWriteFileError(song.getFileName(), e);
}
// Update table
AllSongsListTable.getInstance().addItem(song);