Search in sources :

Example 1 with QATUDataBean

use of net.heartsome.cat.ts.core.qa.QATUDataBean in project translationstudio8 by heartsome.

the class XLFHandler method getAutoQAFilteredTUText.

/**
	 * 针对自动品质检查,根据rowId获取当前tu节点的所有过滤后的数据,过滤条件为不包括上下文匹配,不包括完全匹配,不包括已锁文本,过滤条件在首选项中设置.包括源文本,源纯文本,目标文本,目标纯文本,源语言,目标语言 robert
	 * 2011-02-14
	 * @return ;
	 */
public QATUDataBean getAutoQAFilteredTUText(String rowId, Map<String, Boolean> filterMap) {
    QATUDataBean tuDataBean = new QATUDataBean();
    VTDNav vn = getVTDNavByRowId(rowId).duplicateNav();
    String tuXpath = RowIdUtil.parseRowIdToXPath(rowId);
    Assert.isNotNull(vn, Messages.getString("file.XLFHandler.msg4") + RowIdUtil.getFileNameByRowId(rowId));
    try {
        AutoPilot ap = new AutoPilot(vn);
        AutoPilot childAp = new AutoPilot(vn);
        AutoPilot langAp = new AutoPilot(vn);
        VTDUtils vUtils = new VTDUtils(vn);
        ap.selectXPath(tuXpath);
        if (ap.evalXPath() != -1) {
            // 首先过滤,如果有不应包括的文本段,则返回一个空对象
            if (!filterTheTU(vn, filterMap)) {
                tuDataBean.setPassFilter(false);
                return tuDataBean;
            }
            vn.push();
            String srcLang = "";
            // 取出源文本的纯文本之前,先查看其内容是否为空,若为空,则返回null,没有source节点,也返回null
            childAp.selectXPath("./source");
            if (childAp.evalXPath() != -1) {
                // 因为标准里面只有一个source,因此此处用if不用while
                String srcContent = vUtils.getElementContent();
                // 如果源文本为空或无值,则返回null
                if (srcContent == null || "".equals(srcContent)) {
                    return null;
                } else {
                    tuDataBean.setSrcPureText(getTUPureText(vn));
                    tuDataBean.setSrcContent(srcContent);
                }
                // 获取源语言
                int langIdx;
                if ((langIdx = vn.getAttrVal("xml:lang")) != -1) {
                    srcLang = vn.toString(langIdx);
                } else {
                    // 若该节点没有源语言,那么向上去查找file节点的源语言
                    langAp.selectXPath("ancestor::file");
                    if (langAp.evalXPath() != -1) {
                        if ((langIdx = vn.getAttrVal("source-language")) != -1) {
                            srcLang = vn.toString(langIdx);
                        }
                        langAp.resetXPath();
                    }
                }
                tuDataBean.setSrcLang(srcLang);
            } else {
                return null;
            }
            childAp.resetXPath();
            vn.pop();
            // 下面获取目标文本的纯文本,在之前先检查目标文本是否为空或为空值,若是,则返回null,若没有target节点,也返回空
            childAp.selectXPath("./target");
            if (childAp.evalXPath() != -1) {
                // 因为标准里面只有一个target,因此此处用if不用while
                String tgtContent = vUtils.getElementContent();
                // 如果源文本为空或无值,则返回空对象
                if (tgtContent == null || "".equals(tgtContent)) {
                    return tuDataBean;
                } else {
                    tuDataBean.setTgtContent(tgtContent);
                    tuDataBean.setTgtPureText(getTUPureText(vn));
                }
                // 获取目标语言
                String tgtLang = "";
                int langIdx;
                if ((langIdx = vn.getAttrVal("xml:lang")) != -1) {
                    tgtLang = vn.toString(langIdx);
                } else {
                    // 若该节点没有源语言,那么向上去查找file节点的源语言
                    langAp.selectXPath("ancestor::file");
                    if (langAp.evalXPath() != -1) {
                        if ((langIdx = vn.getAttrVal("target-language")) != -1) {
                            tgtLang = vn.toString(langIdx);
                        }
                    }
                }
                tuDataBean.setTgtLang(tgtLang);
            } else {
                return tuDataBean;
            }
        }
    } catch (Exception e) {
        LOGGER.error("", e);
        e.printStackTrace();
    }
    return tuDataBean;
}
Also used : VTDUtils(net.heartsome.xml.vtdimpl.VTDUtils) QATUDataBean(net.heartsome.cat.ts.core.qa.QATUDataBean) AutoPilot(com.ximpleware.AutoPilot) VTDNav(com.ximpleware.VTDNav) NavException(com.ximpleware.NavException) CoreException(org.eclipse.core.runtime.CoreException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) XPathParseException(com.ximpleware.XPathParseException) FileNotFoundException(java.io.FileNotFoundException) XQException(javax.xml.xquery.XQException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) TranscodeException(com.ximpleware.TranscodeException) XPathEvalException(com.ximpleware.XPathEvalException) IOException(java.io.IOException) ModifyException(com.ximpleware.ModifyException)

Example 2 with QATUDataBean

use of net.heartsome.cat.ts.core.qa.QATUDataBean in project translationstudio8 by heartsome.

the class QualityAssurance method beginMultiFileQA.

/**
	 * 开始处理多个合并打开文件的品质检查,由于合并打开文件的处理,是个很特殊的例子,因为处理对像不再是单个文件,而是针对语言对。
	 * @param qaResult ;
	 */
public void beginMultiFileQA(final QAResult qaResult) {
    this.qaResult = qaResult;
    handler = new QAXmlHandler();
    Job job = new Job(Messages.getString("qa.all.qa")) {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            long time1 = System.currentTimeMillis();
            int fileNum = model.getQaXlfList().size();
            // 定义的进度条总共五格,其中,解析文件1格,进行检查9格
            monitor.beginTask(Messages.getString("qa.QualityAssurance.tip1"), fileNum * 10);
            //先将所有的文件进行解析
            if (!openFile(monitor)) {
                monitor.done();
                return Status.CANCEL_STATUS;
            }
            if (model.getQaXlfList().size() == 0) {
                MessageDialog.openInformation(shell, _INFO, Messages.getString("qa.QualityAssurance.tip2"));
                return Status.CANCEL_STATUS;
            }
            initWorkInterval();
            int allTUSize = handler.getAllTUSize();
            //遍历tu节点的序列号
            int traversalTuIndex = 0;
            IProgressMonitor subMonitor = new SubProgressMonitor(monitor, fileNum * 9, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK);
            subMonitor.beginTask("", allTUSize % workInterval == 0 ? (allTUSize / workInterval) : (allTUSize / workInterval) + 1);
            QARealization realization = null;
            Map<String, ArrayList<String>> languageList = handler.getLanguages();
            int lineNumber = 0;
            IFile iFile;
            for (Entry<String, ArrayList<String>> langEntry : languageList.entrySet()) {
                String srcLang = langEntry.getKey();
                for (String tgtLang : langEntry.getValue()) {
                    List<String> rowIdsList = handler.getAllRowIdsByLanguages(srcLang.toUpperCase(), tgtLang.toUpperCase());
                    model.setRowIdsList(rowIdsList);
                    //开始针对每一个文本段进行检查
                    for (String rowId : rowIdsList) {
                        traversalTuIndex++;
                        //行号
                        lineNumber = rowIdsList.indexOf(rowId) + 1;
                        String filePath = RowIdUtil.getFileNameByRowId(rowId);
                        iFile = ResourceUtils.fileToIFile(filePath);
                        String langPair = srcLang + Hyphen + tgtLang;
                        QATUDataBean tuDataBean = handler.getFilteredTUText(filePath, RowIdUtil.parseRowIdToXPath(rowId), model.getNotInclude());
                        if (tuDataBean == null) {
                            if (!monitorWork(subMonitor, traversalTuIndex, false)) {
                                closeDB();
                                return Status.CANCEL_STATUS;
                            }
                            continue;
                        }
                        if (!tuDataBean.isPassFilter()) {
                            if (!monitorWork(subMonitor, traversalTuIndex, false)) {
                                closeDB();
                                return Status.CANCEL_STATUS;
                            }
                            continue;
                        }
                        tuDataBean.setLineNumber(lineNumber + "");
                        tuDataBean.setFileName(iFile.getName());
                        tuDataBean.setSrcLang(srcLang);
                        tuDataBean.setTgtLang(tgtLang);
                        for (int i = 0; i < model.getBatchQAItemIdList().size(); i++) {
                            final String qaItemId = model.getBatchQAItemIdList().get(i);
                            realization = getClassInstance(qaItemId);
                            // 若没有该项检查的实例,提示出错
                            if (realization == null) {
                                Display.getDefault().asyncExec(new Runnable() {

                                    public void run() {
                                        MessageDialog.openError(shell, _ERROR, MessageFormat.format(Messages.getString("qa.QualityAssurance.tip4"), new Object[] { model.getQaItemId_Name_Class().get(qaItemId).get(QAConstant.QA_ITEM_NAME) }));
                                    }
                                });
                                closeDB();
                                return Status.CANCEL_STATUS;
                            }
                            // 开始进行该项文件的该项检查
                            final String result = realization.startQA(model, subMonitor, iFile, handler, tuDataBean);
                            // // 当未设置术语库、拼写检查词典配置 错误时才会返回 null,所以这时可以直接删。
                            if (result == null) {
                                model.getBatchQAItemIdList().remove(qaItemId);
                                i--;
                            }
                            if (monitor.isCanceled()) {
                                return Status.CANCEL_STATUS;
                            }
                        }
                        qaResult.sendDataToViewer(null);
                        if (!monitorWork(subMonitor, traversalTuIndex, false)) {
                            closeDB();
                            return Status.CANCEL_STATUS;
                        }
                    }
                }
                if (!monitorWork(subMonitor, traversalTuIndex, true)) {
                    closeDB();
                    return Status.CANCEL_STATUS;
                }
            }
            closeDB();
            qaResult.informQAEndFlag();
            subMonitor.done();
            monitor.done();
            System.out.println("所用时间为" + (System.currentTimeMillis() - time1));
            return Status.OK_STATUS;
        }
    };
    // 当程序退出时,检测当前 job 是否正常关闭
    CommonFunction.jobCantCancelTip(job);
    job.addJobChangeListener(new JobChangeAdapter() {

        @Override
        public void running(IJobChangeEvent event) {
            ProgressIndicatorManager.displayProgressIndicator();
            super.running(event);
        }

        @Override
        public void done(IJobChangeEvent event) {
            ProgressIndicatorManager.hideProgressIndicator();
            super.done(event);
        }
    });
    job.setUser(true);
    job.schedule();
}
Also used : IFile(org.eclipse.core.resources.IFile) QATUDataBean(net.heartsome.cat.ts.core.qa.QATUDataBean) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) QAXmlHandler(net.heartsome.cat.ts.core.qa.QAXmlHandler) ArrayList(java.util.ArrayList) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Job(org.eclipse.core.runtime.jobs.Job)

Example 3 with QATUDataBean

use of net.heartsome.cat.ts.core.qa.QATUDataBean in project translationstudio8 by heartsome.

the class AutomaticQA method autoQA.

public void autoQA(String rowId, StringBuffer resultSB, boolean isAddToDb) {
    iFile = root.getFileForLocation(Path.fromOSString(RowIdUtil.getFileNameByRowId(rowId)));
    //先通过rowId获取品质检查所需要的数据
    QATUDataBean tuDataBean = handler.getAutoQAFilteredTUText(rowId, filterMap);
    if (!tuDataBean.isPassFilter()) {
        return;
    }
    String lineNumber = "" + (handler.getRowIndex(rowId) + 1);
    tuDataBean.setLineNumber(lineNumber);
    tuDataBean.setRowId(rowId);
    tuDataBean.setFileName(iFile.getName());
    // 译文为空时,只有文本段完整性里面有检查,而,自动品质检查时已经翻译了的,因此不考虑此种情况
    if (tuDataBean.getTgtContent() == null || tuDataBean.getTgtContent().isEmpty()) {
        return;
    }
    resultSB.append(MessageFormat.format(Messages.getString("qa.AutomaticQATrigger.tip1"), new Object[] { lineNumber, isAddToDb ? Messages.getString("qa.AutomaticQATrigger.name1") : Messages.getString("qa.AutomaticQATrigger.name2") }));
    // 品质检查项的总数
    QARealization realization = null;
    boolean hasError = false;
    IProgressMonitor monitor = new NullProgressMonitor();
    for (int i = 0; i < model.getBatchQAItemIdList().size(); i++) {
        final String qaItemId = model.getBatchQAItemIdList().get(i);
        realization = getClassInstance(qaItemId, qaResult);
        // 若没有该项检查的实例,提示出错
        if (realization == null) {
            MessageDialog.openError(model.getShell(), Messages.getString("qa.AutomaticQATrigger.name3"), MessageFormat.format(Messages.getString("qa.AutomaticQATrigger.tip2"), new Object[] { model.getQaItemId_Name_Class().get(qaItemId).get(QAConstant.QA_ITEM_NAME) }));
        }
        // 开始进行该项文件的该项检查
        String result = realization.startQA(model, monitor, iFile, xmlHandler, tuDataBean);
        if (monitor.isCanceled()) {
            isCancel = true;
            return;
        }
        // 未配置术语库, 
        if (result == null) {
            model.getBatchQAItemIdList().remove(qaItemId);
            i--;
        }
        if (result != null && !"".equals(result)) {
            hasError = true;
            result = model.getQaItemId_Name_Class().get(result).get(QAConstant.QA_ITEM_NAME);
            resultSB.append("\t" + result).append(Messages.getString("qa.AutomaticQATrigger.tip3")).append("\n");
        }
    }
    // 这一步很重要,将数据传送至结果视图
    qaResult.sendDataToViewer(tuDataBean.getRowId());
    if (!hasError) {
        resultSB.delete(0, resultSB.length());
    }
    monitor.done();
    return;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) QATUDataBean(net.heartsome.cat.ts.core.qa.QATUDataBean)

Example 4 with QATUDataBean

use of net.heartsome.cat.ts.core.qa.QATUDataBean in project translationstudio8 by heartsome.

the class NumberOrTagConsisQAHandler method beginQA.

private void beginQA(final ArrayList<IFile> selectIFiles, final QAModel model, final boolean isNumberQA, final QAResult qaResult) {
    final String titile = isNumberQA ? Messages.getString("qa.NumberOrTagConsisQAHandler.jobTitle1") : Messages.getString("qa.NumberOrTagConsisQAHandler.jobTitle2");
    Job job = new Job(titile) {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            // 解析一格,其余九格
            monitor.beginTask(titile, 10 * selectIFiles.size());
            xmlHandler = new QAXmlHandler();
            // 首先解析文件,如果为false,则退出
            if (!openFile(selectIFiles, monitor)) {
                return Status.OK_STATUS;
            }
            int allTUSize = 0;
            for (IFile iFile : selectIFiles) {
                allTUSize += xmlHandler.getTuSizeMap().get(iFile.getLocation().toOSString());
            }
            initWorkInterval(allTUSize);
            // 开始进行数据处理
            IProgressMonitor subMonitor = new SubProgressMonitor(monitor, 9, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK);
            subMonitor.beginTask(titile + "...", allTUSize % workInterval == 0 ? (allTUSize / workInterval) : (allTUSize / workInterval) + 1);
            Map<String, ArrayList<String>> languageList = xmlHandler.getLanguages();
            int lineNumber = 0;
            int traversalTuIndex = 0;
            IFile iFile;
            for (Entry<String, ArrayList<String>> langEntry : languageList.entrySet()) {
                String srcLang = langEntry.getKey();
                for (String tgtLang : langEntry.getValue()) {
                    List<String> rowIdsList = xmlHandler.getAllRowIdsByLanguages(srcLang.toUpperCase(), tgtLang.toUpperCase());
                    model.setRowIdsList(rowIdsList);
                    // 开始针对每一个文本段进行检查
                    for (String rowId : rowIdsList) {
                        traversalTuIndex++;
                        // 行号
                        lineNumber = rowIdsList.indexOf(rowId) + 1;
                        String filePath = RowIdUtil.getFileNameByRowId(rowId);
                        iFile = ResourceUtils.fileToIFile(filePath);
                        String langPair = srcLang + Hyphen + tgtLang;
                        QATUDataBean tuDataBean = xmlHandler.getFilteredTUText(filePath, RowIdUtil.parseRowIdToXPath(rowId), model.getNotInclude());
                        if (tuDataBean == null) {
                            if (!xmlHandler.monitorWork(subMonitor, traversalTuIndex, workInterval, false)) {
                                return Status.CANCEL_STATUS;
                            }
                            continue;
                        }
                        if (!tuDataBean.isPassFilter()) {
                            if (!xmlHandler.monitorWork(subMonitor, traversalTuIndex, workInterval, false)) {
                                return Status.CANCEL_STATUS;
                            }
                            continue;
                        } else if (tuDataBean.getTgtContent() == null || "".equals(tuDataBean.getTgtContent())) {
                            // 因为文本段完整性检查要判断译文是否为空的情况,所以,如果译文为空,只有文本段完整性要进行检查,其他检查项都跳过。
                            continue;
                        }
                        tuDataBean.setLineNumber(lineNumber + "");
                        tuDataBean.setFileName(iFile.getName());
                        tuDataBean.setSrcLang(srcLang);
                        tuDataBean.setTgtLang(tgtLang);
                        if (isNumberQA) {
                            NumberConsistenceQA numberQA = new NumberConsistenceQA();
                            qaResult.setMultiOper(model.getMultiOper());
                            numberQA.setQaResult(qaResult);
                            numberQA.startQA(model, subMonitor, iFile, xmlHandler, tuDataBean);
                        } else {
                            TagConsistenceQA tagQA = new TagConsistenceQA();
                            qaResult.setMultiOper(model.getMultiOper());
                            tagQA.setQaResult(qaResult);
                            tagQA.startQA(model, subMonitor, iFile, xmlHandler, tuDataBean);
                        }
                        qaResult.sendDataToViewer(null);
                        if (!xmlHandler.monitorWork(subMonitor, traversalTuIndex, workInterval, false)) {
                            return Status.CANCEL_STATUS;
                        }
                    }
                }
                if (!xmlHandler.monitorWork(subMonitor, traversalTuIndex, workInterval, false)) {
                    return Status.CANCEL_STATUS;
                }
            }
            qaResult.informQAEndFlag();
            subMonitor.done();
            monitor.done();
            return Status.OK_STATUS;
        }
    };
    // 当程序退出时,检测当前 job 是否正常关闭
    CommonFunction.jobCantCancelTip(job);
    job.addJobChangeListener(new JobChangeAdapter() {

        @Override
        public void running(IJobChangeEvent event) {
            ProgressIndicatorManager.displayProgressIndicator();
            super.running(event);
        }

        @Override
        public void done(IJobChangeEvent event) {
            ProgressIndicatorManager.hideProgressIndicator();
            super.done(event);
        }
    });
    job.setUser(true);
    job.schedule();
}
Also used : NumberConsistenceQA(net.heartsome.cat.ts.ui.qa.NumberConsistenceQA) IFile(org.eclipse.core.resources.IFile) QATUDataBean(net.heartsome.cat.ts.core.qa.QATUDataBean) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) QAXmlHandler(net.heartsome.cat.ts.core.qa.QAXmlHandler) ArrayList(java.util.ArrayList) TagConsistenceQA(net.heartsome.cat.ts.ui.qa.TagConsistenceQA) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Job(org.eclipse.core.runtime.jobs.Job)

Example 5 with QATUDataBean

use of net.heartsome.cat.ts.core.qa.QATUDataBean in project translationstudio8 by heartsome.

the class QualityAssurance method beginQA.

//------------------下面是优化品质检查的试用代码
public void beginQA(final QAResult qaResult) {
    this.qaResult = qaResult;
    handler = new QAXmlHandler();
    Job job = new Job(Messages.getString("qa.all.qa")) {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            long time1 = System.currentTimeMillis();
            // 品质检查项的总数
            int fileNum = model.getQaXlfList().size();
            // 定义的进度条总共五格,其中,解析文件一格,进行检查四格
            monitor.beginTask(Messages.getString("qa.QualityAssurance.tip1"), fileNum * 5);
            //先将所有的文件进行解析
            if (!openFile(monitor)) {
                monitor.done();
                return Status.CANCEL_STATUS;
            }
            if (model.getQaXlfList().size() == 0) {
                MessageDialog.openInformation(shell, _INFO, Messages.getString("qa.QualityAssurance.tip2"));
                return Status.CANCEL_STATUS;
            }
            initWorkInterval();
            QARealization realization = null;
            //先遍历每个文件
            for (int fileIndex = 0; fileIndex < model.getQaXlfList().size(); fileIndex++) {
                final IFile iFile = model.getQaXlfList().get(fileIndex);
                String xlfPath = iFile.getLocation().toOSString();
                String iFileFullPath = iFile.getFullPath().toOSString();
                IProgressMonitor subMonitor = new SubProgressMonitor(monitor, 4, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK);
                int allTuSum = handler.getNodeCount(xlfPath, "/xliff/file/body//trans-unit");
                subMonitor.beginTask("", allTuSum % workInterval == 0 ? (allTuSum / workInterval) : (allTuSum / workInterval) + 1);
                subMonitor.setTaskName(MessageFormat.format(Messages.getString("qa.QualityAssurance.tip3"), new Object[] { Messages.getString("qa.all.qa"), iFileFullPath }));
                int fileNodeSum = handler.getNodeCount(xlfPath, "/xliff/file");
                //行号
                int lineNumber = 0;
                //遍历tu节点的序列号
                int traversalTuIndex = 0;
                for (int fileNodeIdx = QAConstant.QA_FIRST; fileNodeIdx <= fileNodeSum; fileNodeIdx++) {
                    //获取语言对
                    String srcLang = handler.getNodeAttribute(xlfPath, "/xliff/file[" + fileNodeIdx + "]", "source-language");
                    String tgtLang = handler.getNodeAttribute(xlfPath, "/xliff/file[" + fileNodeIdx + "]", "target-language");
                    String langPair = srcLang + Hyphen + tgtLang;
                    int curFileTUNodeSum = handler.getNodeCount(xlfPath, "/xliff/file[" + fileNodeIdx + "]/body//trans-unit");
                    for (int tuIndex = QAConstant.QA_FIRST; tuIndex <= curFileTUNodeSum; tuIndex++) {
                        traversalTuIndex++;
                        String tuXpath = "/xliff/file[" + fileNodeIdx + "]/body/descendant::trans-unit[" + tuIndex + "]";
                        QATUDataBean dataBean = handler.getFilteredTUText(xlfPath, tuXpath, model.getNotInclude());
                        //如果返回的map为null,则进行下一循环,行号也不加自加,这样可以保持这里的行号与界面上的行号一致性,方便定位,出现这种情况的可能很小,因为 rowID 的过滤已经处理过了。
                        if (dataBean == null) {
                            if (!monitorWork(subMonitor, traversalTuIndex, false)) {
                                closeDB();
                                return Status.CANCEL_STATUS;
                            }
                            continue;
                        }
                        lineNumber++;
                        if (lineNumber == 73) {
                            System.out.println("开始处理。。。。");
                        }
                        // 未通过 过滤器过滤的情况,
                        if (!dataBean.isPassFilter()) {
                            if (!monitorWork(subMonitor, traversalTuIndex, false)) {
                                closeDB();
                                return Status.CANCEL_STATUS;
                            }
                            continue;
                        }
                        dataBean.setLineNumber(lineNumber + "");
                        dataBean.setFileName(iFile.getName());
                        dataBean.setSrcLang(srcLang);
                        dataBean.setTgtLang(tgtLang);
                        dataBean.setXlfPath(xlfPath);
                        for (int i = 0; i < model.getBatchQAItemIdList().size(); i++) {
                            final String qaItemId = model.getBatchQAItemIdList().get(i);
                            realization = getClassInstance(qaItemId);
                            // 若没有该项检查的实例,提示出错
                            if (realization == null) {
                                Display.getDefault().asyncExec(new Runnable() {

                                    public void run() {
                                        MessageDialog.openError(shell, _ERROR, MessageFormat.format(Messages.getString("qa.QualityAssurance.tip4"), new Object[] { model.getQaItemId_Name_Class().get(qaItemId).get(QAConstant.QA_ITEM_NAME) }));
                                    }
                                });
                                closeDB();
                                return Status.CANCEL_STATUS;
                            }
                            // 开始进行该项文件的该项检查
                            final String result = realization.startQA(model, subMonitor, iFile, handler, dataBean);
                            // 当未设置术语库、拼写检查词典配置 错误时才会返回 null,所以这时可以直接删。
                            if (result == null) {
                                model.getBatchQAItemIdList().remove(qaItemId);
                                i--;
                            }
                            if (monitor.isCanceled()) {
                                return Status.CANCEL_STATUS;
                            }
                        }
                        // UNDO 发现这里很耗时,需要处理。
                        qaResult.sendDataToViewer(null);
                        if (!monitorWork(subMonitor, traversalTuIndex, false)) {
                            closeDB();
                            return Status.CANCEL_STATUS;
                        }
                    }
                    if (!monitorWork(subMonitor, traversalTuIndex, true)) {
                        closeDB();
                        return Status.CANCEL_STATUS;
                    }
                }
                subMonitor.done();
            }
            closeDB();
            qaResult.informQAEndFlag();
            monitor.done();
            System.out.println("所用时间为" + (System.currentTimeMillis() - time1));
            return Status.OK_STATUS;
        }
    };
    // 当程序退出时,检测当前 job 是否正常关闭
    CommonFunction.jobCantCancelTip(job);
    job.addJobChangeListener(new JobChangeAdapter() {

        @Override
        public void running(IJobChangeEvent event) {
            ProgressIndicatorManager.displayProgressIndicator();
            super.running(event);
        }

        @Override
        public void done(IJobChangeEvent event) {
            ProgressIndicatorManager.hideProgressIndicator();
            super.done(event);
        }
    });
    job.setUser(true);
    job.schedule();
}
Also used : IFile(org.eclipse.core.resources.IFile) QATUDataBean(net.heartsome.cat.ts.core.qa.QATUDataBean) JobChangeAdapter(org.eclipse.core.runtime.jobs.JobChangeAdapter) QAXmlHandler(net.heartsome.cat.ts.core.qa.QAXmlHandler) IJobChangeEvent(org.eclipse.core.runtime.jobs.IJobChangeEvent) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Job(org.eclipse.core.runtime.jobs.Job)

Aggregations

QATUDataBean (net.heartsome.cat.ts.core.qa.QATUDataBean)5 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)4 QAXmlHandler (net.heartsome.cat.ts.core.qa.QAXmlHandler)3 IFile (org.eclipse.core.resources.IFile)3 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)3 IJobChangeEvent (org.eclipse.core.runtime.jobs.IJobChangeEvent)3 Job (org.eclipse.core.runtime.jobs.Job)3 JobChangeAdapter (org.eclipse.core.runtime.jobs.JobChangeAdapter)3 ArrayList (java.util.ArrayList)2 AutoPilot (com.ximpleware.AutoPilot)1 ModifyException (com.ximpleware.ModifyException)1 NavException (com.ximpleware.NavException)1 TranscodeException (com.ximpleware.TranscodeException)1 VTDNav (com.ximpleware.VTDNav)1 XPathEvalException (com.ximpleware.XPathEvalException)1 XPathParseException (com.ximpleware.XPathParseException)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 XQException (javax.xml.xquery.XQException)1