use of net.heartsome.cat.document.ImportTmx in project translationstudio8 by heartsome.
the class DatabaseService method importTmxWithString.
/**
* 将内容为TMX标准格式的字符串数据导入到指定的数据库中,数据库连接由外部管理
* @param dbOp
* @param tmxStr
* @param monitor
* @param strategy
* @param checkContext
* @param sourceLanguage
* @return ;
* @throws ImportException
*/
public static int importTmxWithString(DBOperator dbOp, String tmxStr, IProgressMonitor monitor, int strategy, boolean checkContext, String sourceLanguage) throws ImportException {
// ImportAbstract impOp = new ImportTmx(dbOp, strategy, checkContext);
// int result = impOp.doImport(tmxStr, sourceLanguage, monitor);
ImportTmx i = new ImportTmx(dbOp, strategy, monitor);
i.importTmxContent(tmxStr);
return 1;
}
use of net.heartsome.cat.document.ImportTmx in project translationstudio8 by heartsome.
the class DatabaseService method importTmxWithFile.
/**
* 将TMX文件导入到指定的数据库中
* @param metaData
* 数据库元数据,封装了一系列连接数据库的参数,用于连接数据,参考{@link MetaData}
* @param fileName
* TMX文件完整路径
* @param monitor
* 需要使用的进度条,如果不需要使用进度条,则为null
* @param strategy
* TMX导入策略,参考{@link Constants}中的定义
* @param checkContext
* TMX导入时,是否需要检查上下文
* @return 导入结果,为int型数据,参考{@link ImportAbstract}中的定义;
* @throws ImportException
*/
public static int importTmxWithFile(MetaData metaData, String fileName, IProgressMonitor monitor, int strategy, boolean checkContext) throws ImportException {
// add convert to tmx method
File convert2Tmx = null;
try {
convert2Tmx = ConverterUtil.convert2Tmx(fileName, monitor);
} catch (ImportException e) {
LOGGER.error("", e);
throw new ImportException(e.getMessage().replace("\n", " "));
}
File file = null;
if (convert2Tmx != null) {
file = convert2Tmx;
} else {
file = new File(fileName);
}
if (file.exists() || !file.isDirectory()) {
// try {
// // 检查原始文件是否能通过 VTD 的解析
// new TmxReader(file);
// } catch (TmxReadException e1) {
// throw new ImportException(e1.getMessage().replace("\n", " "));
// }
// File _file = Utils.clearTmxFile(file);
DBOperator dbOp = getDBOperator(metaData);
try {
dbOp.start();
// ImportAbstract impOp = new ImportTmx(dbOp, strategy, checkContext);
// int result = impOp.doImport(_file.getAbsolutePath(), monitor);
// return result;
ImportTmx i = new ImportTmx(dbOp, strategy, monitor);
i.importTmxFile(file);
return 1;
} catch (SQLException e) {
LOGGER.error(Messages.getString("service.DatabaseService.logger1") + dbOp.getMetaData().getDatabaseName(), e);
return ImportAbstract.FAILURE_3;
} catch (ClassNotFoundException e) {
LOGGER.error(Messages.getString("service.DatabaseService.logger2"), e);
return ImportAbstract.FAILURE_3;
} finally {
if (dbOp != null) {
try {
dbOp.end();
} catch (SQLException e) {
LOGGER.error(Messages.getString("service.DatabaseService.logger3"), e);
}
}
if (null != convert2Tmx) {
convert2Tmx.delete();
}
// _file.delete();
}
}
return ImportAbstract.FAILURE_1;
}
use of net.heartsome.cat.document.ImportTmx in project translationstudio8 by heartsome.
the class DatabaseService method importTmxWithString.
/**
* 将内容为TMX标准格式的字符串数据导入到指定的数据库中
* @param metaData
* 数据库元数据,封装了一系列连接数据库的参数,用于连接数据,参考{@link MetaData}
* @param tmxStr
* 内容为TMX标准格式的字符串
* @param monitor
* 需要使用的进度条,如果不需要使用进度条,则为null
* @param strategy
* TMX导入策略,参考{@link Constants}中的定义
* @param checkContext
* TMX导入时,是否需要检查上下文
* @param sourceLanguage
* 该字符串内容的TMX源语言
* @return 导入结果,为int型数据,参考{@link ImportAbstract}中的定义;
* @throws ImportException
*/
public static int importTmxWithString(MetaData metaData, String tmxStr, IProgressMonitor monitor, int strategy, boolean checkContext, String sourceLanguage) throws ImportException {
if (tmxStr != null && tmxStr.length() > 0) {
DBOperator dbOp = getDBOperator(metaData);
try {
dbOp.start();
// ImportAbstract impOp = new ImportTmx(dbOp, strategy, checkContext);
// int result = impOp.doImport(tmxStr, sourceLanguage, monitor);
ImportTmx i = new ImportTmx(dbOp, strategy, monitor);
i.importTmxContent(tmxStr);
return 1;
} catch (SQLException e) {
LOGGER.error(Messages.getString("service.DatabaseService.logger4") + dbOp.getMetaData().getDatabaseName(), e);
return ImportAbstract.FAILURE_3;
} catch (ClassNotFoundException e) {
LOGGER.error(Messages.getString("service.DatabaseService.logger5"), e);
return ImportAbstract.FAILURE_3;
} finally {
if (dbOp != null) {
try {
dbOp.end();
} catch (SQLException e) {
LOGGER.error(Messages.getString("service.DatabaseService.logger6"), e);
}
}
}
}
return ImportAbstract.FAILURE;
}
Aggregations