Search in sources :

Example 61 with VTDUtils

use of net.heartsome.xml.vtdimpl.VTDUtils 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 62 with VTDUtils

use of net.heartsome.xml.vtdimpl.VTDUtils 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 63 with VTDUtils

use of net.heartsome.xml.vtdimpl.VTDUtils 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 64 with VTDUtils

use of net.heartsome.xml.vtdimpl.VTDUtils 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 65 with VTDUtils

use of net.heartsome.xml.vtdimpl.VTDUtils in project translationstudio8 by heartsome.

the class QAXmlHandler method addAspellConfig.

/**
	 * 将语言与词典对添加到 Aspell 配置文件中
	 * @throws Exception
	 */
public void addAspellConfig(String xmlPath, String lang, String dic, boolean isUpdate) throws Exception {
    VTDNav vn = vnMap.get(xmlPath);
    XMLModifier xm = null;
    VTDUtils vu = new VTDUtils(vn);
    if (isUpdate) {
        String xpath = "/aspell/aspellDictionaries/" + lang + "/text()";
        xm = vu.update(xpath, dic);
    } else {
        String xpath = "/aspell/aspellDictionaries/text()";
        String insertValue = "\n<" + lang + ">" + dic + "</" + lang + ">\n";
        xm = vu.insert(xpath, insertValue);
    }
    vu.bind(xm.outputAndReparse());
    saveAndReparse(xm, xmlPath);
}
Also used : XMLModifier(com.ximpleware.XMLModifier) VTDUtils(net.heartsome.xml.vtdimpl.VTDUtils) VTDNav(com.ximpleware.VTDNav)

Aggregations

VTDUtils (net.heartsome.xml.vtdimpl.VTDUtils)137 AutoPilot (com.ximpleware.AutoPilot)112 NavException (com.ximpleware.NavException)103 VTDNav (com.ximpleware.VTDNav)99 XPathParseException (com.ximpleware.XPathParseException)83 XPathEvalException (com.ximpleware.XPathEvalException)81 IOException (java.io.IOException)64 ModifyException (com.ximpleware.ModifyException)62 TranscodeException (com.ximpleware.TranscodeException)49 CoreException (org.eclipse.core.runtime.CoreException)45 XMLModifier (com.ximpleware.XMLModifier)41 VTDGen (com.ximpleware.VTDGen)33 FileNotFoundException (java.io.FileNotFoundException)30 UnsupportedEncodingException (java.io.UnsupportedEncodingException)29 HashMap (java.util.HashMap)27 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)27 LinkedHashMap (java.util.LinkedHashMap)25 ArrayList (java.util.ArrayList)23 XQException (javax.xml.xquery.XQException)20 LinkedList (java.util.LinkedList)14