use of net.heartsome.xml.vtdimpl.VTDUtils 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 net.heartsome.xml.vtdimpl.VTDUtils 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 net.heartsome.xml.vtdimpl.VTDUtils 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;
}
use of net.heartsome.xml.vtdimpl.VTDUtils in project translationstudio8 by heartsome.
the class XLFHandler method getNodeAttribute.
/**
* 获取某属性名的属性值
* @param xlfPath
* @param nodeXpath
* @param attrName
* @return robert 2011-11-02
*/
public String getNodeAttribute(String xlfPath, String nodeXpath, String attrName) {
String attribute = "";
VTDNav vn = vnMap.get(xlfPath);
Assert.isNotNull(vn, Messages.getString("file.XLFHandler.msg4") + xlfPath);
try {
AutoPilot ap = new AutoPilot(vn);
VTDUtils vu = new VTDUtils(vn);
ap.selectXPath(nodeXpath);
while (ap.evalXPath() != -1) {
attribute = vu.getCurrentElementAttribut(attrName, "");
}
} catch (Exception e) {
LOGGER.error("", e);
e.printStackTrace();
}
return attribute;
}
use of net.heartsome.xml.vtdimpl.VTDUtils in project translationstudio8 by heartsome.
the class XLFHandler method getTgtPropValue.
/**
* 得到Target节点属性的值
* @param rowId
* 行的唯一标识
* @return ;
*/
public String getTgtPropValue(String rowId, String propName) {
VTDNav vn = getVTDNavByRowId(rowId);
String tuXPath = RowIdUtil.parseRowIdToXPath(rowId);
try {
VTDUtils vu = new VTDUtils(vn);
return vu.getValue(tuXPath + "/target/@" + propName);
} catch (NavException e) {
LOGGER.error("", e);
e.printStackTrace();
}
return null;
}
Aggregations