use of com.ximpleware.VTDNav in project translationstudio8 by heartsome.
the class XLFHandler method getAllSrcTextForFuzzy.
/**
* 针对繁殖翻译。获取所有的源文。robert 2012-09-20
* @return
*/
public Map<String, FuzzyTransDataBean> getAllSrcTextForFuzzy(ArrayList<String> rowIdList, boolean ignoreTag) {
Map<String, FuzzyTransDataBean> textMap = new LinkedHashMap<String, FuzzyTransDataBean>();
try {
VTDNav vn = null;
AutoPilot ap = new AutoPilot();
VTDUtils vUtils = new VTDUtils();
AutoPilot childAp = new AutoPilot();
for (String rowId : rowIdList) {
// 标识译文是否为空,如果为空,则为true,不为空则为 false
boolean isTargetNull = false;
// 是否锁定
boolean isLock = false;
vn = getVTDNavByRowId(rowId).duplicateNav();
ap.bind(vn);
vUtils.bind(vn);
childAp.bind(vn);
vn.push();
ap.selectXPath(RowIdUtil.parseRowIdToXPath(rowId));
if (ap.evalXPath() != -1) {
// 如果,当前文本段是处于锁定状态的,就不用获取
int index = vn.getAttrVal("translate");
if (index != -1 && "no".equalsIgnoreCase(vn.toString(index))) {
isLock = true;
}
String srcText = null;
vn.push();
childAp.selectXPath("./source");
if (childAp.evalXPath() != -1) {
// 如果忽略标记的话,就没有必要获取source节点的完整内容了
if (!ignoreTag) {
srcText = vUtils.getElementContent();
} else {
srcText = getTUPureText(vn);
}
}
vn.pop();
vn.push();
childAp.selectXPath("./target[text()!='' or *]");
if (childAp.evalXPath() != -1) {
isTargetNull = false;
} else {
isTargetNull = true;
}
vn.pop();
// 存放值
textMap.put(rowId, new FuzzyTransDataBean(srcText.trim(), isTargetNull, isLock));
}
vn.pop();
}
} catch (Exception e) {
e.printStackTrace();
}
return textMap;
}
use of com.ximpleware.VTDNav in project translationstudio8 by heartsome.
the class XLFHandler method getPrpoGroups.
// 获取当前节点下的属性组集合。
private Vector<PropGroupBean> getPrpoGroups(VTDUtils vu) throws XPathParseException, XPathEvalException, NavException {
VTDNav vn = vu.getVTDNav();
Vector<PropGroupBean> pgs = new Vector<PropGroupBean>();
AutoPilot ap = new AutoPilot(vn);
ap.selectXPath("./prop-group");
while (ap.evalXPath() != -1) {
vn.push();
Vector<PropBean> props = getProps(vu);
vn.pop();
PropGroupBean pg = new PropGroupBean(props);
// 获取属性组名称。
pg.setName(vu.getCurrentElementAttribut("name", null));
pgs.add(pg);
}
ap.resetXPath();
ap.declareXPathNameSpace("xml", VTDUtils.XML_NAMESPACE_URL);
ap.declareXPathNameSpace(hsNSPrefix, hsR7NSUrl);
ap.selectXPath("./hs:prop-group");
while (ap.evalXPath() != -1) {
vn.push();
Vector<PropBean> props = getProps(vu);
vn.pop();
PropGroupBean pg = new PropGroupBean(props);
// 获取属性组名称。
pg.setName(vu.getCurrentElementAttribut("name", null));
pgs.add(pg);
}
if (pgs.isEmpty()) {
pgs = null;
}
return pgs;
}
use of com.ximpleware.VTDNav in project translationstudio8 by heartsome.
the class XLFHandler method deleteNodeByXpath.
/**
* 从当前xlfPath的文件中删除xpath指定的内容 Add By Jason
* @param xlfPath
* 文件
* @param xpath
* 如当前VN定位在trans-unit节点,则./target|./alt-trans 为删除所有的target节点和alt-trans节点 ;
*/
public void deleteNodeByXpath(String xlfPath, String xpath) {
VTDNav vn = vnMap.get(xlfPath);
Assert.isNotNull(vn, Messages.getString("file.XLFHandler.msg4") + xlfPath);
try {
VTDUtils vu = new VTDUtils(vn);
XMLModifier xm = vu.delete(xpath, VTDUtils.PILOT_TO_END);
saveAndReparse(xm, xlfPath);
} catch (Exception e) {
LOGGER.error("", e);
e.printStackTrace();
}
}
use of com.ximpleware.VTDNav in project translationstudio8 by heartsome.
the class XLFHandler method unlockSegment.
/**
* 给当前界面所显示的文本段解锁 robert 2012-09-24
*/
public void unlockSegment() {
Map<String, List<String>> groupRowIdMap = RowIdUtil.groupRowIdByFileName(rowIds);
for (Entry<String, List<String>> entry : groupRowIdMap.entrySet()) {
String filePath = entry.getKey();
List<String> rowIdList = entry.getValue();
VTDNav vn = vnMap.get(filePath);
Assert.isNotNull(vn, Messages.getString("file.XLFHandler.msg4") + filePath);
AutoPilot ap = new AutoPilot(vn);
boolean isUpdate = false;
try {
XMLModifier xm = new XMLModifier(vn);
for (String rowId : rowIdList) {
ap.selectXPath(RowIdUtil.parseRowIdToXPath(rowId));
if (ap.evalXPath() != -1) {
int index = vn.getAttrVal("translate");
if (index != -1 && "no".equalsIgnoreCase(vn.toString(index))) {
xm.removeAttribute(index - 1);
isUpdate = true;
}
}
}
if (isUpdate) {
saveAndReparse(xm, filePath);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
use of com.ximpleware.VTDNav in project translationstudio8 by heartsome.
the class XLFHandler method refreshRowIdsByFilterXPath.
/**
* 更新可编辑文本段唯一标识的集合(rowIds)
* @param filterXPath
* ;
*/
private void refreshRowIdsByFilterXPath(String filterXPath) {
// 清楚缓存的翻译单元
resetCache();
// 清除之前的可编辑文本段
rowIds.clear();
AutoPilot ap = new AutoPilot();
for (Entry<String, VTDNav> entry : vnMap.entrySet()) {
String fileName = entry.getKey();
VTDNav vn = entry.getValue().duplicateNav();
ap.bind(vn);
ap.declareXPathNameSpace("xml", VTDUtils.XML_NAMESPACE_URL);
ap.declareXPathNameSpace(hsNSPrefix, hsR7NSUrl);
try {
ap.selectXPath(filterXPath);
while (ap.evalXPath() != -1) {
String rowId = RowIdUtil.getRowId(vn, fileName);
if (rowId != null) {
rowIds.add(rowId);
}
}
} catch (XPathParseException e) {
LOGGER.error("", e);
e.printStackTrace();
} catch (XPathEvalException e) {
LOGGER.error("", e);
e.printStackTrace();
} catch (NavException e) {
LOGGER.error("", e);
e.printStackTrace();
}
}
}
Aggregations