Search in sources :

Example 6 with ImportException

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();
}
Also used : ImportException(net.heartsome.cat.common.core.exception.ImportException) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Example 7 with ImportException

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();
}
Also used : ImportException(net.heartsome.cat.common.core.exception.ImportException) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Example 8 with ImportException

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;
}
Also used : IFile(org.eclipse.core.resources.IFile) DatabaseModelBean(net.heartsome.cat.common.bean.DatabaseModelBean) IEditorPart(org.eclipse.ui.IEditorPart) IXliffEditor(net.heartsome.cat.ts.ui.editors.IXliffEditor) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) ImportException(net.heartsome.cat.common.core.exception.ImportException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ProjectConfiger(net.heartsome.cat.ts.core.file.ProjectConfiger) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) XLFHandler(net.heartsome.cat.ts.core.file.XLFHandler)

Example 9 with ImportException

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;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) EncodingException(com.ximpleware.EncodingException) SQLException(java.sql.SQLException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) EntityException(com.ximpleware.EntityException) VTDGen(com.ximpleware.VTDGen) NavException(com.ximpleware.NavException) EncodingException(com.ximpleware.EncodingException) SQLException(java.sql.SQLException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) ImportException(net.heartsome.cat.common.core.exception.ImportException) TranscodeException(com.ximpleware.TranscodeException) XPathEvalException(com.ximpleware.XPathEvalException) EOFException(com.ximpleware.EOFException) XPathParseException(com.ximpleware.XPathParseException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) ModifyException(com.ximpleware.ModifyException) ParseException(com.ximpleware.ParseException) VTDException(com.ximpleware.VTDException) EntityException(com.ximpleware.EntityException) ImportException(net.heartsome.cat.common.core.exception.ImportException) VTDUtils(net.heartsome.xml.vtdimpl.VTDUtils) VTDException(com.ximpleware.VTDException) EOFException(com.ximpleware.EOFException) XPathParseException(com.ximpleware.XPathParseException) ParseException(com.ximpleware.ParseException)

Example 10 with ImportException

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();
}
Also used : ImportException(net.heartsome.cat.common.core.exception.ImportException) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor)

Aggregations

ImportException (net.heartsome.cat.common.core.exception.ImportException)19 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)8 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)7 File (java.io.File)5 IOException (java.io.IOException)4 SQLException (java.sql.SQLException)4 XLFHandler (net.heartsome.cat.ts.core.file.XLFHandler)4 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)4 FileNotFoundException (java.io.FileNotFoundException)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Entry (java.util.Map.Entry)2 DBOperator (net.heartsome.cat.database.DBOperator)2 SystemDBOperator (net.heartsome.cat.database.SystemDBOperator)2 AutomaticQATrigger (net.heartsome.cat.ts.ui.xliffeditor.nattable.qa.AutomaticQATrigger)2 IProject (org.eclipse.core.resources.IProject)2 EOFException (com.ximpleware.EOFException)1 EncodingException (com.ximpleware.EncodingException)1 EntityException (com.ximpleware.EntityException)1 ModifyException (com.ximpleware.ModifyException)1