Search in sources :

Example 11 with ImportException

use of net.heartsome.cat.common.core.exception.ImportException in project translationstudio8 by heartsome.

the class TermDbManagerImportWizardTbxPage 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.TermDbManagerImportWizardTbxPage.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 (!resultMessage.toString().equals("")) {
        final String _message = resultMessage.toString();
        Display.getDefault().asyncExec(new Runnable() {

            public void run() {
                setErrorMessage(_message);
            }
        });
        throw new InterruptedException();
    }
    if (tbxResult != DatabaseService.SUCCESS) {
        if (tbxResult == DatabaseService.FAILURE_1) {
            resultMessage.append(Messages.getString("wizard.TermDbManagerImportWizardTbxPage.msg1"));
        } else if (tbxResult == DatabaseService.FAILURE_2) {
            resultMessage.append(Messages.getString("wizard.TermDbManagerImportWizardTbxPage.msg2"));
        } else if (tbxResult == DatabaseService.FAILURE_3) {
            resultMessage.append(Messages.getString("wizard.TermDbManagerImportWizardTbxPage.msg3"));
        } else if (tbxResult == DatabaseService.FAILURE_4) {
            resultMessage.append(Messages.getString("wizard.TermDbManagerImportWizardTbxPage.msg4"));
        } else if (tbxResult == DatabaseService.FAILURE) {
            resultMessage.append(Messages.getString("wizard.TermDbManagerImportWizardTbxPage.msg5"));
        } else if (tbxResult == DatabaseService.CANCEL) {
            resultMessage.append(Messages.getString("wizard.TermDbManagerImportWizardTbxPage.msg6"));
        }
        if (!resultMessage.toString().equals("")) {
            final String _message = resultMessage.toString();
            Display.getDefault().asyncExec(new Runnable() {

                public void run() {
                    setErrorMessage(_message);
                }
            });
        }
        throw new InterruptedException();
    } else {
        Display.getDefault().asyncExec(new Runnable() {

            public void run() {
                setErrorMessage(null);
                setMessage(Messages.getString("wizard.TermDbManagerImportWizardTbxPage.msg7"));
            }
        });
    }
    monitor.done();
}
Also used : ImportException(net.heartsome.cat.common.core.exception.ImportException) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor)

Example 12 with ImportException

use of net.heartsome.cat.common.core.exception.ImportException in project translationstudio8 by heartsome.

the class AddTermToTBDialog method okPressed.

@Override
protected void okPressed() {
    String srcTerm = cleanString(txtSrc.getText());
    String tgtTerm = cleanString(txtTgt.getText());
    if (srcTerm == null || srcTerm.equals("")) {
        MessageDialog.openInformation(getShell(), Messages.getString("dialog.AddTermToTBDialog.msgTitle"), Messages.getString("dialog.AddTermToTBDialog.msg1"));
        return;
    }
    if (tgtTerm == null || tgtTerm.equals("")) {
        MessageDialog.openInformation(getShell(), Messages.getString("dialog.AddTermToTBDialog.msgTitle"), Messages.getString("dialog.AddTermToTBDialog.msg2"));
        return;
    }
    // 添加空格不可入库的判断,--robert 2012-11-19
    if (srcTerm.length() > 0 && srcTerm.trim().equals("")) {
        MessageDialog.openInformation(getShell(), Messages.getString("dialog.AddTermToTBDialog.msgTitle"), Messages.getString("dialog.AddTermToTBDialog.addTip1"));
        return;
    }
    if (tgtTerm.length() > 0 && tgtTerm.trim().equals("")) {
        MessageDialog.openInformation(getShell(), Messages.getString("dialog.AddTermToTBDialog.msgTitle"), Messages.getString("dialog.AddTermToTBDialog.addTip2"));
        return;
    }
    srcTerm = srcTerm.trim();
    tgtTerm = tgtTerm.trim();
    XLFHandler handler = new XLFHandler();
    IStructuredSelection srcSelected = (IStructuredSelection) cmbSrcLang.getSelection();
    Language srcSelectedLang = (Language) srcSelected.getFirstElement();
    String srcLang = srcSelectedLang.getCode();
    IStructuredSelection tgtSelection = (IStructuredSelection) cmbTgtLang.getSelection();
    Language tgtSelectedLang = (Language) tgtSelection.getFirstElement();
    String tgtLang = tgtSelectedLang.getCode();
    String strTBX = handler.generateTBXWithString(srcLang, tgtLang, srcTerm, tgtTerm, txtProperty.getText());
    TbImporter importer = TbImporter.getInstance();
    importer.setProject(project);
    int state = -1;
    try {
        if (TYPE == EDIT_TYPE) {
            if (null != this.dbOperator) {
                state = DatabaseService.importTbxWithString(strTBX, null, this.dbOperator, Constants.IMPORT_MODEL_ALWAYSADD, srcLang);
                if (state != 1) {
                    return;
                }
            }
        } else if (TYPE == ADD_TYPE) {
            state = importer.executeImport(strTBX, srcLang, null);
            if (state == ITbImporter.IMPORT_STATE_FAILED) {
                MessageDialog.openInformation(Display.getCurrent().getActiveShell(), Messages.getString("dialog.AddTermToTBDialog.msgTitle"), Messages.getString("dialog.AddTermToTBDialog.msg3"));
                importer.clearResources();
                return;
            }
        }
    } catch (ImportException e) {
        final String msg = e.getMessage();
        Display.getDefault().syncExec(new Runnable() {

            public void run() {
                MessageDialog.openInformation(Display.getDefault().getActiveShell(), Messages.getString("dialog.AddTermToTBDialog.msgTitle"), msg);
            }
        });
        return;
    }
    importer.clearResources();
    TerminologyViewPart view = (TerminologyViewPart) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(TerminologyViewPart.ID);
    if (view != null) {
        view.refresh();
    }
    setReturnCode(OK);
    if (TYPE == ADD_TYPE) {
        try {
            project.refreshLocal(IResource.DEPTH_INFINITE, null);
        } catch (CoreException e) {
            LOGGER.error("", e);
        }
    }
    close();
}
Also used : ImportException(net.heartsome.cat.common.core.exception.ImportException) Language(net.heartsome.cat.common.locale.Language) CoreException(org.eclipse.core.runtime.CoreException) TbImporter(net.heartsome.cat.ts.tb.importer.TbImporter) ITbImporter(net.heartsome.cat.ts.tb.importer.extension.ITbImporter) TerminologyViewPart(net.heartsome.cat.ts.ui.term.view.TerminologyViewPart) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) XLFHandler(net.heartsome.cat.ts.core.file.XLFHandler)

Example 13 with ImportException

use of net.heartsome.cat.common.core.exception.ImportException in project translationstudio8 by heartsome.

the class ImportTmxPage 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.ImportTmxPage.task1"));
    int tmxResult = -10;
    StringBuffer resultMessage = new StringBuffer();
    String message = "";
    if (tmxFile != 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();
        }
    }
    if (tmxResult != DatabaseService.SUCCESS) {
        if (tmxResult == DatabaseService.FAILURE_1) {
            resultMessage.append(Messages.getString("wizard.ImportTmxPage.msg1"));
        } else if (tmxResult == DatabaseService.FAILURE_2) {
            resultMessage.append(Messages.getString("wizard.ImportTmxPage.msg2"));
        } else if (tmxResult == DatabaseService.FAILURE_3) {
            resultMessage.append(Messages.getString("wizard.ImportTmxPage.msg3"));
        } else if (tmxResult == DatabaseService.FAILURE_4) {
            resultMessage.append(Messages.getString("wizard.ImportTmxPage.msg4"));
        } else if (tmxResult == DatabaseService.FAILURE) {
            resultMessage.append(Messages.getString("wizard.ImportTmxPage.msg5"));
        } else if (tmxResult == DatabaseService.CANCEL) {
            resultMessage.append(Messages.getString("wizard.ImportTmxPage.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 14 with ImportException

use of net.heartsome.cat.common.core.exception.ImportException in project translationstudio8 by heartsome.

the class ConverterUtil method convert2Tbx.

public static File convert2Tbx(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(".tbx")) {
        return null;
    }
    AbstractConverter conveter = ConverterFactory.getFile2TbxConverter(fileName);
    if (null == conveter) {
        return null;
    }
    File createTempFile = null;
    boolean hasError = true;
    monitor.beginTask("", 1);
    try {
        createTempFile = File.createTempFile("Tbx_", "" + System.currentTimeMillis() + ".tbx");
        conveter.doConvert(createTempFile.getAbsolutePath(), new SubProgressMonitor(monitor, 1));
        hasError = false;
    } catch (OperationCanceledException e) {
        throw e;
    } 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();
        }
        monitor.done();
    }
    return createTempFile;
}
Also used : ImportException(net.heartsome.cat.common.core.exception.ImportException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) IOException(java.io.IOException) AbstractConverter(net.heartsome.cat.document.converter.AbstractConverter) 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)

Example 15 with ImportException

use of net.heartsome.cat.common.core.exception.ImportException 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;
}
Also used : ImportException(net.heartsome.cat.common.core.exception.ImportException) SQLException(java.sql.SQLException) SystemDBOperator(net.heartsome.cat.database.SystemDBOperator) DBOperator(net.heartsome.cat.database.DBOperator) File(java.io.File) ImportTmx(net.heartsome.cat.document.ImportTmx)

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