use of com.ximpleware.AutoPilot in project translationstudio8 by heartsome.
the class ADXmlHandler method validSrx.
/**
* 验证指定的srx文件是否符合srx标准,通过验证其根元素是否为srx
* @param srxLoaction
* @return ;
*/
public boolean validSrx(String srxLoaction) {
VTDNav vn = super.getVTDNav(srxLoaction);
AutoPilot ap = new AutoPilot(vn);
try {
ap.selectXPath("/srx");
if (ap.evalXPath() != -1) {
return true;
}
} catch (Exception e) {
LOGGER.error("", e);
return false;
}
return false;
}
use of com.ximpleware.AutoPilot in project translationstudio8 by heartsome.
the class ADXmlHandler method getMapRuleNames.
/**
* 获取srx文件所有的映射节点名称
* @param srxLocation
* @return ;
*/
public List<String[]> getMapRuleNames(String srxLocation) {
List<String[]> mapRuleNames = new LinkedList<String[]>();
VTDNav vn = super.getVTDNav(srxLocation);
AutoPilot ap = new AutoPilot(vn);
try {
ap.selectXPath("/srx/body/maprules/maprule");
while (ap.evalXPath() != -1) {
if (vn.getAttrVal("maprulename") != -1) {
mapRuleNames.add(new String[] { "" + (mapRuleNames.size() + 1), vn.toString(vn.getAttrVal("maprulename")) });
}
}
} catch (Exception e) {
LOGGER.error("", e);
}
return mapRuleNames;
}
use of com.ximpleware.AutoPilot in project translationstudio8 by heartsome.
the class ADXmlHandler method addMapRules.
/**
* 分段规则中,添加映射规则
* @param srxLoaction
* @param mapRulesData
* @param mapRuleName
* @return true:添加成功,false:添加失败;
*/
public boolean addMapRules(String srxLoaction, String mapRulesData) {
VTDNav vn = super.getVTDNav(srxLoaction);
AutoPilot ap = new AutoPilot(vn);
//在添加之前,先判断body与maprules节点是否存在,如果存在,则创建
try {
//在添加之前,先判断body节点是否存在,如果不存在,则创建
ap.selectXPath("/srx/body");
if (ap.evalXPath() == -1) {
String bodyStr = "\t<body>\n\t</body>";
if (super.addDataToXml(srxLoaction, "/srx", bodyStr)) {
vn = super.getVTDNav(srxLoaction);
}
}
ap.resetXPath();
//若无languagerule节点存在,创建此节点
ap.selectXPath("/srx/body/maprules");
if (ap.evalXPath() == -1) {
String langRuleStr = "\t<maprules>\n" + "\t\t</maprules>";
if (super.addDataToXml(srxLoaction, "/srx/body", langRuleStr)) {
vn = super.getVTDNav(srxLoaction);
}
}
ap.resetXPath();
return super.addDataToXml(srxLoaction, "/srx/body/maprules", mapRulesData);
} catch (Exception e) {
LOGGER.error("", e);
}
return false;
}
use of com.ximpleware.AutoPilot in project translationstudio8 by heartsome.
the class ADXmlHandler method validNodeExist.
/**
* 验证给出的xpath所表示的节点是否存在,如果存在,则返回true,如果不存在,则返回false
* @param xmlLoaction
* @param validXpath
* @return ;
*/
public boolean validNodeExist(String xmlLocation, String validXpath) {
VTDNav vn = super.getVTDNav(xmlLocation);
AutoPilot ap = new AutoPilot(vn);
try {
ap.selectXPath(validXpath);
if (ap.evalXPath() != -1) {
return true;
}
} catch (Exception e) {
LOGGER.error("", e);
}
return false;
}
use of com.ximpleware.AutoPilot in project translationstudio8 by heartsome.
the class ExportDocx method addTagRIdToRels.
/**
* 给标记的 r:id 属性添加关系申明
*/
private void addTagRIdToRels() throws Exception {
VTDGen vg = new VTDGen();
String docRelsPath = docxFolderPath + File.separator + "word" + File.separator + "_rels" + File.separator + "document.xml.rels";
boolean parseResult = vg.parseFile(docRelsPath, true);
if (!parseResult) {
throw new Exception(MessageFormat.format("文件{0}解析失败!", new Object[] { docRelsPath }));
}
VTDNav vn = vg.getNav();
AutoPilot ap = new AutoPilot(vn);
XMLModifier xm = new XMLModifier(vn);
ap.selectXPath("/Relationships");
if (ap.evalXPath() != -1) {
String tagRelationShip = "<Relationship Id=\"" + tagRId + "\" Type=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink\" Target=\"http://null\" TargetMode=\"External\"/>";
xm.insertBeforeTail(tagRelationShip);
xm.output(docRelsPath);
}
}
Aggregations