use of net.heartsome.cat.document.converter.AbstractConverter in project translationstudio8 by heartsome.
the class ConverterUtil method convert2Tbx.
public static File convert2Tbx(String fileName, IProgressMonitor monitor) throws ImportException {
File file = new File(fileName);
if (!file.exists()) {
throw new ImportException(fileName + Messages.getString("converter.ConverterUtil.msg"));
}
if (fileName.toLowerCase().endsWith(".tbx")) {
return null;
}
AbstractConverter conveter = ConverterFactory.getFile2TbxConverter(fileName);
if (null == conveter) {
return null;
}
File createTempFile = null;
boolean hasError = true;
monitor.beginTask("", 1);
try {
createTempFile = File.createTempFile("Tbx_", "" + System.currentTimeMillis() + ".tbx");
conveter.doConvert(createTempFile.getAbsolutePath(), new SubProgressMonitor(monitor, 1));
hasError = false;
} catch (OperationCanceledException e) {
throw e;
} catch (IOException e) {
LOGGER.error("", e);
throw new ImportException(e.getMessage().replace("\n", " "));
} catch (Exception e) {
LOGGER.error("", e);
throw new ImportException(e.getMessage().replace("\n", " "));
} finally {
if (hasError && null != createTempFile) {
createTempFile.delete();
}
monitor.done();
}
return createTempFile;
}
Aggregations