Search in sources :

Example 86 with VTDNav

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

the class XLFHandler method getNotes.

public Vector<NoteBean> getNotes(String rowId) throws NavException, XPathParseException, XPathEvalException {
    Vector<NoteBean> notes = new Vector<NoteBean>();
    VTDNav vn = getVTDNavByRowId(rowId);
    VTDUtils vu = new VTDUtils(vn);
    AutoPilot ap = new AutoPilot(vn);
    ap.declareXPathNameSpace("xml", VTDUtils.XML_NAMESPACE_URL);
    ap.declareXPathNameSpace(hsNSPrefix, hsR7NSUrl);
    String tuXPath = RowIdUtil.parseRowIdToXPath(rowId);
    ap.selectXPath(tuXPath + "/note");
    while (ap.evalXPath() != -1) {
        NoteBean note = new NoteBean(vu.getElementContent());
        note.setLang(vu.getCurrentElementAttribut("xml:lang", null));
        note.setFrom(vu.getCurrentElementAttribut("from", null));
        note.setPriority(vu.getCurrentElementAttribut("priority", null));
        note.setAnnotates(vu.getCurrentElementAttribut("annotates", null));
        note.setApplyCurrent(vu.getCurrentElementAttribut("hs:apply-current", "Yes"));
        notes.add(0, note);
    }
    if (notes.isEmpty()) {
        notes = null;
    }
    return notes;
}
Also used : NoteBean(net.heartsome.cat.ts.core.bean.NoteBean) VTDUtils(net.heartsome.xml.vtdimpl.VTDUtils) AutoPilot(com.ximpleware.AutoPilot) Vector(java.util.Vector) VTDNav(com.ximpleware.VTDNav)

Example 87 with VTDNav

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

the class QAXmlHandler method getNodeCount.

/**
	 * 获取某节点的总数
	 * @return
	 */
public int getNodeCount(String xlfPath, String nodeXpath) {
    int nodeNum = 0;
    VTDNav vn = vnMap.get(xlfPath);
    AutoPilot ap = apMap.get(xlfPath);
    validNull(vn, ap, xlfPath);
    try {
        ap.selectXPath("count(" + nodeXpath + ")");
        nodeNum = (int) ap.evalXPathToNumber();
    } catch (Exception e) {
        e.printStackTrace();
        logger.error(Messages.getString("qa.QAXmlHandler.logger9"), e);
    }
    return nodeNum;
}
Also used : 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 88 with VTDNav

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

the class QAXmlHandler method deleteAllNode.

/**
	 * 根据指定的 xpaht 删除所有的节点
	 * @param filePath
	 * @param nodeXpath
	 * @return
	 */
public boolean deleteAllNode(String filePath, String nodeXpath) {
    VTDNav vn = vnMap.get(filePath);
    Assert.isNotNull(vn, Messages.getString("qa.QAXmlHandler.msg1") + filePath);
    try {
        AutoPilot ap = new AutoPilot(vn);
        ap.selectXPath(nodeXpath);
        XMLModifier xm = new XMLModifier(vn);
        boolean hasRemoved = false;
        while (ap.evalXPath() != -1) {
            xm.remove();
            hasRemoved = true;
        }
        if (hasRemoved) {
            return saveAndReparse(xm, filePath);
        }
    } catch (Exception e) {
        e.printStackTrace();
        logger.error("", e);
    }
    return false;
}
Also used : XMLModifier(com.ximpleware.XMLModifier) 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 89 with VTDNav

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

the class QAXmlHandler method getFilteredTUText.

/**
	 * 获取trans-unit节点过滤后的值,过滤条件为不包括上下文匹配,不包括完全匹配,不包括已锁文本,过滤条件在首选项中设置
	 * @return Map<String, String > 六个键值对,srcPureText --> 源文本的纯文本,tarPureText --> 目标文本的纯文本, srcContent -->
	 *         源文本的内容,tarContent --> 目标文本的内容 , srcTag --> 源文本的标记, tarTag --> 目标文本的标记;
	 *         如果返回的是null,则标志source节点无内容,这对与行号就不自增
	 * @param xlfPath	
	 * @param nodeXpath	
	 * @param filterMap	过滤条件
	 * @return ;
	 */
public QATUDataBean getFilteredTUText(String xlfPath, String nodeXpath, Map<String, Boolean> filterMap) {
    QATUDataBean bean = new QATUDataBean();
    VTDNav vn = vnMap.get(xlfPath);
    AutoPilot ap = new AutoPilot(vn);
    Assert.isNotNull(vn, Messages.getString("qa.QAXmlHandler.msg1") + xlfPath);
    AutoPilot childAp = new AutoPilot(vn);
    try {
        VTDUtils vUtils = new VTDUtils(vn);
        ap.selectXPath(nodeXpath);
        while (ap.evalXPath() != -1) {
            String rowId = RowIdUtil.getRowId(vn, xlfPath);
            bean.setRowId(rowId);
            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)) {
                    return null;
                } else {
                    bean.setSrcPureText(getTUPureText(vn));
                    bean.setSrcContent(srcContent);
                }
            } else {
                return null;
            }
            childAp.resetXPath();
            vn.pop();
            //首先过滤,如果有不应包括的文本段,则返回一个空对象
            if (!filterTheTU(vn, filterMap)) {
                bean.setPassFilter(false);
                return bean;
            }
            //下面获取目标文本的纯文本,在之前先检查目标文本是否为空或为空值,若是,则返回null,若没有target节点,也返回空
            childAp.selectXPath("./target");
            if (childAp.evalXPath() != -1) {
                //因为标准里面只有一个target,因此此处用if不用while
                String tarContent = vUtils.getElementContent();
                //如果源文本为空或无值,则返回空对象
                if (tarContent == null || "".equals(tarContent)) {
                    bean.setTgtContent(tarContent);
                    return bean;
                } else {
                    bean.setTgtContent(tarContent);
                    bean.setTgtPureText(getTUPureText(vn));
                }
            } else {
                return bean;
            }
            childAp.resetXPath();
        }
    } catch (Exception e) {
        e.printStackTrace();
        logger.error(Messages.getString("qa.QAXmlHandler.logger13"), e);
    }
    return bean;
}
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 90 with VTDNav

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

the class QAXmlHandler method getFilteredTUPureText.

/**
	 * 获取trans-unit节点过滤后的值,过滤条件为不包括上下文匹配,不包括完全匹配,不包括已锁文本,过滤条件在首选项中设置
	 * @return	Map<String, String >	两个键值对,srcPureText --> 源文本的纯文本,tarPureText --> 目标文本的纯文本
	 * 如果返回的是null,则标志source节点无内容,这对与行号就不自增
	 */
public Map<String, String> getFilteredTUPureText(String xlfPath, String nodeXpath, Map<String, Boolean> filterMap) {
    Map<String, String> filteredTuPureTextMap = new HashMap<String, String>();
    VTDNav vn = vnMap.get(xlfPath);
    AutoPilot ap = new AutoPilot(vn);
    Assert.isNotNull(vn, Messages.getString("qa.QAXmlHandler.msg1") + xlfPath);
    AutoPilot childAp = new AutoPilot(vn);
    try {
        VTDUtils vUtils = new VTDUtils(vn);
        ap.selectXPath(nodeXpath);
        while (ap.evalXPath() != -1) {
            vn.push();
            //取出源文本的纯文本之前,先查看其内容是否为空,若为空,则返回,没有source节点,也返回null
            childAp.selectXPath("./source");
            if (childAp.evalXPath() != -1) {
                //因为标准里面只有一个source,因此此处用if不用while
                String srcContent = vUtils.getElementContent();
                //如果源文本为空或无值,则返回null
                if (srcContent == null || "".equals(srcContent)) {
                    return null;
                } else {
                    filteredTuPureTextMap.put("srcPureText", getTUPureText(vn));
                }
            } else {
                return null;
            }
            childAp.resetXPath();
            vn.pop();
            //首先过滤,如果有不应包括的文本段,则返回空
            if (!filterTheTU(vn, filterMap)) {
                return filteredTuPureTextMap;
            }
            //下面获取目标文本的纯文本,在之前先检查目标文本是否为空或为空值,若是,则返回null,若没有target节点,也返回空
            childAp.selectXPath("./target");
            if (childAp.evalXPath() != -1) {
                //因为标准里面只有一个target,因此此处用if不用while
                String tarContent = vUtils.getElementContent();
                //如果源文本为空或无值,则返回null
                if (tarContent == null || "".equals(tarContent)) {
                    return filteredTuPureTextMap;
                } else {
                    filteredTuPureTextMap.put("tarPureText", getTUPureText(vn));
                }
            } else {
                return filteredTuPureTextMap;
            }
            childAp.resetXPath();
        }
    } catch (Exception e) {
        logger.error(Messages.getString("qa.QAXmlHandler.logger12"), e);
    }
    return filteredTuPureTextMap;
}
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)

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