Search in sources :

Example 26 with XMLModifier

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

the class XLFHandler method deleteLastSplitInfo.

/**
	 * 删除目标文件的最后一条切割信息
	 * @param xlfPath
	 *            robert 2011-10-26
	 */
public void deleteLastSplitInfo(String xlfPath) {
    VTDNav vn = vnMap.get(xlfPath);
    Assert.isNotNull(vn, Messages.getString("file.XLFHandler.msg4") + xlfPath);
    try {
        // --robert split
        String xPath = "/xliff/file/header/hs:splitInfos/hs:splitInfo[last()]";
        // String xPath = "/xliff/file/header/splitInfos/splitInfo[last()]";
        VTDUtils vu = new VTDUtils(vn);
        AutoPilot ap = new AutoPilot(vn);
        ap.declareXPathNameSpace(hsNSPrefix, hsR7NSUrl);
        XMLModifier xm = vu.delete(ap, null, 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) AutoPilot(com.ximpleware.AutoPilot) 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 27 with XMLModifier

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

the class XLFHandler method resetMergeSegment.

/**
	 * 合并文本段的撤销功能 robert 2012-11-06
	 */
public void resetMergeSegment(Map<String, String> oldSegFragMap) {
    String xlfPath = "";
    VTDNav vn = null;
    AutoPilot ap = new AutoPilot();
    ap.declareXPathNameSpace("xml", VTDUtils.XML_NAMESPACE_URL);
    ap.declareXPathNameSpace(hsNSPrefix, hsR7NSUrl);
    XMLModifier xm = new XMLModifier();
    try {
        // 由于合并的文本段都是同一个文件,因此此处不做 文件名 的判断
        for (Entry<String, String> entry : oldSegFragMap.entrySet()) {
            String rowId = entry.getKey();
            if ("".equals(xlfPath) || xlfPath == null || vn == null) {
                xlfPath = RowIdUtil.getFileNameByRowId(rowId);
                vn = vnMap.get(xlfPath);
                ap.bind(vn);
                xm.bind(vn);
            }
            ap.selectXPath(RowIdUtil.parseRowIdToXPath(rowId));
            if (ap.evalXPath() != -1) {
                xm.remove();
                xm.insertAfterElement(entry.getValue());
            }
        }
        saveAndReparse(xm, xlfPath);
        resetRowIdsToUnsorted();
    } catch (Exception e) {
        LOGGER.error("", e);
    }
}
Also used : XMLModifier(com.ximpleware.XMLModifier) AutoPilot(com.ximpleware.AutoPilot) 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 28 with XMLModifier

use of com.ximpleware.XMLModifier 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 29 with XMLModifier

use of com.ximpleware.XMLModifier 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 30 with XMLModifier

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

XMLModifier (com.ximpleware.XMLModifier)80 NavException (com.ximpleware.NavException)54 VTDNav (com.ximpleware.VTDNav)53 AutoPilot (com.ximpleware.AutoPilot)50 ModifyException (com.ximpleware.ModifyException)50 XPathParseException (com.ximpleware.XPathParseException)42 VTDUtils (net.heartsome.xml.vtdimpl.VTDUtils)41 XPathEvalException (com.ximpleware.XPathEvalException)40 IOException (java.io.IOException)38 TranscodeException (com.ximpleware.TranscodeException)34 VTDGen (com.ximpleware.VTDGen)23 UnsupportedEncodingException (java.io.UnsupportedEncodingException)22 CoreException (org.eclipse.core.runtime.CoreException)17 FileNotFoundException (java.io.FileNotFoundException)15 FileOutputStream (java.io.FileOutputStream)15 ParseException (com.ximpleware.ParseException)13 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)13 ArrayList (java.util.ArrayList)12 File (java.io.File)11 XQException (javax.xml.xquery.XQException)11