Search in sources :

Example 91 with NullProgressMonitor

use of org.eclipse.core.runtime.NullProgressMonitor in project translationstudio8 by heartsome.

the class TestWord2007 method testSegDocument.

public void testSegDocument() {
    //		String inputFile = "/home/robert/Desktop/测试简单word文档.docx";
    //		String inputFile = "/home/robert/Desktop/Word2007 for test.docx";
    //		String xliffFile = "/home/robert/workspace/runtime-UltimateEdition.product/testDocxConverter/XLIFF/zh-CN/测试简单word文档.docx.hsxliff";
    //		String sourceLanguage = "en-US";
    //		String targetLanguage = "zh-CN";
    //		String srx = "/home/robert/workspace/newR8/.metadata/.plugins/org.eclipse.pde.core/UltimateEdition.product/net.heartsome.cat.converter/srx/default_rules.srx";
    //		String catalogue = "/home/robert/workspace/newR8/.metadata/.plugins/org.eclipse.pde.core/UltimateEdition.product/net.heartsome.cat.converter/catalogue/catalogue.xml";
    //		String docPath = "/home/robert/Desktop/document.xml";
    String inputFile = "C:\\Users\\Administrator\\Desktop\\test word 2007 converter\\测试简单word文档.docx";
    //		String inputFile = "C:\\Users\\Administrator\\Desktop\\test word 2007 converter\\Word2007 for test.docx";
    String xliffFile = "E:\\workspaces\\runtime-UltimateEdition.product\\testWord2007Convert\\XLIFF\\zh-CN\\测试简单word文档.docx.hsxliff";
    String sourceLanguage = "en-US";
    String targetLanguage = "zh-CN";
    String srx = "E:\\workspaces\\newR8\\.metadata\\.plugins\\org.eclipse.pde.core\\UltimateEdition.product\\net.heartsome.cat.converter\\srx\\default_rules.srx";
    String catalogue = "E:\\workspaces\\newR8\\.metadata\\.plugins\\org.eclipse.pde.core\\UltimateEdition.product\\net.heartsome.cat.converter\\catalogue\\catalogue.xml";
    String docPath = "C:\\Users\\Administrator\\Desktop\\document.xml";
    try {
        StringSegmenter segmenter = new StringSegmenter(srx, sourceLanguage, catalogue);
        // 定义一个 hsxliff 文件的写入方法
        xlfOutput = new XliffOutputer(xliffFile, sourceLanguage, targetLanguage);
        xlfOutput.writeHeader(inputFile, "skeletonFile", true, "UTF-8", "");
        // 先从主文档 document 文件入手
        DocumentPart docPart = new DocumentPart(docPath, null, xlfOutput, segmenter, inputFile, new NullProgressMonitor());
        docPart.testSegFile();
        System.out.println("--------------");
        xlfOutput.outputEndTag();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) DocumentPart(net.heartsome.cat.converter.word2007.partOper.DocumentPart) StringSegmenter(net.heartsome.cat.converter.StringSegmenter)

Example 92 with NullProgressMonitor

use of org.eclipse.core.runtime.NullProgressMonitor 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 93 with NullProgressMonitor

use of org.eclipse.core.runtime.NullProgressMonitor 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 94 with NullProgressMonitor

use of org.eclipse.core.runtime.NullProgressMonitor in project translationstudio8 by heartsome.

the class NewTmDbBaseInfoPage method checkDb4Server.

/**
	 * 检查服务器型数据库
	 * @return ;
	 */
public String checkDb4Server(IProgressMonitor monitor) {
    if (monitor == null) {
        monitor = new NullProgressMonitor();
    }
    monitor.beginTask("", 3);
    monitor.setTaskName(Messages.getString("wizard.NewTmDbBaseInfoPage.task1"));
    String message = null;
    if (!dbOp.checkDbConnection()) {
        message = Messages.getString("wizard.NewTmDbBaseInfoPage.msg7");
        return message;
    }
    if (!dbOp.checkSysDb()) {
        // 检查是否创建了系统库,没创建则创建
        try {
            dbOp.createSysDb();
        } catch (Exception e) {
            logger.error(Messages.getString("wizard.NewTmDbBaseInfoPage.logger1"));
            message = Messages.getString("wizard.NewTmDbBaseInfoPage.msg8");
            return message;
        }
    }
    monitor.worked(1);
    if (dbOp.checkDbExistOnServer()) {
        message = Messages.getString("wizard.NewTmDbBaseInfoPage.msg9");
        return message;
    }
    if (monitor.isCanceled()) {
        throw new OperationCanceledException();
    }
    monitor.done();
    return message;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) InvocationTargetException(java.lang.reflect.InvocationTargetException) SQLException(java.sql.SQLException)

Example 95 with NullProgressMonitor

use of org.eclipse.core.runtime.NullProgressMonitor in project translationstudio8 by heartsome.

the class NewTmDbBaseInfoPage method executeCreateDB.

/**
	 * 创建数据库
	 * @return ;
	 */
public String executeCreateDB(SystemDBOperator dbOp, IProgressMonitor monitor) {
    if (monitor == null) {
        monitor = new NullProgressMonitor();
    }
    monitor.beginTask("", 3);
    monitor.setTaskName(Messages.getString("wizard.NewTmDbBaseInfoPage.task2"));
    String message = null;
    try {
        if (Constants.FAILURE == dbOp.createDB()) {
            message = Messages.getString("wizard.NewTmDbBaseInfoPage.msg8");
        } else {
            if (!dbOp.getDBConfig().getDefaultType().equals(Constants.DBTYPE_SQLITE)) {
                // 更新系统库
                dbOp.updataSysDb(Constants.DB_TYPE_TM);
                // 处理本地服务器列表
                saveToServerConfigFile(dbOp);
            }
        }
        monitor.worked(3);
    } catch (SQLException e) {
        logger.error("", e);
        e.printStackTrace();
        message = Messages.getString("wizard.NewTmDbBaseInfoPage.msg10") + e.getMessage();
        return message;
    } finally {
        if (message != null) {
            final String _message = message;
            Display.getDefault().asyncExec(new Runnable() {

                public void run() {
                    setErrorMessage(_message);
                }
            });
        }
        monitor.done();
    }
    return message;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) SQLException(java.sql.SQLException)

Aggregations

NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1614 CoreException (org.eclipse.core.runtime.CoreException)416 Test (org.junit.Test)382 IFile (org.eclipse.core.resources.IFile)342 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)267 IProject (org.eclipse.core.resources.IProject)258 File (java.io.File)205 IPath (org.eclipse.core.runtime.IPath)182 IOException (java.io.IOException)153 Path (org.eclipse.core.runtime.Path)132 ArrayList (java.util.ArrayList)122 IStatus (org.eclipse.core.runtime.IStatus)113 IFolder (org.eclipse.core.resources.IFolder)87 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)69 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)63 InvocationTargetException (java.lang.reflect.InvocationTargetException)60 List (java.util.List)59 IProjectDescription (org.eclipse.core.resources.IProjectDescription)57 IType (org.eclipse.jdt.core.IType)57 Status (org.eclipse.core.runtime.Status)55