Search in sources :

Example 26 with VTDNav

use of com.ximpleware.VTDNav in project translationstudio8 by heartsome.

the class ADXmlHandler method getLanguageRuleNamesOfSrx_2.

/**
	 * 获取语言规则的名称,返回结果为list<String>类型
	 * @param srxLocation
	 * @return ;
	 */
public List<String> getLanguageRuleNamesOfSrx_2(String srxLocation) {
    List<String> langRuleNames = new LinkedList<String>();
    VTDNav vn = super.getVTDNav(srxLocation);
    AutoPilot ap = new AutoPilot(vn);
    try {
        ap.selectXPath("/srx/body/languagerules/languagerule");
        while (ap.evalXPath() != -1) {
            if (vn.getAttrVal("languagerulename") != -1) {
                langRuleNames.add(vn.toString(vn.getAttrVal("languagerulename")));
            }
        }
    } catch (Exception e) {
        LOGGER.error("", e);
    }
    return langRuleNames;
}
Also used : AutoPilot(com.ximpleware.AutoPilot) VTDNav(com.ximpleware.VTDNav) LinkedList(java.util.LinkedList)

Example 27 with VTDNav

use of com.ximpleware.VTDNav 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 28 with VTDNav

use of com.ximpleware.VTDNav 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 29 with VTDNav

use of com.ximpleware.VTDNav 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 30 with VTDNav

use of com.ximpleware.VTDNav 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)

Aggregations

VTDNav (com.ximpleware.VTDNav)206 AutoPilot (com.ximpleware.AutoPilot)177 NavException (com.ximpleware.NavException)128 XPathParseException (com.ximpleware.XPathParseException)115 XPathEvalException (com.ximpleware.XPathEvalException)110 VTDUtils (net.heartsome.xml.vtdimpl.VTDUtils)99 IOException (java.io.IOException)85 ModifyException (com.ximpleware.ModifyException)81 TranscodeException (com.ximpleware.TranscodeException)69 CoreException (org.eclipse.core.runtime.CoreException)69 XMLModifier (com.ximpleware.XMLModifier)53 UnsupportedEncodingException (java.io.UnsupportedEncodingException)49 FileNotFoundException (java.io.FileNotFoundException)46 VTDGen (com.ximpleware.VTDGen)45 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)43 XQException (javax.xml.xquery.XQException)37 LinkedHashMap (java.util.LinkedHashMap)27 ArrayList (java.util.ArrayList)26 HashMap (java.util.HashMap)25 LinkedList (java.util.LinkedList)23