Search in sources :

Example 96 with AutoPilot

use of com.ximpleware.AutoPilot in project translationstudio8 by heartsome.

the class QAXmlHandler method getTUTag.

/**
	 * 获取trans-unit节点下source与target节点的标记信息,如果节点不存在,或者为空,则返回null
	 * @param xlfPath
	 * @param nodeXPath
	 * @return
	 */
public List<Map<String, String>> getTUTag(String xlfPath, String nodeXPath) {
    VTDNav vn = vnMap.get(xlfPath);
    Assert.isNotNull(vn, Messages.getString("qa.QAXmlHandler.msg1") + xlfPath);
    try {
        AutoPilot ap = apMap.get(xlfPath);
        VTDUtils vUtils = new VTDUtils(vn);
        ap.selectXPath(nodeXPath);
        while (ap.evalXPath() != -1) {
            String nodeContent = vUtils.getElementContent();
            if (nodeContent == null || "".equals(nodeContent)) {
                return null;
            }
            //开始获取所有的标记
            return getTUTag(vn);
        }
    } catch (Exception e) {
        e.printStackTrace();
        logger.error(Messages.getString("qa.QAXmlHandler.logger18"), e);
    }
    return null;
}
Also used : VTDUtils(net.heartsome.xml.vtdimpl.VTDUtils) AutoPilot(com.ximpleware.AutoPilot) VTDNav(com.ximpleware.VTDNav) NavException(com.ximpleware.NavException) CoreException(org.eclipse.core.runtime.CoreException) TranscodeException(com.ximpleware.TranscodeException) XPathEvalException(com.ximpleware.XPathEvalException) XPathParseException(com.ximpleware.XPathParseException) IOException(java.io.IOException) ModifyException(com.ximpleware.ModifyException)

Example 97 with AutoPilot

use of com.ximpleware.AutoPilot in project translationstudio8 by heartsome.

the class QAXmlHandler method getNodePureText.

/**
	 * 获取一个节点的纯文本,将所有的标记除外,包括标记里面的内容
	 * @return
	 */
public String getNodePureText(String xlfPath, String nodeXpath) {
    String pureText = "";
    VTDNav vn = vnMap.get(xlfPath);
    AutoPilot ap = apMap.get(xlfPath);
    validNull(vn, ap, xlfPath);
    try {
        VTDUtils vUtils = new VTDUtils(vn);
        ap.selectXPath(nodeXpath);
        while (ap.evalXPath() != -1) {
            pureText = vUtils.getElementPureText();
        }
    } catch (Exception e) {
        e.printStackTrace();
        logger.error(Messages.getString("qa.QAXmlHandler.logger14"), e);
    }
    return pureText;
}
Also used : VTDUtils(net.heartsome.xml.vtdimpl.VTDUtils) AutoPilot(com.ximpleware.AutoPilot) VTDNav(com.ximpleware.VTDNav) NavException(com.ximpleware.NavException) CoreException(org.eclipse.core.runtime.CoreException) TranscodeException(com.ximpleware.TranscodeException) XPathEvalException(com.ximpleware.XPathEvalException) XPathParseException(com.ximpleware.XPathParseException) IOException(java.io.IOException) ModifyException(com.ximpleware.ModifyException)

Example 98 with AutoPilot

use of com.ximpleware.AutoPilot in project translationstudio8 by heartsome.

the class QAXmlHandler method getHunspellAvailableLang.

/**
	 * 获取 hunspell 所支持的语言	2013-01-15
	 * @param xmlPath
	 * @return
	 */
public Map<String, String> getHunspellAvailableLang(String xmlPath) {
    Map<String, String> langMap = new HashMap<String, String>();
    VTDGen vg = new VTDGen();
    if (!vg.parseFile(xmlPath, true)) {
        logger.error("Hunspell 语言管理文件破损,无法解析。");
        return null;
    }
    VTDNav vn = vg.getNav();
    AutoPilot ap = new AutoPilot(vn);
    AutoPilot childAP = new AutoPilot(vn);
    String xpath = "/config/language";
    try {
        ap.selectXPath(xpath);
        while (ap.evalXPath() != -1) {
            String code = null;
            String dictionary = null;
            vn.push();
            childAP.selectXPath("./isoCode");
            if (childAP.evalXPath() != -1) {
                if (vn.getText() != -1) {
                    code = vn.toRawString(vn.getText());
                }
            }
            vn.pop();
            vn.push();
            childAP.selectXPath("./dict");
            if (childAP.evalXPath() != -1) {
                if (vn.getText() != -1) {
                    dictionary = vn.toRawString(vn.getText());
                }
            }
            vn.pop();
            if (code != null && dictionary != null && !"".equals(code) && !"".equals(dictionary)) {
                langMap.put(code, dictionary);
            }
        }
    } catch (Exception e) {
        logger.error("Hunspell 语言管理文件内容获取失败!", e);
    }
    return langMap;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) AutoPilot(com.ximpleware.AutoPilot) VTDGen(com.ximpleware.VTDGen) VTDNav(com.ximpleware.VTDNav) NavException(com.ximpleware.NavException) CoreException(org.eclipse.core.runtime.CoreException) TranscodeException(com.ximpleware.TranscodeException) XPathEvalException(com.ximpleware.XPathEvalException) XPathParseException(com.ximpleware.XPathParseException) IOException(java.io.IOException) ModifyException(com.ximpleware.ModifyException)

Example 99 with AutoPilot

use of com.ximpleware.AutoPilot in project translationstudio8 by heartsome.

the class QAXmlHandler method getEditProgressData.

/**
	 * 针对文件分析的翻译进度分析,获取每个节点的未翻译文本段数、字数,已翻译文本段数、字数。
	 * 如果返回为null,则标志用户退出分析
	 * @param filePath		要处理的文件的路径
	 * @param monitor		进度条
	 * @param ignoreTag		是否忽略标记
	 * @param workInterval	进度条前进一格的间隔
	 * @param traversalTuIndex	循环trans-unit节点的序列号
	 * @return	editProgDataMap,下面是其健值对详解
	 * key: notApprovedParas --> 未批准文本段数
	 * key: approvedParas --> 已批准文本段数
	 * key: notApprovedWords --> 未批准字数
	 * key: approvedWords --> 已批准字数
	 */
public Map<String, Integer> getEditProgressData(String filePath, IProgressMonitor monitor, int workInterval, int traversalTuIndex) {
    Map<String, Integer> editProgDataMap = new HashMap<String, Integer>();
    int notApprovedParas = 0;
    int approvedParas = 0;
    int lockedParas = 0;
    int notApprovedWords = 0;
    int approvedWords = 0;
    int lockedWords = 0;
    try {
        VTDNav vn = vnMap.get(filePath);
        Assert.isNotNull(vn, Messages.getString("qa.QAXmlHandler.msg1") + filePath);
        AutoPilot ap = new AutoPilot(vn);
        VTDUtils vUtils = new VTDUtils(vn);
        AutoPilot sourceAp = new AutoPilot(vn);
        sourceAp.selectXPath("./source[text()!='' or ./*]");
        String srcLang = vUtils.getElementAttribute("/xliff/file[1]", "source-language");
        ap.selectXPath(XPATH_ALL_TU);
        while (ap.evalXPath() != -1) {
            traversalTuIndex++;
            int curWordsNum = 0;
            //判断是否锁定
            boolean isLocked = false;
            int inx = vn.getAttrVal("translate");
            if (inx != -1 && "no".equals(vn.toString(inx))) {
                isLocked = true;
            }
            //根据是否忽略标记,获取源文本的字数
            vn.push();
            if (sourceAp.evalXPath() != -1) {
                String sourceText = getTUPureText(vn);
                curWordsNum = CountWord.wordCount(sourceText, srcLang);
            }
            sourceAp.resetXPath();
            vn.pop();
            String approved = "";
            int approveIndex = vn.getAttrVal("approved");
            if (approveIndex != -1) {
                approved = vn.toString(approveIndex);
            }
            if ("yes".equals(approved)) {
                approvedParas++;
                approvedWords += curWordsNum;
            } else {
                notApprovedParas++;
                notApprovedWords += curWordsNum;
            }
            if (!monitorWork(monitor, traversalTuIndex, workInterval, false)) {
                return null;
            }
            if (isLocked) {
                lockedParas++;
                lockedWords += curWordsNum;
            }
        }
    } catch (Exception e) {
        if (!monitorWork(monitor, traversalTuIndex, workInterval, false)) {
            return null;
        }
        e.printStackTrace();
        logger.error(MessageFormat.format(Messages.getString("qa.QAXmlHandler.logger24"), filePath), e);
    }
    editProgDataMap.put("notApprovedParas", notApprovedParas);
    editProgDataMap.put("approvedParas", approvedParas);
    editProgDataMap.put("lockedParas", lockedParas);
    editProgDataMap.put("notApprovedWords", notApprovedWords);
    editProgDataMap.put("approvedWords", approvedWords);
    editProgDataMap.put("lockedWords", lockedWords);
    return editProgDataMap;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) VTDUtils(net.heartsome.xml.vtdimpl.VTDUtils) AutoPilot(com.ximpleware.AutoPilot) VTDNav(com.ximpleware.VTDNav) NavException(com.ximpleware.NavException) CoreException(org.eclipse.core.runtime.CoreException) TranscodeException(com.ximpleware.TranscodeException) XPathEvalException(com.ximpleware.XPathEvalException) XPathParseException(com.ximpleware.XPathParseException) IOException(java.io.IOException) ModifyException(com.ximpleware.ModifyException)

Example 100 with AutoPilot

use of com.ximpleware.AutoPilot in project translationstudio8 by heartsome.

the class XLFHandler method getFileCountInXliff.

/**
	 * 得到 File 节点个数(此方法仅用于解析单个文件时)
	 * @return ;
	 */
public int getFileCountInXliff(String fileName) {
    VTDNav vn = vnMap.get(fileName);
    Assert.isNotNull(vn, Messages.getString("file.XLFHandler.msg4") + fileName);
    AutoPilot ap = new AutoPilot(vn);
    try {
        ap.selectXPath("count(/xliff/file)");
        // 整个 xliff 文件中的
        int countAllFile = (int) ap.evalXPathToNumber();
        // file 节点的个数
        return countAllFile;
    } catch (XPathParseException e) {
        LOGGER.error("", e);
        e.printStackTrace();
    }
    return -1;
}
Also used : XPathParseException(com.ximpleware.XPathParseException) AutoPilot(com.ximpleware.AutoPilot) VTDNav(com.ximpleware.VTDNav)

Aggregations

AutoPilot (com.ximpleware.AutoPilot)308 VTDNav (com.ximpleware.VTDNav)173 NavException (com.ximpleware.NavException)150 XPathParseException (com.ximpleware.XPathParseException)145 XPathEvalException (com.ximpleware.XPathEvalException)137 VTDUtils (net.heartsome.xml.vtdimpl.VTDUtils)112 IOException (java.io.IOException)103 ModifyException (com.ximpleware.ModifyException)95 TranscodeException (com.ximpleware.TranscodeException)82 CoreException (org.eclipse.core.runtime.CoreException)76 UnsupportedEncodingException (java.io.UnsupportedEncodingException)58 VTDGen (com.ximpleware.VTDGen)50 FileNotFoundException (java.io.FileNotFoundException)49 XMLModifier (com.ximpleware.XMLModifier)46 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)44 ArrayList (java.util.ArrayList)42 HashMap (java.util.HashMap)39 XQException (javax.xml.xquery.XQException)37 LinkedHashMap (java.util.LinkedHashMap)34 LinkedList (java.util.LinkedList)25