use of net.heartsome.cat.ts.core.qa.QAXmlHandler 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();
}
use of net.heartsome.cat.ts.core.qa.QAXmlHandler in project translationstudio8 by heartsome.
the class SpellPage method initProperty.
private void initProperty() {
xmlHandler = new QAXmlHandler();
Map<String, Object> openResultMap = xmlHandler.openFile(configFilePath);
if (openResultMap != null && QAConstant.RETURNVALUE_RESULT_RETURN.equals(openResultMap.get(QAConstant.RETURNVALUE_RESULT))) {
return;
}
if (openResultMap == null || QAConstant.RETURNVALUE_RESULT_SUCCESSFUL != (Integer) openResultMap.get(QAConstant.RETURNVALUE_RESULT)) {
// 针对文件解析出错
boolean response = MessageDialog.openConfirm(getShell(), Messages.getString("qa.all.dialog.info"), Messages.getString("qa.preference.SpellPage.aspellLogCheck"));
if (response) {
checkAspellConfigureFile();
} else {
return;
}
}
String commandPath = xmlHandler.getNodeText(configFilePath, "/aspell/commandLine", "");
txtCommandPath.setText(commandPath == null ? "" : commandPath);
cmbDefaultDic.getCombo().setItems(getDictionaries(commandPath));
cmbDefaultDic.getCombo().select(0);
String utf8 = xmlHandler.getNodeText(configFilePath, "/aspell/utf8", "");
btnUTF8.setSelection(utf8 != null && utf8.equals("yes"));
List<String[]> aspellDicList = null;
try {
aspellDicList = xmlHandler.getAspellDicConfig(configFilePath);
addLangAndDicToTable(aspellDicList);
} catch (Exception e) {
LOGGER.error(Messages.getString("qa.preference.SpellPage.LOG4"), e);
}
}
Aggregations