Search in sources :

Example 1 with AbstractConverter

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;
}
Also used : ImportException(net.heartsome.cat.common.core.exception.ImportException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) IOException(java.io.IOException) AbstractConverter(net.heartsome.cat.document.converter.AbstractConverter) File(java.io.File) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) ImportException(net.heartsome.cat.common.core.exception.ImportException) IOException(java.io.IOException)

Aggregations

File (java.io.File)1 IOException (java.io.IOException)1 ImportException (net.heartsome.cat.common.core.exception.ImportException)1 AbstractConverter (net.heartsome.cat.document.converter.AbstractConverter)1 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)1 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)1