Search in sources :

Example 91 with VTDNav

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

the class QAXmlHandler method getVTDNav.

public VTDNav getVTDNav(String xmlLocation) {
    VTDNav vn = vnMap.get(xmlLocation);
    Assert.isNotNull(vn, Messages.getString("qa.QAXmlHandler.msg1") + xmlLocation);
    return vn;
}
Also used : VTDNav(com.ximpleware.VTDNav)

Example 92 with VTDNav

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

the class QAXmlHandler method getTUPureTextOrContent.

/**
	 * 根据需求获取trans-unit下source或target的纯文本,或者整体内容
	 * @return	如果返回null,则证明这个节点是个空节点,要么没有这个节点,要么这个节点没有值
	 */
public String getTUPureTextOrContent(String xlfPath, String nodeXpath, boolean ignoreTag) {
    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) {
            String content = vUtils.getElementContent();
            if (content == null || "".equals(content)) {
                return null;
            }
            // 如果忽略标记,就返回纯文本,否则返回整体内容
            if (ignoreTag) {
                return getTUPureText(vn);
            }
            return content;
        }
    } catch (NavException e) {
        e.printStackTrace();
        logger.error("", e);
    } catch (XPathParseException e) {
        e.printStackTrace();
        logger.error("", e);
    } catch (XPathEvalException e) {
        e.printStackTrace();
        logger.error("", e);
    }
    return null;
}
Also used : XPathParseException(com.ximpleware.XPathParseException) VTDUtils(net.heartsome.xml.vtdimpl.VTDUtils) AutoPilot(com.ximpleware.AutoPilot) NavException(com.ximpleware.NavException) XPathEvalException(com.ximpleware.XPathEvalException) VTDNav(com.ximpleware.VTDNav)

Example 93 with VTDNav

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

the class QAXmlHandler method getTransUnitContext.

/**
	 * 通过rowId获取当前翻译单元的上下文
	 * @param rowId 
	 * @param num 上下文个数
	 * @return ;
	 */
public Map<String, String> getTransUnitContext(String rowId, int num) {
    Map<String, String> result = new HashMap<String, String>();
    if (tuSizeMap == null || rowId == null) {
        return null;
    }
    VTDUtils vu = null;
    VTDNav vn = getVTDNavByRowId(rowId);
    try {
        vu = new VTDUtils(vn);
    } catch (NavException e1) {
        String errorMsg = Messages.getString("qa.QAXmlHandler.logger21");
        logger.error(errorMsg, e1);
        return null;
    }
    AutoPilot ap = new AutoPilot(vu.getVTDNav());
    result.put("x-preContext", getContext(vu, ap, num, true));
    result.put("x-nextContext", getContext(vu, ap, num, false));
    return result;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) VTDUtils(net.heartsome.xml.vtdimpl.VTDUtils) AutoPilot(com.ximpleware.AutoPilot) NavException(com.ximpleware.NavException) VTDNav(com.ximpleware.VTDNav)

Example 94 with VTDNav

use of com.ximpleware.VTDNav 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 95 with VTDNav

use of com.ximpleware.VTDNav 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)

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