Search in sources :

Example 71 with AutoPilot

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

the class TMXValidator method validTmxRoot.

/**
	 * 通过验证指定文件的头元素是否是TMX,来验证该文件是不是一个TMX文件
	 * @return
	 * @throws Exception ;
	 */
private boolean validTmxRoot(String tmxLocation) throws Exception {
    VTDNav vn = vnMap.get(tmxLocation);
    AutoPilot ap = new AutoPilot(vn);
    Assert.isNotNull(vn, MessageFormat.format(Messages.getString("plugin.TMXValidator.msg11"), tmxLocation));
    ap.selectXPath("/tmx");
    if (ap.evalXPath() != -1) {
        return true;
    }
    return false;
}
Also used : AutoPilot(com.ximpleware.AutoPilot) VTDNav(com.ximpleware.VTDNav)

Example 72 with AutoPilot

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

the class TMX2TXTConverterDialog method getTUCount.

/**
	 * 获取TMX文件的TU节点的总数
	 * @return ;
	 */
private int getTUCount(String tmxLocation) {
    AutoPilot ap = new AutoPilot(vn);
    Assert.isNotNull(vn, MessageFormat.format(Messages.getString("dialog.TMX2TXTConverterDialog.msg8"), tmxLocation));
    try {
        ap.selectXPath("count(/tmx/body/tu)");
        return (int) ap.evalXPathToNumber();
    } catch (Exception e) {
        e.printStackTrace();
        LOGGER.error("", e);
    }
    return 0;
}
Also used : AutoPilot(com.ximpleware.AutoPilot) NavException(com.ximpleware.NavException) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 73 with AutoPilot

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

the class TMX2TXTConverterDialog method processTU.

/**
	 * 开始获取tmx中的tu节点进行添加到TXT文件中
	 * @param txtLocation
	 * @param monitor
	 *            ;
	 */
private IStatus processTU(String tmxLocation, String txtLocation, IProgressMonitor monitor) {
    if (monitor == null) {
        monitor = new NullProgressMonitor();
    }
    monitor.beginTask("", tuNodesCount % workInterval == 0 ? tuNodesCount / workInterval : tuNodesCount / workInterval + 1);
    try {
        int travelIndex = 0;
        AutoPilot ap = new AutoPilot(vn);
        AutoPilot tuvAp = new AutoPilot(vn);
        AutoPilot segAp = new AutoPilot(vn);
        AutoPilot segChildAp = new AutoPilot(vn);
        Assert.isNotNull(vn, MessageFormat.format(Messages.getString("dialog.TMX2TXTConverterDialog.msg8"), tmxLocation));
        ap.selectXPath("/tmx/body/tu");
        segAp.selectXPath("./seg");
        segChildAp.selectXPath("./*");
        while (ap.evalXPath() != -1) {
            travelIndex++;
            writeString("<TrU>\r\n");
            String creationdate = getAttributeValue("creationdate", "");
            if (!creationdate.equals("")) {
                writeString("<CrD>" + creationdate.substring(6, 8) + creationdate.substring(4, 6) + creationdate.substring(0, 4) + ", " + creationdate.substring(9, 11) + ":" + creationdate.substring(11, 13) + ":" + creationdate.substring(13, 15) + "\r\n");
            }
            String creationid = getAttributeValue("creationid", "");
            if (creationid.equals("")) {
                writeString("<CrU>" + System.getProperty("user.name").replaceAll("\\s", "") + "\r\n");
            } else {
                writeString("<CrU>" + creationid + "\r\n");
            }
            String changedate = getAttributeValue("changedate", "");
            if (!changedate.equals("")) {
                writeString("<ChD>" + changedate.substring(6, 8) + changedate.substring(4, 6) + changedate.substring(0, 4) + ", " + changedate.substring(9, 11) + ":" + changedate.substring(11, 13) + ":" + changedate.substring(13, 15) + "\r\n");
            }
            String changeid = getAttributeValue("changeid", "");
            if (!changeid.equals("")) {
                writeString("<ChU>" + changeid + "\r\n");
            }
            // 开始遍历TU节点的子节点:tuv
            tuvAp.selectXPath("./tuv");
            while (tuvAp.evalXPath() != -1) {
                String lang = getAttributeValue("xml:lang", null).toLowerCase();
                String font = "\\f1";
                if (lang.matches("ja.*")) {
                    // Japanese
                    font = "\\f3";
                }
                if (lang.matches("zh.*")) {
                    // Simplified Chinese
                    font = "\\f4";
                }
                if (lang.matches("zh.tw")) {
                    // Traditional Chinese
                    font = "\\f5";
                }
                if (lang.matches("ko.*")) {
                    // Korean
                    font = "\\f6";
                }
                if (lang.matches("pl.*") || lang.matches("cs.*") || lang.matches("bs.*") || lang.matches("sk.*") || lang.matches("sl.*") || lang.matches("hu.*")) {
                    // Eastern European
                    font = "\\f7";
                }
                if (lang.matches("ru.*") || lang.matches("bg.*") || lang.matches("mk.*") || lang.matches("sr.*") || lang.matches("be.*") || lang.matches("uk.*")) {
                    // Russian
                    font = "\\f8";
                }
                if (lang.matches("el.*")) {
                    // Greek
                    font = "\\f9";
                }
                if (lang.matches("tr.*")) {
                    // Turkish
                    font = "\\f10";
                }
                if (lang.matches("he.*") || lang.matches("yi.*")) {
                    // Hebrew
                    font = "\\f11";
                }
                if (lang.matches("ar.*")) {
                    // Arabic
                    font = "\\f12";
                }
                if (lang.matches("lv.*") || lang.matches("lt.*")) {
                    // Baltic
                    font = "\\f13";
                }
                if (lang.matches("th.*")) {
                    // Thai
                    font = "\\f14";
                }
                // 开始遍历tuv节点的子节点seg
                StringBuffer segSB = new StringBuffer();
                vn.push();
                if (segAp.evalXPath() != -1) {
                    if (vn.getText() != -1) {
                        segSB.append(cleanString(vn.toString(vn.getText())));
                    } else {
                        vn.push();
                        while (segChildAp.evalXPath() != -1) {
                            String nodeName = vn.toString(vn.getCurrentIndex());
                            if ("ph".equals(nodeName) || "bpt".equals(nodeName) || "ept".equals(nodeName)) {
                                segSB.append("{\\cs6" + font + "\\cf6\\lang1024 ");
                                String value = "";
                                if (vn.getText() != -1) {
                                    value = vn.toString(vn.getText());
                                }
                                segSB.append(cleanString(value));
                                segSB.append("}");
                            } else {
                                System.out.println("vn.getTokenType(vn.getCurrentIndex()) = " + vn.getTokenType(vn.getCurrentIndex()));
                            }
                        }
                        vn.pop();
                    }
                    writeString("<Seg L=" + lang.toUpperCase() + ">" + segSB.toString() + "\r\n");
                }
                vn.pop();
                segAp.resetXPath();
                segChildAp.resetXPath();
            }
            writeString("</TrU>\r\n");
            if (!monitorWork(monitor, travelIndex, false)) {
                return Status.CANCEL_STATUS;
            }
        }
        if (!monitorWork(monitor, travelIndex, true)) {
            return Status.CANCEL_STATUS;
        }
    } catch (Exception e) {
        e.printStackTrace();
        LOGGER.error("", e);
    }
    monitor.done();
    return Status.OK_STATUS;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) AutoPilot(com.ximpleware.AutoPilot) NavException(com.ximpleware.NavException) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 74 with AutoPilot

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

the class Martif2Tbx method getChildElementPureText.

/**
	 * 得到当前子节点的纯文本。实体会被转义。若无文本内容返回 null。
	 * @exception XPathParseException
	 *                ,XPathEvalException,NavException
	 */
public String getChildElementPureText(VTDNav vn) throws XPathParseException, XPathEvalException, NavException {
    String txtNode = ".//text()";
    AutoPilot ap = new AutoPilot(vn);
    StringBuilder result = new StringBuilder();
    ap.selectXPath(txtNode);
    int txtIndex = -1;
    boolean isNull = true;
    while ((txtIndex = ap.evalXPath()) != -1) {
        result.append(vn.toString(txtIndex));
        if (isNull) {
            isNull = false;
        }
    }
    return isNull ? null : result.toString();
}
Also used : AutoPilot(com.ximpleware.AutoPilot)

Example 75 with AutoPilot

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

the class XliffUtil method getOriginalFiles.

/**
	 * @param vu
	 *            XLIFF 文件对应的 VTDUtils
	 * @return List&lt;String&gt;
	 */
public static List<String> getOriginalFiles(VTDUtils vu) {
    ArrayList<String> list = new ArrayList<String>();
    String xpath = "/xliff/file";
    AutoPilot ap = new AutoPilot(vu.getVTDNav());
    try {
        ap.selectXPath(xpath);
        while (ap.evalXPath() != -1) {
            list.add(vu.getElementAttribute(".", "original"));
        }
    } catch (XPathParseException e) {
        e.printStackTrace();
    } catch (XPathEvalException e) {
        e.printStackTrace();
    } catch (NavException e) {
        e.printStackTrace();
    }
    return list;
}
Also used : XPathParseException(com.ximpleware.XPathParseException) AutoPilot(com.ximpleware.AutoPilot) ArrayList(java.util.ArrayList) XPathEvalException(com.ximpleware.XPathEvalException) NavException(com.ximpleware.NavException)

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