use of com.ximpleware.XMLModifier in project translationstudio8 by heartsome.
the class XLFHandler method deleteLastSplitInfo.
/**
* 删除目标文件的最后一条切割信息
* @param xlfPath
* robert 2011-10-26
*/
public void deleteLastSplitInfo(String xlfPath) {
VTDNav vn = vnMap.get(xlfPath);
Assert.isNotNull(vn, Messages.getString("file.XLFHandler.msg4") + xlfPath);
try {
// --robert split
String xPath = "/xliff/file/header/hs:splitInfos/hs:splitInfo[last()]";
// String xPath = "/xliff/file/header/splitInfos/splitInfo[last()]";
VTDUtils vu = new VTDUtils(vn);
AutoPilot ap = new AutoPilot(vn);
ap.declareXPathNameSpace(hsNSPrefix, hsR7NSUrl);
XMLModifier xm = vu.delete(ap, null, xPath, VTDUtils.PILOT_TO_END);
saveAndReparse(xm, xlfPath);
} catch (Exception e) {
LOGGER.error("", e);
e.printStackTrace();
}
}
use of com.ximpleware.XMLModifier in project translationstudio8 by heartsome.
the class XLFHandler method resetMergeSegment.
/**
* 合并文本段的撤销功能 robert 2012-11-06
*/
public void resetMergeSegment(Map<String, String> oldSegFragMap) {
String xlfPath = "";
VTDNav vn = null;
AutoPilot ap = new AutoPilot();
ap.declareXPathNameSpace("xml", VTDUtils.XML_NAMESPACE_URL);
ap.declareXPathNameSpace(hsNSPrefix, hsR7NSUrl);
XMLModifier xm = new XMLModifier();
try {
// 由于合并的文本段都是同一个文件,因此此处不做 文件名 的判断
for (Entry<String, String> entry : oldSegFragMap.entrySet()) {
String rowId = entry.getKey();
if ("".equals(xlfPath) || xlfPath == null || vn == null) {
xlfPath = RowIdUtil.getFileNameByRowId(rowId);
vn = vnMap.get(xlfPath);
ap.bind(vn);
xm.bind(vn);
}
ap.selectXPath(RowIdUtil.parseRowIdToXPath(rowId));
if (ap.evalXPath() != -1) {
xm.remove();
xm.insertAfterElement(entry.getValue());
}
}
saveAndReparse(xm, xlfPath);
resetRowIdsToUnsorted();
} catch (Exception e) {
LOGGER.error("", e);
}
}
use of com.ximpleware.XMLModifier in project translationstudio8 by heartsome.
the class XLFHandler method lockTransUnit.
/**
* 锁定当前vn所在的Trans-unit Add by Jaosn
* @param xlfPath
* 当前文件
* @param translateValue
* "yes"锁定,"no"解锁
* @return true设置成功,false设置失败;
*/
public void lockTransUnit(String xlfPath, String translateValue) {
VTDNav vn = vnMap.get(xlfPath);
Assert.isNotNull(vn, Messages.getString("file.XLFHandler.msg4") + xlfPath);
try {
XMLModifier xm = new XMLModifier(vn);
changeTranslateProp(vn, translateValue, xm);
// 保存并更新VTDNav对象
saveAndReparse(xm, xlfPath);
} catch (Exception e) {
LOGGER.error(Messages.getString("file.XLFHandler.logger19"), e);
}
}
use of com.ximpleware.XMLModifier in project translationstudio8 by heartsome.
the class QAXmlHandler method lockedTU.
/**
* 锁定指定的trans-unit节点
* @param rowId
* @return ;
*/
public boolean lockedTU(String rowId) {
VTDNav vn = getVTDNavByRowId(rowId);
XMLModifier xm;
// 当前的TransUnit的translate属性是否执行了修改
boolean isChanged = false;
String filePath = RowIdUtil.getFileNameByRowId(rowId);
try {
xm = new XMLModifier(vn);
String tuXpath = RowIdUtil.parseRowIdToXPath(rowId);
AutoPilot ap = new AutoPilot(vn);
ap.selectXPath(tuXpath);
if (ap.evalXPath() != -1) {
int attrIdx = vn.getAttrVal("translate");
if (attrIdx != -1) {
// 存在translate属性
String translate = vn.toString(attrIdx);
if (!translate.equals("no")) {
// translate属性值不为指定的translateValue
xm.updateToken(attrIdx, "no");
isChanged = true;
saveAndReparse(xm, filePath);
}
} else {
xm.insertAttribute(" translate=\"no\" ");
isChanged = true;
saveAndReparse(xm, filePath);
}
}
} catch (Exception e) {
e.printStackTrace();
logger.error(Messages.getString("qa.QAXmlHandler.logger22"), e);
}
return isChanged;
}
use of com.ximpleware.XMLModifier in project translationstudio8 by heartsome.
the class XLFHandler method insert.
/**
* 将content内容插入到当前的vn所有在的元素节点之中 Add By Jason
*/
public void insert(String xlfPath, String content) {
VTDNav vn = vnMap.get(xlfPath);
Assert.isNotNull(vn, Messages.getString("file.XLFHandler.msg4") + xlfPath);
try {
XMLModifier xm = new XMLModifier(vn);
xm.insertBeforeTail(content);
saveAndReparse(xm, xlfPath);
} catch (Exception e) {
LOGGER.error("", e);
e.printStackTrace();
}
}
Aggregations