use of net.heartsome.cat.common.core.exception.ImportException in project translationstudio8 by heartsome.
the class NewTmDbImportPage method executeImport.
/**
* 执行导入
* @param tmxFile
* @param tbxFile
* @param dbMetaData
* @param monitor
* ;
*/
public void executeImport(String tmxFile, MetaData dbMetaData, IProgressMonitor monitor) {
if (monitor == null) {
monitor = new NullProgressMonitor();
}
monitor.setTaskName(Messages.getString("wizard.NewTmDbImportPage.task2"));
monitor.beginTask("", 100);
int tmxResult = -10;
String message = "";
if (tmxFile != null) {
try {
tmxResult = DatabaseService.importTmxWithFile(dbMetaData, tmxFile, new SubProgressMonitor(monitor, 100), getTmxImportStrategy(), isNeedCheckContext());
} catch (ImportException e) {
message = e.getMessage();
}
if (!message.equals("")) {
final String _message = message;
Display.getDefault().asyncExec(new Runnable() {
public void run() {
setErrorMessage(_message);
}
});
}
}
StringBuffer resultMessage = new StringBuffer();
if (tmxResult != DatabaseService.SUCCESS) {
if (tmxResult == DatabaseService.FAILURE_1) {
resultMessage.append(Messages.getString("wizard.NewTmDbImportPage.msg1"));
} else if (tmxResult == DatabaseService.FAILURE_2) {
resultMessage.append(Messages.getString("wizard.NewTmDbImportPage.msg2"));
} else if (tmxResult == DatabaseService.FAILURE_3) {
resultMessage.append(Messages.getString("wizard.NewTmDbImportPage.msg3"));
} else if (tmxResult == DatabaseService.FAILURE_4) {
resultMessage.append(Messages.getString("wizard.NewTmDbImportPage.msg4"));
} else if (tmxResult == DatabaseService.FAILURE) {
resultMessage.append(Messages.getString("wizard.NewTmDbImportPage.msg5"));
} else if (tmxResult == DatabaseService.CANCEL) {
resultMessage.append(Messages.getString("wizard.NewTmDbImportPage.msg6"));
}
if (!resultMessage.toString().equals("")) {
final String _message = resultMessage.toString();
Display.getDefault().asyncExec(new Runnable() {
public void run() {
setErrorMessage(_message);
}
});
}
}
monitor.done();
}
use of net.heartsome.cat.common.core.exception.ImportException in project translationstudio8 by heartsome.
the class TmDbManagerImportWizardTmxPage method executeImport.
/**
* 执行导入
* @param tmxFile
* @param tbxFile
* @param dbMetaData
* @param monitor
* ;
* @throws InterruptedException
*/
public void executeImport(String tmxFile, IProgressMonitor monitor) throws InterruptedException {
if (monitor == null) {
monitor = new NullProgressMonitor();
}
monitor.beginTask("", 100);
monitor.setTaskName(Messages.getString("wizard.TmDbManagerImportWizardTmxPage.task1"));
int tmxResult = -10;
String message = "";
if (tmxFile != null && dbModel != null) {
try {
tmxResult = DatabaseService.importTmxWithFile(dbModel.toDbMetaData(), tmxFile, new SubProgressMonitor(monitor, 100), getTmxImportStrategy(), isNeedCheckContext());
} catch (ImportException e) {
message = e.getMessage();
}
if (!message.equals("")) {
final String _message = message;
Display.getDefault().asyncExec(new Runnable() {
public void run() {
setErrorMessage(_message);
}
});
throw new InterruptedException();
}
}
StringBuffer resultMessage = new StringBuffer();
if (tmxResult != DatabaseService.SUCCESS) {
if (tmxResult == DatabaseService.FAILURE_1) {
resultMessage.append(Messages.getString("wizard.TmDbManagerImportWizardTmxPage.msg1"));
} else if (tmxResult == DatabaseService.FAILURE_2) {
resultMessage.append(Messages.getString("wizard.TmDbManagerImportWizardTmxPage.msg2"));
} else if (tmxResult == DatabaseService.FAILURE_3) {
resultMessage.append(Messages.getString("wizard.TmDbManagerImportWizardTmxPage.msg3"));
} else if (tmxResult == DatabaseService.FAILURE_4) {
resultMessage.append(Messages.getString("wizard.TmDbManagerImportWizardTmxPage.msg4"));
} else if (tmxResult == DatabaseService.FAILURE) {
resultMessage.append(Messages.getString("wizard.TmDbManagerImportWizardTmxPage.msg5"));
} else if (tmxResult == DatabaseService.CANCEL) {
resultMessage.append(Messages.getString("wizard.TmDbManagerImportWizardTmxPage.msg6"));
}
if (!resultMessage.toString().equals("")) {
final String _message = resultMessage.toString();
Display.getDefault().asyncExec(new Runnable() {
public void run() {
setErrorMessage(_message);
}
});
}
throw new InterruptedException();
}
monitor.done();
}
use of net.heartsome.cat.common.core.exception.ImportException in project translationstudio8 by heartsome.
the class UpdateTMWizard method performFinish.
public boolean performFinish() {
final IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
final boolean isDraft = page.isDraft();
final boolean isApproved = page.isApproved();
final boolean isSignedOff = page.isSignedOff();
final boolean isTranslated = page.isTranslated();
final boolean isLocked = page.isLocked();
if (!isDraft && !isApproved && !isSignedOff && !isTranslated && !isLocked) {
MessageDialog.openInformation(getShell(), Messages.getString("wizard.UpdateTMWizard.msgTitle"), Messages.getString("wizard.UpdateTMWizard.msg"));
return false;
}
IPreferenceStore ps = Activator.getDefault().getPreferenceStore();
final int contextSize = ps.getInt(TMPreferenceConstants.CONTEXT_MATCH);
final int tmxImportStrategy = ps.getInt(TMPreferenceConstants.TM_UPDATE);
IRunnableWithProgress progress = new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) {
monitor.setTaskName(Messages.getString("dialog.UpdateTMDialog.jobTask1"));
monitor.beginTask(Messages.getString("dialog.UpdateTMDialog.jobTask1"), lstXLIFF.size() * 2);
for (final IFile xliffFile : lstXLIFF) {
ProjectConfiger projectConfig = ProjectConfigerFactory.getProjectConfiger(xliffFile.getProject());
DatabaseModelBean modelBean = projectConfig.getDefaultTMDb();
FileEditorInput editorInput = new FileEditorInput(xliffFile);
IEditorPart editorPart = activePage.findEditor(editorInput);
// 选择所有语言
XLFHandler handler = null;
if (editorPart != null && editorPart instanceof IXliffEditor) {
// xliff 文件已用 XLIFF 编辑器打开
IXliffEditor xliffEditor = (IXliffEditor) editorPart;
handler = xliffEditor.getXLFHandler();
} else {
// xliff 文件未打开
handler = new XLFHandler();
}
monitor.subTask(Messages.getString("dialog.UpdateTMDialog.jobTask2"));
// 修改获取系统用户方式/*System.getProperty("user.name");*/
String systemUser = PlatformUI.getPreferenceStore().getString(IPreferenceConstants.SYSTEM_USER);
String[] arrTempTMX = handler.generateTMXToUpdateTM(xliffFile, isApproved, isSignedOff, isTranslated, isDraft, isLocked, contextSize, systemUser);
monitor.worked(1);
if (arrTempTMX != null) {
monitor.subTask(Messages.getString("dialog.UpdateTMDialog.jobTask3"));
// }
try {
DatabaseService.importTmxWithString(modelBean.toDbMetaData(), arrTempTMX[1], new SubProgressMonitor(monitor, 1), tmxImportStrategy, false, arrTempTMX[0]);
} catch (ImportException e) {
final String msg = e.getMessage();
Display.getDefault().syncExec(new Runnable() {
public void run() {
MessageDialog.openInformation(getShell(), Messages.getString("dialog.UpdateTMDialog.job.msgTitle"), msg);
}
});
canFinish = false;
return;
}
}
}
monitor.done();
// 刷新项目
ResourceUtils.refreshCurentSelectProject();
canFinish = true;
}
};
try {
getContainer().run(true, true, progress);
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
return canFinish;
}
use of net.heartsome.cat.common.core.exception.ImportException in project translationstudio8 by heartsome.
the class ImportAbstract method doImport.
/**
* 导入文件内容
* @param fileContent
* @param srcLang
* @param monitor
* @return ;
* @throws ImportException
*/
public int doImport(String fileContent, String srcLang, IProgressMonitor monitor) throws ImportException {
if (monitor == null) {
this.monitor = new NullProgressMonitor();
} else {
this.monitor = monitor;
}
// 解析文件
String message = "";
VTDGen vg = new VTDGen();
vg.setDoc(fileContent.getBytes());
try {
vg.parse(true);
} catch (EncodingException e) {
logger.error(Messages.getString("document.ImportAbstract.logger1"), e);
message = Messages.getString("document.ImportAbstract.msg1");
throw new ImportException(message + e.getMessage());
} catch (EOFException e) {
logger.error("", e);
message = Messages.getString("document.ImportAbstract.tbx.msg1");
throw new ImportException(message + e.getMessage());
} catch (EntityException e) {
logger.error("", e);
message = Messages.getString("document.ImportAbstract.tbx.msg1");
throw new ImportException(message + e.getMessage());
} catch (ParseException e) {
logger.error(Messages.getString("document.ImportAbstract.logger3"), e);
String errMsg = e.getMessage();
if (errMsg.indexOf("invalid encoding") != -1) {
// 编码异常
message = Messages.getString("document.ImportAbstract.msg1");
} else {
message = Messages.getString("document.ImportAbstract.tbx.msg1");
}
throw new ImportException(message + e.getMessage());
}
try {
// 构建VTD解析工具
vu = new VTDUtils(vg.getNav());
dbOperator.beginTransaction();
// 执行导入
executeImport(srcLang);
dbOperator.commit();
} catch (VTDException e) {
logger.error("", e);
try {
dbOperator.rollBack();
} catch (SQLException e1) {
logger.error("", e);
}
return FAILURE_4;
} catch (SQLException e) {
logger.error("", e);
try {
dbOperator.rollBack();
} catch (SQLException e1) {
logger.error("", e1);
}
throw new ImportException(Messages.getString("document.ImportAbstract.tbx.importDbError") + e.getMessage());
} catch (OperationCanceledException e) {
logger.error("", e);
try {
dbOperator.rollBack();
} catch (SQLException e1) {
logger.error("", e1);
return CANCEL;
}
} catch (Exception e) {
logger.error("", e);
try {
dbOperator.rollBack();
} catch (SQLException e1) {
logger.error("", e1);
}
throw new ImportException(Messages.getString("document.ImportAbstract.tbx.importDbError") + e.getMessage());
}
return SUCCESS;
}
use of net.heartsome.cat.common.core.exception.ImportException in project translationstudio8 by heartsome.
the class TbxImportWizardTbxPage method executeImport.
public void executeImport(String tbxFile, IProgressMonitor monitor) throws InterruptedException {
if (monitor == null) {
monitor = new NullProgressMonitor();
}
monitor.beginTask("", 100);
monitor.setTaskName(Messages.getString("wizard.TbxImportWizardTbxPage.task1"));
int tbxResult = -10;
String message = "";
try {
tbxResult = DatabaseService.importTbxWithFile(tbxFile, monitor, dbModel.toDbMetaData(), getTbxImportStrategy());
} catch (ImportException e) {
message = e.getMessage();
}
if (!message.equals("")) {
final String _message = message;
Display.getDefault().asyncExec(new Runnable() {
public void run() {
setErrorMessage(_message);
}
});
throw new InterruptedException();
}
StringBuffer resultMessage = new StringBuffer();
if (tbxResult != DatabaseService.SUCCESS) {
if (tbxResult == DatabaseService.FAILURE_1) {
resultMessage.append(Messages.getString("wizard.TbxImportWizardTbxPage.msg1"));
} else if (tbxResult == DatabaseService.FAILURE_2) {
resultMessage.append(Messages.getString("wizard.TbxImportWizardTbxPage.msg2"));
} else if (tbxResult == DatabaseService.FAILURE_3) {
resultMessage.append(Messages.getString("wizard.TbxImportWizardTbxPage.msg3"));
} else if (tbxResult == DatabaseService.FAILURE_4) {
resultMessage.append(Messages.getString("wizard.TbxImportWizardTbxPage.msg4"));
} else if (tbxResult == DatabaseService.FAILURE) {
resultMessage.append(Messages.getString("wizard.TbxImportWizardTbxPage.msg5"));
} else if (tbxResult == DatabaseService.CANCEL) {
resultMessage.append(Messages.getString("wizard.TbxImportWizardTbxPage.msg6"));
}
if (!resultMessage.toString().equals("")) {
final String _message = resultMessage.toString();
Display.getDefault().asyncExec(new Runnable() {
public void run() {
setErrorMessage(_message);
}
});
}
throw new InterruptedException();
}
monitor.done();
}
Aggregations