use of net.heartsome.xml.vtdimpl.VTDUtils in project translationstudio8 by heartsome.
the class QAXmlHandler method getTUPureTextOrContent.
/**
* 根据需求获取trans-unit下source或target的纯文本,或者整体内容
* @return 如果返回null,则证明这个节点是个空节点,要么没有这个节点,要么这个节点没有值
*/
public String getTUPureTextOrContent(String xlfPath, String nodeXpath, boolean ignoreTag) {
VTDNav vn = vnMap.get(xlfPath);
AutoPilot ap = apMap.get(xlfPath);
validNull(vn, ap, xlfPath);
try {
VTDUtils vUtils = new VTDUtils(vn);
ap.selectXPath(nodeXpath);
while (ap.evalXPath() != -1) {
String content = vUtils.getElementContent();
if (content == null || "".equals(content)) {
return null;
}
// 如果忽略标记,就返回纯文本,否则返回整体内容
if (ignoreTag) {
return getTUPureText(vn);
}
return content;
}
} catch (NavException e) {
e.printStackTrace();
logger.error("", e);
} catch (XPathParseException e) {
e.printStackTrace();
logger.error("", e);
} catch (XPathEvalException e) {
e.printStackTrace();
logger.error("", e);
}
return null;
}
use of net.heartsome.xml.vtdimpl.VTDUtils in project translationstudio8 by heartsome.
the class QAXmlHandler method getTransUnitContext.
/**
* 通过rowId获取当前翻译单元的上下文
* @param rowId
* @param num 上下文个数
* @return ;
*/
public Map<String, String> getTransUnitContext(String rowId, int num) {
Map<String, String> result = new HashMap<String, String>();
if (tuSizeMap == null || rowId == null) {
return null;
}
VTDUtils vu = null;
VTDNav vn = getVTDNavByRowId(rowId);
try {
vu = new VTDUtils(vn);
} catch (NavException e1) {
String errorMsg = Messages.getString("qa.QAXmlHandler.logger21");
logger.error(errorMsg, e1);
return null;
}
AutoPilot ap = new AutoPilot(vu.getVTDNav());
result.put("x-preContext", getContext(vu, ap, num, true));
result.put("x-nextContext", getContext(vu, ap, num, false));
return result;
}
use of net.heartsome.xml.vtdimpl.VTDUtils in project translationstudio8 by heartsome.
the class QAXmlHandler method getTUTag.
/**
* 获取trans-unit节点下source与target节点的标记信息,如果节点不存在,或者为空,则返回null
* @param xlfPath
* @param nodeXPath
* @return
*/
public List<Map<String, String>> getTUTag(String xlfPath, String nodeXPath) {
VTDNav vn = vnMap.get(xlfPath);
Assert.isNotNull(vn, Messages.getString("qa.QAXmlHandler.msg1") + xlfPath);
try {
AutoPilot ap = apMap.get(xlfPath);
VTDUtils vUtils = new VTDUtils(vn);
ap.selectXPath(nodeXPath);
while (ap.evalXPath() != -1) {
String nodeContent = vUtils.getElementContent();
if (nodeContent == null || "".equals(nodeContent)) {
return null;
}
//开始获取所有的标记
return getTUTag(vn);
}
} catch (Exception e) {
e.printStackTrace();
logger.error(Messages.getString("qa.QAXmlHandler.logger18"), e);
}
return null;
}
use of net.heartsome.xml.vtdimpl.VTDUtils in project translationstudio8 by heartsome.
the class QAXmlHandler method getNodePureText.
/**
* 获取一个节点的纯文本,将所有的标记除外,包括标记里面的内容
* @return
*/
public String getNodePureText(String xlfPath, String nodeXpath) {
String pureText = "";
VTDNav vn = vnMap.get(xlfPath);
AutoPilot ap = apMap.get(xlfPath);
validNull(vn, ap, xlfPath);
try {
VTDUtils vUtils = new VTDUtils(vn);
ap.selectXPath(nodeXpath);
while (ap.evalXPath() != -1) {
pureText = vUtils.getElementPureText();
}
} catch (Exception e) {
e.printStackTrace();
logger.error(Messages.getString("qa.QAXmlHandler.logger14"), e);
}
return pureText;
}
use of net.heartsome.xml.vtdimpl.VTDUtils in project translationstudio8 by heartsome.
the class QAXmlHandler method addAspellConfig.
/**
* 将语言与词典对添加到 Aspell 配置文件中
* @throws Exception
*/
public void addAspellConfig(String xmlPath, String lang, String dic, boolean isUpdate) throws Exception {
VTDNav vn = vnMap.get(xmlPath);
XMLModifier xm = null;
VTDUtils vu = new VTDUtils(vn);
if (isUpdate) {
String xpath = "/aspell/aspellDictionaries/" + lang + "/text()";
xm = vu.update(xpath, dic);
} else {
String xpath = "/aspell/aspellDictionaries/text()";
String insertValue = "\n<" + lang + ">" + dic + "</" + lang + ">\n";
xm = vu.insert(xpath, insertValue);
}
vu.bind(xm.outputAndReparse());
saveAndReparse(xm, xmlPath);
}
Aggregations