Search in sources :

Example 1 with File2TmxConvertBean

use of net.heartsome.cat.tmx.converter.bean.File2TmxConvertBean in project translationstudio8 by heartsome.

the class ConverterUtil method convert2Tmx.

public static File convert2Tmx(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(".tmx")) {
        return null;
    }
    AbstractFile2Tmx file2TmxConverter = ConverterFactory.getFile2TmxConverter(fileName);
    if (null == file2TmxConverter) {
        return null;
    }
    File createTempFile = null;
    boolean hasError = true;
    try {
        createTempFile = File.createTempFile("Tmx_", "" + System.currentTimeMillis() + ".tmx");
        SubProgressMonitor spm = new SubProgressMonitor(monitor, 30);
        File2TmxConvertBean bean = new File2TmxConvertBean();
        bean.sourceFilePath = fileName;
        bean.newTmxFilePath = createTempFile.getAbsolutePath();
        file2TmxConverter.doCovnerter(bean, spm);
        hasError = false;
    } 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();
        }
    }
    return createTempFile;
}
Also used : ImportException(net.heartsome.cat.common.core.exception.ImportException) File2TmxConvertBean(net.heartsome.cat.tmx.converter.bean.File2TmxConvertBean) IOException(java.io.IOException) 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 File2TmxConvertBean (net.heartsome.cat.tmx.converter.bean.File2TmxConvertBean)1 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)1 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)1