Search in sources :

Example 56 with VTDNav

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

the class XLFHandler method getAllSrcTextForFuzzy.

/**
	 * 针对繁殖翻译。获取所有的源文。robert 2012-09-20
	 * @return
	 */
public Map<String, FuzzyTransDataBean> getAllSrcTextForFuzzy(ArrayList<String> rowIdList, boolean ignoreTag) {
    Map<String, FuzzyTransDataBean> textMap = new LinkedHashMap<String, FuzzyTransDataBean>();
    try {
        VTDNav vn = null;
        AutoPilot ap = new AutoPilot();
        VTDUtils vUtils = new VTDUtils();
        AutoPilot childAp = new AutoPilot();
        for (String rowId : rowIdList) {
            // 标识译文是否为空,如果为空,则为true,不为空则为 false
            boolean isTargetNull = false;
            // 是否锁定
            boolean isLock = false;
            vn = getVTDNavByRowId(rowId).duplicateNav();
            ap.bind(vn);
            vUtils.bind(vn);
            childAp.bind(vn);
            vn.push();
            ap.selectXPath(RowIdUtil.parseRowIdToXPath(rowId));
            if (ap.evalXPath() != -1) {
                // 如果,当前文本段是处于锁定状态的,就不用获取
                int index = vn.getAttrVal("translate");
                if (index != -1 && "no".equalsIgnoreCase(vn.toString(index))) {
                    isLock = true;
                }
                String srcText = null;
                vn.push();
                childAp.selectXPath("./source");
                if (childAp.evalXPath() != -1) {
                    // 如果忽略标记的话,就没有必要获取source节点的完整内容了
                    if (!ignoreTag) {
                        srcText = vUtils.getElementContent();
                    } else {
                        srcText = getTUPureText(vn);
                    }
                }
                vn.pop();
                vn.push();
                childAp.selectXPath("./target[text()!='' or *]");
                if (childAp.evalXPath() != -1) {
                    isTargetNull = false;
                } else {
                    isTargetNull = true;
                }
                vn.pop();
                // 存放值
                textMap.put(rowId, new FuzzyTransDataBean(srcText.trim(), isTargetNull, isLock));
            }
            vn.pop();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return textMap;
}
Also used : VTDUtils(net.heartsome.xml.vtdimpl.VTDUtils) AutoPilot(com.ximpleware.AutoPilot) FuzzyTransDataBean(net.heartsome.cat.ts.core.bean.FuzzyTransDataBean) VTDNav(com.ximpleware.VTDNav) NavException(com.ximpleware.NavException) CoreException(org.eclipse.core.runtime.CoreException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) XPathParseException(com.ximpleware.XPathParseException) FileNotFoundException(java.io.FileNotFoundException) XQException(javax.xml.xquery.XQException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) TranscodeException(com.ximpleware.TranscodeException) XPathEvalException(com.ximpleware.XPathEvalException) IOException(java.io.IOException) ModifyException(com.ximpleware.ModifyException) LinkedHashMap(java.util.LinkedHashMap)

Example 57 with VTDNav

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

the class XLFHandler method getPrpoGroups.

// 获取当前节点下的属性组集合。
private Vector<PropGroupBean> getPrpoGroups(VTDUtils vu) throws XPathParseException, XPathEvalException, NavException {
    VTDNav vn = vu.getVTDNav();
    Vector<PropGroupBean> pgs = new Vector<PropGroupBean>();
    AutoPilot ap = new AutoPilot(vn);
    ap.selectXPath("./prop-group");
    while (ap.evalXPath() != -1) {
        vn.push();
        Vector<PropBean> props = getProps(vu);
        vn.pop();
        PropGroupBean pg = new PropGroupBean(props);
        // 获取属性组名称。
        pg.setName(vu.getCurrentElementAttribut("name", null));
        pgs.add(pg);
    }
    ap.resetXPath();
    ap.declareXPathNameSpace("xml", VTDUtils.XML_NAMESPACE_URL);
    ap.declareXPathNameSpace(hsNSPrefix, hsR7NSUrl);
    ap.selectXPath("./hs:prop-group");
    while (ap.evalXPath() != -1) {
        vn.push();
        Vector<PropBean> props = getProps(vu);
        vn.pop();
        PropGroupBean pg = new PropGroupBean(props);
        // 获取属性组名称。
        pg.setName(vu.getCurrentElementAttribut("name", null));
        pgs.add(pg);
    }
    if (pgs.isEmpty()) {
        pgs = null;
    }
    return pgs;
}
Also used : PropGroupBean(net.heartsome.cat.ts.core.bean.PropGroupBean) AutoPilot(com.ximpleware.AutoPilot) PropBean(net.heartsome.cat.ts.core.bean.PropBean) VTDNav(com.ximpleware.VTDNav) Vector(java.util.Vector)

Example 58 with VTDNav

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

the class XLFHandler method deleteNodeByXpath.

/**
	 * 从当前xlfPath的文件中删除xpath指定的内容 Add By Jason
	 * @param xlfPath
	 *            文件
	 * @param xpath
	 *            如当前VN定位在trans-unit节点,则./target|./alt-trans 为删除所有的target节点和alt-trans节点 ;
	 */
public void deleteNodeByXpath(String xlfPath, String xpath) {
    VTDNav vn = vnMap.get(xlfPath);
    Assert.isNotNull(vn, Messages.getString("file.XLFHandler.msg4") + xlfPath);
    try {
        VTDUtils vu = new VTDUtils(vn);
        XMLModifier xm = vu.delete(xpath, VTDUtils.PILOT_TO_END);
        saveAndReparse(xm, xlfPath);
    } catch (Exception e) {
        LOGGER.error("", e);
        e.printStackTrace();
    }
}
Also used : XMLModifier(com.ximpleware.XMLModifier) VTDUtils(net.heartsome.xml.vtdimpl.VTDUtils) VTDNav(com.ximpleware.VTDNav) NavException(com.ximpleware.NavException) CoreException(org.eclipse.core.runtime.CoreException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) XPathParseException(com.ximpleware.XPathParseException) FileNotFoundException(java.io.FileNotFoundException) XQException(javax.xml.xquery.XQException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) TranscodeException(com.ximpleware.TranscodeException) XPathEvalException(com.ximpleware.XPathEvalException) IOException(java.io.IOException) ModifyException(com.ximpleware.ModifyException)

Example 59 with VTDNav

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

the class XLFHandler method unlockSegment.

/**
	 * 给当前界面所显示的文本段解锁 robert 2012-09-24
	 */
public void unlockSegment() {
    Map<String, List<String>> groupRowIdMap = RowIdUtil.groupRowIdByFileName(rowIds);
    for (Entry<String, List<String>> entry : groupRowIdMap.entrySet()) {
        String filePath = entry.getKey();
        List<String> rowIdList = entry.getValue();
        VTDNav vn = vnMap.get(filePath);
        Assert.isNotNull(vn, Messages.getString("file.XLFHandler.msg4") + filePath);
        AutoPilot ap = new AutoPilot(vn);
        boolean isUpdate = false;
        try {
            XMLModifier xm = new XMLModifier(vn);
            for (String rowId : rowIdList) {
                ap.selectXPath(RowIdUtil.parseRowIdToXPath(rowId));
                if (ap.evalXPath() != -1) {
                    int index = vn.getAttrVal("translate");
                    if (index != -1 && "no".equalsIgnoreCase(vn.toString(index))) {
                        xm.removeAttribute(index - 1);
                        isUpdate = true;
                    }
                }
            }
            if (isUpdate) {
                saveAndReparse(xm, filePath);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
Also used : XMLModifier(com.ximpleware.XMLModifier) AutoPilot(com.ximpleware.AutoPilot) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) VTDNav(com.ximpleware.VTDNav) NavException(com.ximpleware.NavException) CoreException(org.eclipse.core.runtime.CoreException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) XPathParseException(com.ximpleware.XPathParseException) FileNotFoundException(java.io.FileNotFoundException) XQException(javax.xml.xquery.XQException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) TranscodeException(com.ximpleware.TranscodeException) XPathEvalException(com.ximpleware.XPathEvalException) IOException(java.io.IOException) ModifyException(com.ximpleware.ModifyException)

Example 60 with VTDNav

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

the class XLFHandler method refreshRowIdsByFilterXPath.

/**
	 * 更新可编辑文本段唯一标识的集合(rowIds)
	 * @param filterXPath
	 *            ;
	 */
private void refreshRowIdsByFilterXPath(String filterXPath) {
    // 清楚缓存的翻译单元
    resetCache();
    // 清除之前的可编辑文本段
    rowIds.clear();
    AutoPilot ap = new AutoPilot();
    for (Entry<String, VTDNav> entry : vnMap.entrySet()) {
        String fileName = entry.getKey();
        VTDNav vn = entry.getValue().duplicateNav();
        ap.bind(vn);
        ap.declareXPathNameSpace("xml", VTDUtils.XML_NAMESPACE_URL);
        ap.declareXPathNameSpace(hsNSPrefix, hsR7NSUrl);
        try {
            ap.selectXPath(filterXPath);
            while (ap.evalXPath() != -1) {
                String rowId = RowIdUtil.getRowId(vn, fileName);
                if (rowId != null) {
                    rowIds.add(rowId);
                }
            }
        } catch (XPathParseException e) {
            LOGGER.error("", e);
            e.printStackTrace();
        } catch (XPathEvalException e) {
            LOGGER.error("", e);
            e.printStackTrace();
        } catch (NavException e) {
            LOGGER.error("", e);
            e.printStackTrace();
        }
    }
}
Also used : XPathParseException(com.ximpleware.XPathParseException) AutoPilot(com.ximpleware.AutoPilot) XPathEvalException(com.ximpleware.XPathEvalException) NavException(com.ximpleware.NavException) VTDNav(com.ximpleware.VTDNav)

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