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;
}
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();
}
}
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);
}
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;
}
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);
}
}
Aggregations