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;
}
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;
}
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;
}
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();
}
use of com.ximpleware.AutoPilot in project translationstudio8 by heartsome.
the class XliffUtil method getOriginalFiles.
/**
* @param vu
* XLIFF 文件对应的 VTDUtils
* @return List<String>
*/
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;
}
Aggregations