Search in sources :

Example 66 with XMLModifier

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

the class XLFHandler method handleAllSegment.

/**
	 * 处理所有的文本段
	 * @param handler
	 *            单个文件的处理实现 ;
	 */
private void handleAllSegment(PerFileHandler handler) {
    AutoPilot ap = new AutoPilot();
    ap.declareXPathNameSpace("xml", VTDUtils.XML_NAMESPACE_URL);
    ap.declareXPathNameSpace(hsNSPrefix, hsR7NSUrl);
    XMLModifier xm = new XMLModifier();
    VTDUtils vu = new VTDUtils();
    VTDNav vn;
    for (Entry<String, VTDNav> entry : vnMap.entrySet()) {
        String fileName = entry.getKey();
        vn = entry.getValue();
        vn.push();
        try {
            ap.bind(vn);
            xm.bind(vn);
            vu.bind(vn);
            // 针对每个文件的VTDNav对象进行操作
            handler.handle(fileName, vu, ap, xm);
        } catch (ModifyException e) {
            LOGGER.error("", e);
            e.printStackTrace();
        } catch (XPathParseException e) {
            LOGGER.error("", e);
            e.printStackTrace();
        } catch (XPathEvalException e) {
            LOGGER.error("", e);
            e.printStackTrace();
        } catch (NavException e) {
            LOGGER.error("", e);
            e.printStackTrace();
        } catch (UnsupportedEncodingException e) {
            LOGGER.error("", e);
            e.printStackTrace();
        } finally {
            vn.pop();
        }
    }
    ap = null;
    xm = null;
    vu = null;
}
Also used : XPathParseException(com.ximpleware.XPathParseException) XMLModifier(com.ximpleware.XMLModifier) VTDUtils(net.heartsome.xml.vtdimpl.VTDUtils) AutoPilot(com.ximpleware.AutoPilot) XPathEvalException(com.ximpleware.XPathEvalException) NavException(com.ximpleware.NavException) ModifyException(com.ximpleware.ModifyException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) VTDNav(com.ximpleware.VTDNav)

Example 67 with XMLModifier

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

the class XLFHandler method lockFaTU.

/**
	 * 专门针对字数分析后的锁定文本段 roebrt 2012-05-21
	 * @param rowIdList
	 */
public void lockFaTU(List<String> rowIdList) {
    if (rowIdList == null || rowIdList.size() <= 0) {
        return;
    }
    VTDNav vn = getVTDNavByRowId(rowIdList.get(0));
    try {
        XMLModifier xm = new XMLModifier(vn);
        saveAndReparse(xm, RowIdUtil.getFileNameByRowId(rowIdList.get(0)));
        lockTransUnits(rowIdList, true);
    } 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)

Example 68 with XMLModifier

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

the class XLFHandler method batchUpdateAltTrans.

public void batchUpdateAltTrans(int[] rowIndexs, Map<Integer, List<AltTransBean>> newAltTransList, Map<Integer, List<String>> oldAltTransToolIdList) {
    String preFileName = "";
    XMLModifier xm = null;
    VTDUtils vu = new VTDUtils();
    for (int rowIndex : rowIndexs) {
        String rowId = getRowId(rowIndex);
        String fileName = RowIdUtil.getFileNameByRowId(rowId);
        try {
            if (preFileName.equals("")) {
                preFileName = fileName;
                vu.bind(vnMap.get(fileName));
                xm = new XMLModifier(vu.getVTDNav());
                preFileName = fileName;
            } else if (!preFileName.equals(fileName)) {
                saveAndReparse(xm, fileName);
                vu.bind(vnMap.get(fileName));
                xm = new XMLModifier(vu.getVTDNav());
                preFileName = fileName;
            }
            updateAltTrans(vu, xm, rowId, newAltTransList.get(rowIndex), oldAltTransToolIdList.get(rowIndex));
        } catch (NavException e) {
            LOGGER.error("", e);
        } catch (ModifyException e) {
            LOGGER.error("", e);
        }
    }
    saveAndReparse(xm, preFileName);
}
Also used : XMLModifier(com.ximpleware.XMLModifier) VTDUtils(net.heartsome.xml.vtdimpl.VTDUtils) NavException(com.ximpleware.NavException) ModifyException(com.ximpleware.ModifyException)

Example 69 with XMLModifier

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

the class QAXmlHandler method addDataToXml.

/**
	 * 将数据添加到文件中,并且是添加到指定节点的尾部
	 * @param newXlfPath
	 * @param data	要添加的内容
	 * @param toXpath	要添加的位置
	 */
public boolean addDataToXml(String filePath, String toXpath, String data) {
    VTDNav vn = vnMap.get(filePath);
    Assert.isNotNull(vn, Messages.getString("qa.QAXmlHandler.msg1") + filePath);
    try {
        AutoPilot ap = new AutoPilot(vn);
        ap.selectXPath(toXpath);
        if (ap.evalXPath() != -1) {
            XMLModifier xm = new XMLModifier(vn);
            xm.insertBeforeTail((data + "\n").getBytes("UTF-8"));
            //更新新生成的xliff文件,并重新加载并更新VTDVNav
            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 70 with XMLModifier

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

the class QAXmlHandler method saveAspellConfig.

/**
	 * 当 spellPage 点击确定时,保存 aspell 配置的部份信息
	 * @param xmlPath
	 * @param isUtf8 界面上是否选中了 utf-8 的 button。
	 */
public void saveAspellConfig(String xmlPath, String commandLine, boolean isUtf8) throws Exception {
    VTDNav vn = vnMap.get(xmlPath);
    VTDUtils vu = new VTDUtils(vn);
    XMLModifier xm = null;
    String commandPath = getNodeText(xmlPath, "/aspell/commandLine", null);
    if (commandPath == null && commandLine != null) {
        String insertValue = "\n<commandLine>" + commandLine + "</commandLine>\n";
        xm = vu.insert("/aspell/text()", insertValue);
    } else if (commandPath != null && commandLine != null) {
        if (!commandLine.equals(commandPath)) {
            xm = vu.update("/aspell/commandLine/text()", commandLine);
        }
    } else if (commandPath != null && commandLine == null) {
        xm = vu.delete("/aspell/commandLine");
    }
    if (xm != null) {
        vu.bind(xm.outputAndReparse());
    }
    String utf8File = getNodeText(xmlPath, "/aspell/utf8", null);
    String utf8 = isUtf8 ? "yes" : "no";
    if (utf8File == null) {
        String insertValue = "\n<utf8>" + utf8 + "</utf8>\n";
        xm = vu.insert("/aspell/text()", insertValue);
    } else {
        if (!utf8File.equals(utf8)) {
            xm = vu.update("/aspell/utf8/text()", utf8);
        }
    }
    if (xm != null) {
        saveAndReparse(xm, xmlPath);
    }
}
Also used : XMLModifier(com.ximpleware.XMLModifier) VTDUtils(net.heartsome.xml.vtdimpl.VTDUtils) VTDNav(com.ximpleware.VTDNav)

Aggregations

XMLModifier (com.ximpleware.XMLModifier)76 NavException (com.ximpleware.NavException)52 VTDNav (com.ximpleware.VTDNav)49 ModifyException (com.ximpleware.ModifyException)48 AutoPilot (com.ximpleware.AutoPilot)46 VTDUtils (net.heartsome.xml.vtdimpl.VTDUtils)41 XPathParseException (com.ximpleware.XPathParseException)40 XPathEvalException (com.ximpleware.XPathEvalException)39 IOException (java.io.IOException)35 TranscodeException (com.ximpleware.TranscodeException)32 UnsupportedEncodingException (java.io.UnsupportedEncodingException)22 VTDGen (com.ximpleware.VTDGen)19 CoreException (org.eclipse.core.runtime.CoreException)17 FileNotFoundException (java.io.FileNotFoundException)15 ParseException (com.ximpleware.ParseException)13 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)13 ArrayList (java.util.ArrayList)12 FileOutputStream (java.io.FileOutputStream)11 XQException (javax.xml.xquery.XQException)11 File (java.io.File)10