Search in sources :

Example 61 with AutoPilot

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;
}
Also used : AutoPilot(com.ximpleware.AutoPilot) VTDNav(com.ximpleware.VTDNav)

Example 62 with AutoPilot

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;
}
Also used : AutoPilot(com.ximpleware.AutoPilot) VTDNav(com.ximpleware.VTDNav) LinkedList(java.util.LinkedList)

Example 63 with AutoPilot

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;
}
Also used : AutoPilot(com.ximpleware.AutoPilot) VTDNav(com.ximpleware.VTDNav)

Example 64 with AutoPilot

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;
}
Also used : AutoPilot(com.ximpleware.AutoPilot) VTDNav(com.ximpleware.VTDNav)

Example 65 with AutoPilot

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);
    }
}
Also used : XMLModifier(com.ximpleware.XMLModifier) AutoPilot(com.ximpleware.AutoPilot) VTDGen(com.ximpleware.VTDGen) VTDNav(com.ximpleware.VTDNav)

Aggregations

AutoPilot (com.ximpleware.AutoPilot)308 VTDNav (com.ximpleware.VTDNav)173 NavException (com.ximpleware.NavException)150 XPathParseException (com.ximpleware.XPathParseException)145 XPathEvalException (com.ximpleware.XPathEvalException)137 VTDUtils (net.heartsome.xml.vtdimpl.VTDUtils)112 IOException (java.io.IOException)103 ModifyException (com.ximpleware.ModifyException)95 TranscodeException (com.ximpleware.TranscodeException)82 CoreException (org.eclipse.core.runtime.CoreException)76 UnsupportedEncodingException (java.io.UnsupportedEncodingException)58 VTDGen (com.ximpleware.VTDGen)50 FileNotFoundException (java.io.FileNotFoundException)49 XMLModifier (com.ximpleware.XMLModifier)46 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)44 ArrayList (java.util.ArrayList)42 HashMap (java.util.HashMap)39 XQException (javax.xml.xquery.XQException)37 LinkedHashMap (java.util.LinkedHashMap)34 LinkedList (java.util.LinkedList)25