Search in sources :

Example 71 with VTDNav

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

the class XLFHandler method lockTransUnit.

/**
	 * 锁定当前vn所在的Trans-unit Add by Jaosn
	 * @param xlfPath
	 *            当前文件
	 * @param translateValue
	 *            "yes"锁定,"no"解锁
	 * @return true设置成功,false设置失败;
	 */
public void lockTransUnit(String xlfPath, String translateValue) {
    VTDNav vn = vnMap.get(xlfPath);
    Assert.isNotNull(vn, Messages.getString("file.XLFHandler.msg4") + xlfPath);
    try {
        XMLModifier xm = new XMLModifier(vn);
        changeTranslateProp(vn, translateValue, xm);
        // 保存并更新VTDNav对象
        saveAndReparse(xm, xlfPath);
    } catch (Exception e) {
        LOGGER.error(Messages.getString("file.XLFHandler.logger19"), e);
    }
}
Also used : XMLModifier(com.ximpleware.XMLModifier) 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 72 with VTDNav

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

the class XLFHandler method getNodeFrag.

/**
	 * 获取整个节点,包括其头部,其子节点,其文本
	 * @param xlfPath
	 * @param nodeXPath
	 *            节点的xpath
	 * @return robert 2011-10-21
	 */
public String getNodeFrag(String xlfPath, String nodeXPath) {
    VTDNav vn = vnMap.get(xlfPath);
    Assert.isNotNull(vn, Messages.getString("file.XLFHandler.msg4") + xlfPath);
    String xliffNodeContent = "";
    try {
        AutoPilot ap = new AutoPilot(vn);
        ap.selectXPath(nodeXPath);
        VTDUtils vu = new VTDUtils(vn);
        if (ap.evalXPath() != -1) {
            xliffNodeContent = vu.getElementFragment();
        }
    } catch (XPathParseException e) {
        LOGGER.error("", e);
        e.printStackTrace();
    } catch (NavException e) {
        LOGGER.error("", e);
        e.printStackTrace();
    } catch (XPathEvalException e) {
        LOGGER.error("", e);
        e.printStackTrace();
    }
    return xliffNodeContent;
}
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 73 with VTDNav

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

the class XLFHandler method getNotes.

// 获取当前节点的所有批注。
private Vector<NoteBean> getNotes(VTDUtils vu) throws XPathEvalException, NavException, XPathParseException {
    Vector<NoteBean> notes = new Vector<NoteBean>();
    VTDNav vn = vu.getVTDNav();
    AutoPilot ap = new AutoPilot(vn);
    ap.declareXPathNameSpace("xml", VTDUtils.XML_NAMESPACE_URL);
    ap.declareXPathNameSpace(hsNSPrefix, hsR7NSUrl);
    ap.selectXPath("./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) AutoPilot(com.ximpleware.AutoPilot) Vector(java.util.Vector) VTDNav(com.ximpleware.VTDNav)

Example 74 with VTDNav

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

the class QAXmlHandler method lockedTU.

/**
	 * 锁定指定的trans-unit节点
	 * @param rowId
	 * @return ;
	 */
public boolean lockedTU(String rowId) {
    VTDNav vn = getVTDNavByRowId(rowId);
    XMLModifier xm;
    // 当前的TransUnit的translate属性是否执行了修改
    boolean isChanged = false;
    String filePath = RowIdUtil.getFileNameByRowId(rowId);
    try {
        xm = new XMLModifier(vn);
        String tuXpath = RowIdUtil.parseRowIdToXPath(rowId);
        AutoPilot ap = new AutoPilot(vn);
        ap.selectXPath(tuXpath);
        if (ap.evalXPath() != -1) {
            int attrIdx = vn.getAttrVal("translate");
            if (attrIdx != -1) {
                // 存在translate属性
                String translate = vn.toString(attrIdx);
                if (!translate.equals("no")) {
                    // translate属性值不为指定的translateValue
                    xm.updateToken(attrIdx, "no");
                    isChanged = true;
                    saveAndReparse(xm, filePath);
                }
            } else {
                xm.insertAttribute(" translate=\"no\" ");
                isChanged = true;
                saveAndReparse(xm, filePath);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        logger.error(Messages.getString("qa.QAXmlHandler.logger22"), e);
    }
    return isChanged;
}
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 75 with VTDNav

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

the class XLFHandler method insert.

/**
	 * 将content内容插入到当前的vn所有在的元素节点之中 Add By Jason
	 */
public void insert(String xlfPath, String content) {
    VTDNav vn = vnMap.get(xlfPath);
    Assert.isNotNull(vn, Messages.getString("file.XLFHandler.msg4") + xlfPath);
    try {
        XMLModifier xm = new XMLModifier(vn);
        xm.insertBeforeTail(content);
        saveAndReparse(xm, xlfPath);
    } catch (Exception e) {
        LOGGER.error("", e);
        e.printStackTrace();
    }
}
Also used : XMLModifier(com.ximpleware.XMLModifier) 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)

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