use of com.ximpleware.XPathEvalException in project translationstudio8 by heartsome.
the class LanguageConfiger method getAllLanguage.
/**
* 返回所有语言列表,key:code,value:<code>Language</code>
*/
public Map<String, Language> getAllLanguage() {
Map<String, Language> result = new HashMap<String, Language>();
AutoPilot tempAp = new AutoPilot(vu.getVTDNav());
String codeAttr = "code";
String bidiAttr = "bidi";
String imgAttr = "image";
String bidiYes = "Yes";
try {
tempAp.selectXPath("/languages/lang");
while (tempAp.evalXPath() != -1) {
Map<String, String> attrs = vu.getCurrentElementAttributs();
String code = attrs.get(codeAttr);
String bidi = attrs.get(bidiAttr);
String img = attrs.get(imgAttr);
String langName = vu.getElementPureText();
boolean isBidi = false;
if (code != null && langName != null) {
if (bidi != null && bidi.equals(bidiYes)) {
isBidi = true;
}
result.put(code, new Language(code, langName, img == null ? "" : img, isBidi));
}
}
} catch (XPathParseException e) {
LOGGER.error("", e);
} catch (XPathEvalException e) {
LOGGER.error("", e);
} catch (NavException e) {
LOGGER.error("", e);
}
return result;
}
use of com.ximpleware.XPathEvalException in project translationstudio8 by heartsome.
the class LanguageConfiger method getLanguageByCode.
/**
* 返回Code对应的Language对象,如果在配置中找到则返回null
* @param code
* @return ;
*/
public Language getLanguageByCode(String code) {
AutoPilot tempAp = new AutoPilot(vu.getVTDNav());
String bidiAttr = "bidi";
String imgAttr = "image";
String bidiYes = "Yes";
try {
tempAp.selectXPath("/languages/lang[@code='" + code + "']");
if (tempAp.evalXPath() != -1) {
Map<String, String> attrs = vu.getCurrentElementAttributs();
String bidi = attrs.get(bidiAttr);
String img = attrs.get(imgAttr);
String langName = vu.getElementPureText();
boolean isBidi = false;
if (code != null && langName != null) {
if (bidi != null && bidi.equals(bidiYes)) {
isBidi = true;
}
return new Language(code, langName, img == null ? "" : img, isBidi);
}
}
} catch (XPathParseException e) {
LOGGER.error("", e);
} catch (XPathEvalException e) {
LOGGER.error("", e);
} catch (NavException e) {
LOGGER.error("", e);
}
return null;
}
use of com.ximpleware.XPathEvalException in project translationstudio8 by heartsome.
the class DocUtils method isTBX.
/**
* 判断是否是正确的 TBX 文件
* @param fileName
* TBX 文件的全路径
* @return 反回null,验证失败
* @throws ParseException
* @throws EntityException
* @throws EOFException
* @throws EncodingException
* @throws FileNotFoundException
*/
public static VTDUtils isTBX(String fileName) throws EncodingException, ParseException, FileNotFoundException {
VTDGen vg = new VTDGen();
FileInputStream fis = null;
File f = null;
try {
f = new File(fileName);
fis = new FileInputStream(f);
byte[] b = new byte[(int) f.length()];
int offset = 0;
int numRead = 0;
// I choose this value randomally,
int numOfBytes = 1048576;
// any other (not too big) value also can be here.
if (b.length - offset < numOfBytes) {
numOfBytes = b.length - offset;
}
while (offset < b.length && (numRead = fis.read(b, offset, numOfBytes)) >= 0) {
offset += numRead;
if (b.length - offset < numOfBytes) {
numOfBytes = b.length - offset;
}
}
vg.setDoc(b);
vg.parse(true);
} catch (IOException e) {
LOGGER.error(Messages.getString("document.DocUtils.logger1"), e);
} finally {
if (fis != null) {
try {
fis.close();
} catch (Exception e) {
}
}
}
VTDNav vn = vg.getNav();
AutoPilot ap = new AutoPilot(vn);
String rootPath = "/martif";
VTDUtils vtdUtils = new VTDUtils();
try {
vtdUtils.bind(vn);
ap.selectXPath(rootPath);
if (ap.evalXPath() == -1) {
// } else {
return null;
}
} catch (NavException e) {
LOGGER.error(Messages.getString("document.DocUtils.logger2"), e);
return null;
} catch (XPathEvalException e) {
LOGGER.error(Messages.getString("document.DocUtils.logger2"), e);
return null;
} catch (XPathParseException e) {
LOGGER.error(Messages.getString("document.DocUtils.logger2"), e);
return null;
} finally {
vg.clear();
}
return vtdUtils;
}
use of com.ximpleware.XPathEvalException in project translationstudio8 by heartsome.
the class XliffUtil method getLangPairOfFile.
/**
* @param xlfFile
* @param filePath
* @return String[] 第一个元素为源语言,第二个为目标语言
*/
public static String[] getLangPairOfFile(String xlfFile, String filePath) {
VTDUtils vu = getVU(xlfFile);
String xpath = "/xliff/file[@original=\"" + filePath + "\"]";
String[] langPair = new String[2];
try {
langPair[0] = vu.getElementAttribute(xpath, "source-language");
langPair[1] = vu.getElementAttribute(xpath, "target-language");
} catch (XPathParseException e) {
e.printStackTrace();
} catch (XPathEvalException e) {
e.printStackTrace();
} catch (NavException e) {
e.printStackTrace();
}
return langPair;
}
use of com.ximpleware.XPathEvalException 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