Search in sources :

Example 1 with ImportAbstract

use of net.heartsome.cat.document.ImportAbstract in project translationstudio8 by heartsome.

the class DatabaseService method importTbxWithFile.

/**
	 * 将TBX文件导入到指定的数据库中
	 * @param fileName
	 *            TBX文件完整路径
	 * @param monitor
	 *            需要使用的进度条,如果不需要使用进度条,则为null
	 * @param metaData
	 *            数据库元数据,封装了一系列连接数据库的参数,用于连接数据,参考{@link MetaData}
	 * @param strategy
	 *            TBX导入策略,参考{@link Constants}中的定义
	 * @return 导入结果,为int型数据,参考{@link ImportAbstract}中的定义;;
	 * @throws ImportException
	 */
public static int importTbxWithFile(String fileName, IProgressMonitor monitor, MetaData metaData, int strategy) throws ImportException {
    File file = new File(fileName);
    if (file.exists() || !file.isDirectory()) {
        if (!fileName.toLowerCase().endsWith(".tbx")) {
            monitor.beginTask("", 100);
            File convet2tbx = null;
            try {
                convet2tbx = ConverterUtil.convert2Tbx(fileName, new SubProgressMonitor(monitor, 30));
            } catch (OperationCanceledException e) {
                return CANCEL;
            } catch (ImportException e) {
                LOGGER.error("", e);
                throw new ImportException(e.getMessage().replace("\n", " "));
            }
            if (convet2tbx != null) {
                file = convet2tbx;
            } else {
                file = new File(fileName);
            }
        } else {
            monitor.beginTask("", 70);
        }
        DBOperator dbOp = getDBOperator(metaData);
        try {
            dbOp.start();
            ImportAbstract impOp = new ImportTbx(dbOp, strategy);
            int result = impOp.doImport(file.getAbsolutePath(), new SubProgressMonitor(monitor, 70));
            return result;
        } catch (SQLException e) {
            LOGGER.error(Messages.getString("service.DatabaseService.logger10") + dbOp.getMetaData().getDatabaseName(), e);
            return ImportAbstract.FAILURE_3;
        } catch (ClassNotFoundException e) {
            LOGGER.error(Messages.getString("service.DatabaseService.logger11"), e);
            return ImportAbstract.FAILURE_3;
        } finally {
            if (dbOp != null) {
                try {
                    dbOp.end();
                } catch (SQLException e) {
                    LOGGER.error(Messages.getString("service.DatabaseService.logger12"), e);
                }
            }
            monitor.done();
        }
    }
    return ImportAbstract.FAILURE;
}
Also used : ImportException(net.heartsome.cat.common.core.exception.ImportException) ImportTbx(net.heartsome.cat.document.ImportTbx) ImportAbstract(net.heartsome.cat.document.ImportAbstract) SQLException(java.sql.SQLException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) SystemDBOperator(net.heartsome.cat.database.SystemDBOperator) DBOperator(net.heartsome.cat.database.DBOperator) File(java.io.File) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Example 2 with ImportAbstract

use of net.heartsome.cat.document.ImportAbstract in project translationstudio8 by heartsome.

the class DatabaseService method importTbxWithString.

public static int importTbxWithString(String tbxStr, IProgressMonitor monitor, DBOperator dbOp, int strategy, String srcLang) throws ImportException {
    ImportAbstract impOp = new ImportTbx(dbOp, strategy);
    int result = impOp.doImport(tbxStr, srcLang, monitor);
    return result;
}
Also used : ImportTbx(net.heartsome.cat.document.ImportTbx) ImportAbstract(net.heartsome.cat.document.ImportAbstract)

Aggregations

ImportAbstract (net.heartsome.cat.document.ImportAbstract)2 ImportTbx (net.heartsome.cat.document.ImportTbx)2 File (java.io.File)1 SQLException (java.sql.SQLException)1 ImportException (net.heartsome.cat.common.core.exception.ImportException)1 DBOperator (net.heartsome.cat.database.DBOperator)1 SystemDBOperator (net.heartsome.cat.database.SystemDBOperator)1 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)1 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)1