Search in sources :

Example 46 with VTDNav

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

the class QAXmlHandler method getNodeContent.

/**
	 * 获取指定文件的指定节点的内容(除节点头与尾之外)
	 * @param xlfPath
	 * @param nodeXpath
	 * @return
	 * robert	2011-10-26
	 */
public String getNodeContent(String xlfPath, String nodeXpath) {
    String nodeContent = "";
    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) {
            nodeContent = vUtils.getElementContent();
        }
    } catch (Exception e) {
        logger.error(Messages.getString("qa.QAXmlHandler.logger16"), e);
        e.printStackTrace();
    }
    return nodeContent;
}
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 47 with VTDNav

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

the class QAXmlHandler method getNonTransElementsRegex.

/**
	 * 只获取非译元素的正则表达式
	 * @param filePath
	 * @return
	 */
public List<String> getNonTransElementsRegex(String filePath) {
    List<String> regexList = new ArrayList<String>();
    VTDNav vn = vnMap.get(filePath);
    AutoPilot ap = new AutoPilot(vn);
    validNull(vn, ap, filePath);
    try {
        VTDUtils vUtils = new VTDUtils(vn);
        ap.selectXPath("/nonTrans/element/regular");
        while (ap.evalXPath() != -1) {
            regexList.add(vUtils.getElementContent());
        }
    } catch (Exception e) {
        e.printStackTrace();
        logger.error(Messages.getString("qa.QAXmlHandler.logger19"), e);
    }
    return regexList;
}
Also used : VTDUtils(net.heartsome.xml.vtdimpl.VTDUtils) AutoPilot(com.ximpleware.AutoPilot) ArrayList(java.util.ArrayList) 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 48 with VTDNav

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

the class QAXmlHandler method getFilteredTUTextForMultiParaConsis.

/**
	 * 针对合并打开的文本段一致性检查的情况,获取trans-unit节点过滤后的值,过滤条件为不包括上下文匹配,不包括完全匹配,不包括已锁文本,过滤条件在首选项中设置
	 * @param xlfPath	
	 * @param nodeXpath	
	 * @param filterMap	过滤条件
	 * @return ;
	 */
public Map<String, ParaConsisDataBean> getFilteredTUTextForMultiParaConsis(List<String> rowIdList, Map<String, Boolean> filterMap, boolean checkSameSource, boolean checkSameTarget, boolean srcIgnoreTag, boolean tarIgnoreTag) {
    Map<String, ParaConsisDataBean> filteredTuTextMap = new HashMap<String, ParaConsisDataBean>();
    try {
        //检查项有两个,即相同源文不同译文,相同译文不同源文,如果某项不检查,那么它的忽略标记为false
        if (!checkSameSource) {
            srcIgnoreTag = false;
        }
        if (!checkSameTarget) {
            tarIgnoreTag = false;
        }
        for (String rowId : rowIdList) {
            String xlfPath = RowIdUtil.getFileNameByRowId(rowId);
            VTDNav vn = vnMap.get(xlfPath);
            AutoPilot ap = new AutoPilot(vn);
            Assert.isNotNull(vn, Messages.getString("qa.QAXmlHandler.msg1") + xlfPath);
            AutoPilot childAp = new AutoPilot(vn);
            VTDUtils vUtils = new VTDUtils(vn);
            ap.selectXPath(RowIdUtil.parseRowIdToXPath(rowId));
            if (ap.evalXPath() != -1) {
                ParaConsisDataBean dataBean = new ParaConsisDataBean();
                vn.push();
                //取出源文本的纯文本之前,先查看其内容是否为空,若为空,则返回null,没有source节点,也返回null
                childAp.selectXPath("./source");
                if (childAp.evalXPath() != -1) {
                    //因为标准里面只有一个source,因此此处用if不用while
                    String srcContent = vUtils.getElementContent();
                    //如果源文本为空或无值,则返回null
                    if (srcContent == null || "".equals(srcContent)) {
                        continue;
                    } else {
                        //两个检查项中的忽略标记,若有一项为true,那么就必须获取纯文本
                        if (srcIgnoreTag || tarIgnoreTag) {
                            dataBean.setSrcContent(srcContent.trim());
                            dataBean.setSrcPureText(getTUPureText(vn).trim());
                        } else {
                            dataBean.setSrcContent(srcContent.trim());
                        }
                    }
                } else {
                    continue;
                }
                childAp.resetXPath();
                vn.pop();
                //首先过滤,如果有不应包括的文本段,则返回一个空对象
                if (!filterTheTU(vn, filterMap)) {
                    continue;
                }
                vn.push();
                //下面获取目标文本的纯文本,在之前先检查目标文本是否为空或为空值,若是,则返回null,若没有target节点,也返回空
                childAp.selectXPath("./target");
                if (childAp.evalXPath() != -1) {
                    //因为标准里面只有一个target,因此此处用if不用while
                    String tgtContent = vUtils.getElementContent();
                    //如果源文本为空或无值,则返回空对象
                    if (tgtContent == null || "".equals(tgtContent)) {
                        continue;
                    } else {
                        //两个检查项中的忽略标记,若有一项为true,那么就必须获取纯文本
                        if (srcIgnoreTag || tarIgnoreTag) {
                            dataBean.setTgtContent(tgtContent.trim());
                            dataBean.setTgtPureText(getTUPureText(vn).trim());
                        } else {
                            dataBean.setTgtContent(tgtContent.trim());
                        }
                    }
                } else {
                    continue;
                }
                dataBean.setLineNumber(rowIdList.indexOf(rowId) + 1);
                vn.pop();
                filteredTuTextMap.put(rowId, dataBean);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        logger.error(Messages.getString("qa.QAXmlHandler.logger13"), e);
    }
    return filteredTuTextMap;
}
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 49 with VTDNav

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

the class QAXmlHandler method getTuProp.

/**
	 * 得到翻译单元的属性值	,来自XLFHandler
	 * @param rowId
	 *            行的唯一标识
	 * @param propName
	 *            属性名
	 * @return 属性值;
	 */
public String getTuProp(String rowId, String propName) {
    VTDNav vn = getVTDNavByRowId(rowId);
    String tuXPath = RowIdUtil.parseRowIdToXPath(rowId);
    try {
        VTDUtils vu = new VTDUtils(vn);
        return vu.getValue(tuXPath + "/@" + propName);
    } catch (NavException e) {
        e.printStackTrace();
        logger.error(Messages.getString("qa.QAXmlHandler.logger7"), e);
    }
    return null;
}
Also used : VTDUtils(net.heartsome.xml.vtdimpl.VTDUtils) NavException(com.ximpleware.NavException) VTDNav(com.ximpleware.VTDNav)

Example 50 with VTDNav

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

the class TSFileHandler method fileAnalysis.

/**
	 * 分析指定名称的 XLIFF 文件或项目文件,获取其进度报告。
	 * 
	 * @param xliff
	 *            要分析的文件名。
	 * @param reportFormat
	 *            报告的格式。
	 * @return Map 中 ReportPath 键值表示最终生成的报告路径。
	 * */
public Map<String, Object> fileAnalysis(String filename, int reportFormat, int analysisMode, float eqvFactor) {
    File file = new File(filename);
    String filepath = file.getAbsolutePath();
    if (file == null || !file.exists()) {
        String msg = Messages.getString("file.TSFileHandler.logger21");
        logger.error(msg);
        return getErrorResult(msg, null);
    }
    // 解析文件,判断其文件类型,并调用不同的分析方法。
    VTDGen vg = new VTDGen();
    if (vg.parseFile(filepath, true)) {
        VTDNav vn = vg.getNav();
        int inx = vn.getRootIndex();
        try {
            String rootName = vn.toString(inx);
            if (rootName.equals("xliff")) {
                return xliffAnalysis(file, analysisMode, eqvFactor);
            } else if (rootName.equals("hsts-project")) {
                return projectAnalysis(file);
            } else {
                String msg = MessageFormat.format(Messages.getString("file.TSFileHandler.logger22"), filepath);
                logger.error(msg);
                return getErrorResult(msg, null);
            }
        } catch (NavException e) {
            String msg = MessageFormat.format(Messages.getString("file.TSFileHandler.logger23"), filepath);
            logger.error(msg, e);
            return getErrorResult(msg, e);
        } catch (ModifyException e) {
            String msg = Messages.getString("file.TSFileHandler.logger24");
            logger.error(msg, e);
            return getErrorResult(msg, e);
        } catch (UnsupportedEncodingException e) {
            String msg = Messages.getString("file.TSFileHandler.logger25");
            logger.error(msg, e);
            return getErrorResult(msg, e);
        } catch (TranscodeException e) {
            String msg = Messages.getString("file.TSFileHandler.logger26");
            logger.error(msg, e);
            return getErrorResult(msg, e);
        } catch (IOException e) {
            String msg = Messages.getString("file.TSFileHandler.logger27");
            logger.error(msg, e);
            return getErrorResult(msg, e);
        } catch (XPathParseException e) {
            String msg = MessageFormat.format(Messages.getString("file.TSFileHandler.logger23"), filepath);
            logger.error(msg, e);
            return getErrorResult(msg, e);
        } catch (XPathEvalException e) {
            String msg = MessageFormat.format(Messages.getString("file.TSFileHandler.logger23"), filepath);
            logger.error(msg, e);
            return getErrorResult(msg, e);
        }
    } else {
        String msg = MessageFormat.format(Messages.getString("file.TSFileHandler.logger28"), filepath);
        logger.error(msg);
        return getErrorResult(msg, null);
    }
}
Also used : XPathParseException(com.ximpleware.XPathParseException) NavException(com.ximpleware.NavException) XPathEvalException(com.ximpleware.XPathEvalException) ModifyException(com.ximpleware.ModifyException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) VTDGen(com.ximpleware.VTDGen) IOException(java.io.IOException) File(java.io.File) VTDNav(com.ximpleware.VTDNav) TranscodeException(com.ximpleware.TranscodeException)

Aggregations

VTDNav (com.ximpleware.VTDNav)206 AutoPilot (com.ximpleware.AutoPilot)177 NavException (com.ximpleware.NavException)128 XPathParseException (com.ximpleware.XPathParseException)115 XPathEvalException (com.ximpleware.XPathEvalException)110 VTDUtils (net.heartsome.xml.vtdimpl.VTDUtils)99 IOException (java.io.IOException)85 ModifyException (com.ximpleware.ModifyException)81 TranscodeException (com.ximpleware.TranscodeException)69 CoreException (org.eclipse.core.runtime.CoreException)69 XMLModifier (com.ximpleware.XMLModifier)53 UnsupportedEncodingException (java.io.UnsupportedEncodingException)49 FileNotFoundException (java.io.FileNotFoundException)46 VTDGen (com.ximpleware.VTDGen)45 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)43 XQException (javax.xml.xquery.XQException)37 LinkedHashMap (java.util.LinkedHashMap)27 ArrayList (java.util.ArrayList)26 HashMap (java.util.HashMap)25 LinkedList (java.util.LinkedList)23