boolean bFlat = sFileName.toLowerCase().endsWith(".xml");
// Determine the type of document by the extension:
boolean bCalc = sFileName.toLowerCase().endsWith(".sxc");
boolean bImpress = sFileName.toLowerCase().endsWith(".sxi");
ConvertData dataOut = null;
// Create and use the converter
// No longer uses the XMerge interface
// Somewhat messy, should be changed if XMerge is discarded
OfficeDocument oooDoc;
if (bCalc) {
oooDoc = new SxcDocument(sFileName);
}
else if (bImpress) {
oooDoc = new SxiDocument(sFileName);
}
else {
oooDoc = new SxwDocument(sFileName);
}
File f = new File(sFileName);
// Make sure the input file actually exists before using it
try {
if (!f.exists()) {
System.out.println("I'm sorry, I can't find "+sFileName);
System.exit(0);
}
FileInputStream fis = new FileInputStream(f);
oooDoc.read(fis,!bFlat);
}
catch (IOException e) {
System.out.println("Oops, there was an error reading "+sFileName);
e.printStackTrace();
}
try {
if (toMime.equals(MIMETypes.LATEX)) {
writer2latex.latex.ConverterPalette converter
= new writer2latex.latex.ConverterPalette((SxwDocument)oooDoc,sConfigFileName);
converter.setOutFileName(sOutFileName);
dataOut = converter.convert();
}
else if (toMime.equals(MIMETypes.BIBTEX)) {
writer2latex.bibtex.DocumentSerializerImpl converter
= new writer2latex.bibtex.DocumentSerializerImpl((SxwDocument)oooDoc);
converter.setOutFileName(sOutFileName);
dataOut = converter.serialize();
}
/* disabled XHTML filter part
else if (toMime.equals(MIMETypes.XHTML)) {
writer2latex.xhtml.DocumentSerializerImpl converter
= new writer2latex.xhtml.DocumentSerializerImpl(oooDoc,
XhtmlDocument.XHTML10, sConfigFileName);
converter.setOutFileName(sOutFileName);
dataOut = converter.serialize();
}
else if (toMime.equals(MIMETypes.XHTML_MATHML)) {
writer2latex.xhtml.DocumentSerializerImpl converter
= new writer2latex.xhtml.DocumentSerializerImpl(oooDoc,
XhtmlDocument.XHTML_MATHML, sConfigFileName);
converter.setOutFileName(sOutFileName);
dataOut = converter.serialize();
}
else if (toMime.equals(MIMETypes.XHTML_MATHML_XSL)) {
writer2latex.xhtml.DocumentSerializerImpl converter
= new writer2latex.xhtml.DocumentSerializerImpl(oooDoc,
XhtmlDocument.XHTML_MATHML_XSL, sConfigFileName);
converter.setOutFileName(sOutFileName);
dataOut = converter.serialize();
}
*/
}
catch (Exception e) {
System.out.println("Conversion failed");
e.printStackTrace();
}
// TODO: Should do some further checking on the feasability of writing
// the directory and the files.
File dir = new File(sOutPathName);
if (!dir.exists()) { dir.mkdirs(); }
Enumeration docEnum = dataOut.getDocumentEnumeration();
while (docEnum.hasMoreElements()) {
Document docOut = (Document)docEnum.nextElement();
String fileName = sOutPathName+docOut.getFileName();
try {
FileOutputStream fos = new FileOutputStream(fileName);