use of com.ximpleware.VTDNav in project translationstudio8 by heartsome.
the class XLFHandler method getTUFragByRowId.
/**
* 获取给定rowId的完整内容,包括头与尾
* @param rowId
* @return ;
*/
public String getTUFragByRowId(String rowId) {
String nodeStr = null;
String xlfPath = RowIdUtil.getFileNameByRowId(rowId);
VTDNav vn = vnMap.get(xlfPath);
Assert.isNotNull(vn, Messages.getString("file.XLFHandler.msg4") + xlfPath);
String xpath = RowIdUtil.parseRowIdToXPath(rowId);
AutoPilot ap = new AutoPilot(vn);
try {
VTDUtils vu = new VTDUtils(vn);
ap.selectXPath(xpath);
if (ap.evalXPath() != -1) {
nodeStr = vu.getElementFragment();
}
} catch (Exception e) {
LOGGER.error("", e);
e.printStackTrace();
}
return nodeStr;
}
use of com.ximpleware.VTDNav in project translationstudio8 by heartsome.
the class XLFHandler method getSegmentIndex.
/**
* 得到文本段的索引
* @param currentRowIndex
* @param relativeXPath
* @param isNext
* 是否是找下一个。<br/>
* <code>true</code>: 下一个;<code>false</code>: 上一个。
* @return 文本段的索引;
*/
private int getSegmentIndex(int currentRowIndex, String relativeXPath, boolean isNext) {
int step = isNext ? 1 : -1;
currentRowIndex += step;
AutoPilot ap = new AutoPilot();
ap.declareXPathNameSpace(hsNSPrefix, hsR7NSUrl);
while (currentRowIndex >= 0 && currentRowIndex < rowIds.size()) {
String rowId = getRowId(currentRowIndex);
VTDNav vn = getVTDNavByRowId(rowId);
ap.bind(vn);
String xpath = RowIdUtil.parseRowIdToXPath(rowId);
try {
ap.selectXPath(xpath + relativeXPath);
if (ap.evalXPath() != -1) {
return currentRowIndex;
}
} catch (XPathEvalException e) {
LOGGER.error("", e);
e.printStackTrace();
} catch (NavException e) {
LOGGER.error("", e);
e.printStackTrace();
} catch (XPathParseException e) {
LOGGER.error("", e);
e.printStackTrace();
}
currentRowIndex += step;
}
return -1;
}
use of com.ximpleware.VTDNav in project translationstudio8 by heartsome.
the class XLFHandler method addNote.
/**
* 添加批注
* @param rowId
* 行的唯一标识
* @param note
* 批注内容;
*/
public void addNote(Map<String, List<String>> mapRowIdByFileName, String note, String from, boolean isApplyCurrent) {
try {
StringBuffer insertValue = new StringBuffer("<note");
if (from != null) {
insertValue.append(" from='").append(from).append("'");
}
if (!isApplyCurrent) {
insertValue.append(" hs:apply-current='No'");
}
insertValue.append(">").append(StringUtilsBasic.checkNullStr(note)).append("</note>");
VTDUtils vu = new VTDUtils();
XMLModifier xm = new XMLModifier();
Iterator<Entry<String, List<String>>> it = mapRowIdByFileName.entrySet().iterator();
while (it.hasNext()) {
Entry<String, List<String>> entry = it.next();
String fileName = entry.getKey();
VTDNav vn = vnMap.get(fileName);
vu.bind(vn);
xm.bind(vn);
for (String rowId : entry.getValue()) {
StringBuffer xpath = new StringBuffer(RowIdUtil.parseRowIdToXPath(rowId));
xm = vu.insert(null, xm, xpath.append("/text()").toString(), insertValue.toString());
}
saveAndReparse(xm, fileName);
}
} catch (NavException e) {
LOGGER.error("", e);
e.printStackTrace();
} catch (ModifyException e) {
LOGGER.error("", e);
e.printStackTrace();
}
}
use of com.ximpleware.VTDNav in project translationstudio8 by heartsome.
the class XLFHandler method getFileInfo.
/**
* 获取xliff文件的file节点的信息,保存到LinkedHashMap中, 第一个值为file节点的序列,从1开始,第二个值为该file节点下trans-unit的个数
* @param xlfPath
* @return robert 2011-10-21
*/
public Map<Integer, Integer> getFileInfo(String xlfPath) {
Map<Integer, Integer> fileInfo = new LinkedHashMap<Integer, Integer>();
VTDNav vn = vnMap.get(xlfPath);
Assert.isNotNull(vn, Messages.getString("file.XLFHandler.msg4") + xlfPath);
// 备注,这是从1开始。
int fileIndex = 1;
int transUnitNum = 0;
try {
AutoPilot ap = new AutoPilot(vn);
ap.selectXPath("/xliff/file");
while (ap.evalXPath() != -1) {
AutoPilot ap2 = new AutoPilot(vn);
ap2.selectXPath("count(./body/trans-unit)");
transUnitNum = (int) ap2.evalXPathToNumber();
fileInfo.put(fileIndex, transUnitNum);
fileIndex++;
}
} catch (Exception e) {
LOGGER.error("", e);
e.printStackTrace();
}
return fileInfo;
}
use of com.ximpleware.VTDNav in project translationstudio8 by heartsome.
the class XLFHandler method getOldSplitInfo.
/**
* 获取该xliff文件的最终分割信息(针对已经分割的文件)
* @param xlfPath
* @return robert 2011-10-20
*/
public Map<String, String> getOldSplitInfo(String xlfPath) {
Map<String, String> oldSplitInfo = new HashMap<String, String>();
VTDNav vn = vnMap.get(xlfPath);
Assert.isNotNull(vn, Messages.getString("file.XLFHandler.msg4") + xlfPath);
try {
AutoPilot ap = new AutoPilot(vn);
ap.declareXPathNameSpace(hsNSPrefix, hsR7NSUrl);
// --robert split
ap.selectXPath("/xliff/file/header/hs:splitInfos/hs:splitInfo[last()]");
while (ap.evalXPath() != -1) {
VTDUtils vu = new VTDUtils(vn);
oldSplitInfo = vu.getCurrentElementAttributs(hsNSPrefix, hsR7NSUrl);
}
} catch (Exception e) {
LOGGER.error(Messages.getString("file.XLFHandler.logger18"), e);
// TODO: handle exception
}
return oldSplitInfo;
}
Aggregations