Search in sources :

Example 11 with AutoPilot

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

the class VTDUtils method getElementContent.

/**
	 * 得到指定节点的完整内容,包含子节点及文本。若无文本内容返回 null。
	 * @param xpath
	 *            指定节点的XPath。
	 * @throws XPathParseException
	 * @throws XPathEvalException
	 * @throws NavException
	 * @exception XPathParseException
	 *                ,XPathEvalException,NavException
	 */
public String getElementContent(String xpath) throws NavException, XPathParseException, XPathEvalException {
    String text = null;
    if (xpath != null && !xpath.equals("")) {
        AutoPilot ap = new AutoPilot(vn);
        ap.selectXPath(xpath);
        vn.push();
        if (ap.evalXPath() != -1) {
            text = getElementContent();
        }
        vn.pop();
    }
    return text;
}
Also used : AutoPilot(com.ximpleware.AutoPilot)

Example 12 with AutoPilot

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

the class VTDUtils method getChildContent.

/**
	 * 获取当前节点下所有指定元素名称的文本内容,含内部标记等子节点内容。
	 * @param elementName
	 *            子节点名称
	 * @return String 指定子节点内容,无内容返回 null。
	 * @throws XPathParseException
	 * @throws NavException
	 * @throws XPathEvalException
	 */
public String getChildContent(String elementName) throws XPathParseException, XPathEvalException, NavException {
    String text = null;
    AutoPilot ap = new AutoPilot(vn);
    ap.selectXPath("./" + elementName);
    vn.push();
    if (ap.evalXPath() != -1) {
        text = getElementContent();
    }
    vn.pop();
    return text;
}
Also used : AutoPilot(com.ximpleware.AutoPilot)

Example 13 with AutoPilot

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

the class VTDUtils method getChildElementsCount.

/**
	 * 返回当前节点下一级子节点的个数。
	 * @return
	 * @throws XPathParseException
	 * @throws XPathEvalException
	 * @throws NavException
	 *             ;
	 */
public int getChildElementsCount() throws XPathParseException, XPathEvalException, NavException {
    int result = 0;
    AutoPilot ap = new AutoPilot(vn);
    ap.selectXPath("./*");
    vn.push();
    while (ap.evalXPath() != -1) {
        result++;
    }
    vn.pop();
    return result;
}
Also used : AutoPilot(com.ximpleware.AutoPilot)

Example 14 with AutoPilot

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

the class XliffReader method ananysisTag.

private void ananysisTag(Map<Integer, String[]> targetMap) throws VTDException {
    VTDNav vn = vu.getVTDNav();
    vn.push();
    int idex = vn.getCurrentIndex();
    String tagName = vn.toString(idex);
    if ("g".equals(tagName)) {
        String ctype = vu.getCurrentElementAttribut("ctype", null);
        String rpr = vu.getCurrentElementAttribut("rPr", "");
        AutoPilot ap = new AutoPilot(vn);
        ap.selectXPath("./node() | text()");
        while (ap.evalXPath() != -1) {
            idex = vn.getCurrentIndex();
            int tokenType = vn.getTokenType(idex);
            if (tokenType == 0) {
                String name = vu.getCurrentElementName();
                if ("ph".equals(name)) {
                    targetMap.put(idex, new String[] { vu.getElementContent(), rpr, ctype });
                } else if ("g".equals(name)) {
                    ananysisTag(targetMap);
                }
            } else if (tokenType == 5) {
                targetMap.put(idex, new String[] { vn.toRawString(idex), rpr, ctype });
            }
        }
    } else if ("ph".equals(tagName)) {
        targetMap.put(idex, new String[] { vu.getElementContent(), null, null });
    } else {
        // 其他节点,一律当做字符串处理
        targetMap.put(idex, new String[] { vu.getElementFragment(), null, null });
    }
    vn.pop();
}
Also used : AutoPilot(com.ximpleware.AutoPilot) VTDNav(com.ximpleware.VTDNav)

Example 15 with AutoPilot

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

the class ArrangeTTX method getRawTextToken.

/**
	 * 取出 Raw 节点下的文本子节点的 token 值进行存放,单独进行处理
	 */
private void getRawTextToken() throws Exception {
    AutoPilot ap = new AutoPilot(sklVN);
    String xpath = "/TRADOStag/Body/Raw/text()";
    ap.selectXPath(xpath);
    while (ap.evalXPath() != -1) {
        rawTextTokenList.add(sklVN.getCurrentIndex());
    }
}
Also used : AutoPilot(com.ximpleware.AutoPilot)

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