use of com.ximpleware.NavException in project translationstudio8 by heartsome.
the class ExportTbxImpl method filterLangSet.
/**
* 过滤从库中导出的langSet节点<br>
* 在库中TremEntry是以整个节点进行存储的,因此,在导出后也是整个节点导出,所以会将无关的语言也导出来。<br>
* 在导出后,生成的TBX文件中进语言进行过滤
* @param filePath
* 导出后生成的TBX文件路径
* @param srcLang
* 源语言
* @param needLang
* 当前需要导出的语言;
*/
private void filterLangSet(String filePath, String srcLang, List<String> needLang) {
try {
VTDGen vg = new VTDGen();
if (vg.parseFile(filePath, true)) {
VTDUtils vu = new VTDUtils(vg.getNav());
StringBuffer xpath = new StringBuffer("/martif/text/body/termEntry/langSet[");
String noteXpathtemp = "starts-with(@id,'__LANG__,') or ends-with(@id,',__LANG__')";
StringBuffer noteTgtXpath = new StringBuffer();
for (String lang : needLang) {
xpath.append("not(@xml:lang='" + lang + "') and ");
if (!lang.equals(srcLang)) {
noteTgtXpath.append(noteXpathtemp.replace("__LANG__", lang)).append(" or ");
}
}
String tgtLangXpath = noteTgtXpath.substring(0, noteTgtXpath.lastIndexOf("or"));
StringBuffer noteXpath = new StringBuffer();
noteXpath.append("/martif/text/body/termEntry/note[");
noteXpath.append("not(");
noteXpath.append("(").append(noteXpathtemp.replace("__LANG__", srcLang)).append(")");
noteXpath.append(" and ");
noteXpath.append("(").append(tgtLangXpath).append(")");
noteXpath.append(")");
noteXpath.append("]");
String xpathStr = xpath.substring(0, xpath.lastIndexOf("and")) + "]";
XMLModifier xm = new XMLModifier(vu.getVTDNav());
AutoPilot ap = new AutoPilot(vu.getVTDNav());
ap.declareXPathNameSpace("xml", VTDUtils.XML_NAMESPACE_URL);
xm = vu.delete(ap, xm, xpathStr, VTDUtils.PILOT_TO_END);
xm = vu.delete(ap, xm, noteXpath.toString(), VTDUtils.PILOT_TO_END);
FileOutputStream fos = new FileOutputStream(filePath);
BufferedOutputStream bos = new BufferedOutputStream(fos);
// 写入文件
xm.output(bos);
bos.close();
fos.close();
}
} catch (NavException e) {
logger.error("", e);
e.printStackTrace();
} catch (ModifyException e) {
logger.error("", e);
e.printStackTrace();
} catch (FileNotFoundException e) {
logger.error("", e);
e.printStackTrace();
} catch (TranscodeException e) {
logger.error("", e);
e.printStackTrace();
} catch (IOException e) {
logger.error("", e);
e.printStackTrace();
}
}
use of com.ximpleware.NavException in project translationstudio8 by heartsome.
the class TextUtil method loadISOLang.
private static void loadISOLang(String strLangFile) {
if (strLangFile == null) {
return;
}
ISOLang = new Hashtable<String, String>();
VTDGen vg = new VTDGen();
// vg.setDoc(strLangFile.getBytes());
try {
vg.setDoc(readBytesFromIS(CoreActivator.getConfigurationFileInputStream(strLangFile)));
vg.parse(true);
VTDNav vn = vg.getNav();
VTDUtils vu = new VTDUtils(vn);
AutoPilot ap = new AutoPilot(vn);
ap.selectXPath("/languages/lang");
int codeIndex;
String code = null;
String langName;
while ((ap.evalXPath()) != -1) {
codeIndex = vn.getAttrVal("code");
if (codeIndex != -1) {
code = vn.toString(codeIndex);
}
langName = vu.getElementPureText();
if (code != null && langName != null) {
ISOLang.put(code, langName);
}
}
ap.resetXPath();
} catch (NavException e) {
if (LOGGER.isErrorEnabled()) {
String msg = Messages.getString("util.TextUtil.logger1");
Object[] args = { strLangFile };
LOGGER.error(new MessageFormat(msg).format(args), e);
}
} catch (XPathParseException e) {
if (LOGGER.isErrorEnabled()) {
String msg = Messages.getString("util.TextUtil.logger1");
Object[] args = { strLangFile };
LOGGER.error(new MessageFormat(msg).format(args), e);
}
} catch (XPathEvalException e) {
if (LOGGER.isErrorEnabled()) {
String msg = Messages.getString("util.TextUtil.logger1");
Object[] args = { strLangFile };
LOGGER.error(new MessageFormat(msg).format(args), e);
}
} catch (EncodingException e) {
if (LOGGER.isErrorEnabled()) {
String msg = Messages.getString("util.TextUtil.logger1");
Object[] args = { strLangFile };
LOGGER.error(new MessageFormat(msg).format(args), e);
}
} catch (EOFException e) {
if (LOGGER.isErrorEnabled()) {
String msg = Messages.getString("util.TextUtil.logger1");
Object[] args = { strLangFile };
LOGGER.error(new MessageFormat(msg).format(args), e);
}
} catch (EntityException e) {
if (LOGGER.isErrorEnabled()) {
String msg = Messages.getString("util.TextUtil.logger1");
Object[] args = { strLangFile };
LOGGER.error(new MessageFormat(msg).format(args), e);
}
} catch (ParseException e) {
if (LOGGER.isErrorEnabled()) {
String msg = Messages.getString("util.TextUtil.logger1");
Object[] args = { strLangFile };
LOGGER.error(new MessageFormat(msg).format(args), e);
}
} catch (IOException e) {
if (LOGGER.isErrorEnabled()) {
String msg = Messages.getString("util.TextUtil.logger1");
Object[] args = { strLangFile };
LOGGER.error(new MessageFormat(msg).format(args), e);
}
} finally {
vg.clear();
}
}
use of com.ximpleware.NavException in project translationstudio8 by heartsome.
the class TextUtil method loadLanguages.
private static void loadLanguages() {
descriptions = null;
isBidi = null;
descriptions = new Hashtable<String, String>();
isBidi = new Hashtable<String, String>();
String strFile = CoreActivator.LANGUAGE_CODE_PATH;
VTDGen vg = new VTDGen();
try {
vg.setDoc(readBytesFromIS(CoreActivator.getConfigurationFileInputStream(strFile)));
vg.parse(true);
VTDNav vn = vg.getNav();
VTDUtils vu = new VTDUtils(vn);
AutoPilot ap = new AutoPilot(vn);
ap.selectXPath("/languages/lang");
int codeIndex;
String code = null;
int bidiIndex;
String bidi = null;
String langName;
while ((ap.evalXPath()) != -1) {
codeIndex = vn.getAttrVal("code");
if (codeIndex != -1) {
code = vn.toString(codeIndex);
}
bidiIndex = vn.getAttrVal("bidi");
if (bidiIndex != -1) {
bidi = vn.toString(bidiIndex);
}
langName = vu.getElementPureText();
if (code != null && langName != null) {
descriptions.put(code, langName);
}
if (code != null && bidi != null) {
isBidi.put(code, bidi);
}
}
ap.resetXPath();
} catch (NavException e) {
if (LOGGER.isErrorEnabled()) {
String msg = Messages.getString("util.TextUtil.logger1");
Object[] args = { strFile };
LOGGER.error(new MessageFormat(msg).format(args), e);
}
} catch (XPathParseException e) {
if (LOGGER.isErrorEnabled()) {
String msg = Messages.getString("util.TextUtil.logger1");
Object[] args = { strFile };
LOGGER.error(new MessageFormat(msg).format(args), e);
}
} catch (XPathEvalException e) {
if (LOGGER.isErrorEnabled()) {
String msg = Messages.getString("util.TextUtil.logger1");
Object[] args = { strFile };
LOGGER.error(new MessageFormat(msg).format(args), e);
}
} catch (EncodingException e) {
if (LOGGER.isErrorEnabled()) {
String msg = Messages.getString("util.TextUtil.logger1");
Object[] args = { strFile };
LOGGER.error(new MessageFormat(msg).format(args), e);
}
} catch (EOFException e) {
if (LOGGER.isErrorEnabled()) {
String msg = Messages.getString("util.TextUtil.logger1");
Object[] args = { strFile };
LOGGER.error(new MessageFormat(msg).format(args), e);
}
} catch (EntityException e) {
if (LOGGER.isErrorEnabled()) {
String msg = Messages.getString("util.TextUtil.logger1");
Object[] args = { strFile };
LOGGER.error(new MessageFormat(msg).format(args), e);
}
} catch (ParseException e) {
if (LOGGER.isErrorEnabled()) {
String msg = Messages.getString("util.TextUtil.logger1");
Object[] args = { strFile };
LOGGER.error(new MessageFormat(msg).format(args), e);
}
} catch (IOException e) {
if (LOGGER.isErrorEnabled()) {
String msg = Messages.getString("util.TextUtil.logger1");
Object[] args = { strFile };
LOGGER.error(new MessageFormat(msg).format(args), e);
}
} finally {
vg.clear();
}
}
use of com.ximpleware.NavException in project translationstudio8 by heartsome.
the class TextUtil method loadCountries.
private static void loadCountries() {
String strFile = CoreActivator.ISO3166_1_PAHT;
countries = new Hashtable<String, String>();
VTDGen vg = new VTDGen();
try {
vg.setDoc(readBytesFromIS(CoreActivator.getConfigurationFileInputStream(strFile)));
vg.parse(true);
VTDNav vn = vg.getNav();
VTDUtils vu = new VTDUtils(vn);
AutoPilot ap = new AutoPilot(vn);
ap.selectXPath("/ISO_3166-1_List_en/ISO_3166-1_Entry");
while ((ap.evalXPath()) != -1) {
countries.put(vu.getChildContent("ISO_3166-1_Alpha-2_Code_element"), vu.getChildContent("ISO_3166-1_Country_name"));
}
ap.resetXPath();
} catch (NavException e) {
if (LOGGER.isErrorEnabled()) {
String msg = Messages.getString("util.TextUtil.logger1");
Object[] args = { strFile };
LOGGER.error(new MessageFormat(msg).format(args), e);
}
} catch (XPathParseException e) {
if (LOGGER.isErrorEnabled()) {
String msg = Messages.getString("util.TextUtil.logger1");
Object[] args = { strFile };
LOGGER.error(new MessageFormat(msg).format(args), e);
}
} catch (XPathEvalException e) {
if (LOGGER.isErrorEnabled()) {
String msg = Messages.getString("util.TextUtil.logger1");
Object[] args = { strFile };
LOGGER.error(new MessageFormat(msg).format(args), e);
}
} catch (EncodingException e) {
if (LOGGER.isErrorEnabled()) {
String msg = Messages.getString("util.TextUtil.logger1");
Object[] args = { strFile };
LOGGER.error(new MessageFormat(msg).format(args), e);
}
} catch (EOFException e) {
if (LOGGER.isErrorEnabled()) {
String msg = Messages.getString("util.TextUtil.logger1");
Object[] args = { strFile };
LOGGER.error(new MessageFormat(msg).format(args), e);
}
} catch (EntityException e) {
if (LOGGER.isErrorEnabled()) {
String msg = Messages.getString("util.TextUtil.logger1");
Object[] args = { strFile };
LOGGER.error(new MessageFormat(msg).format(args), e);
}
} catch (ParseException e) {
if (LOGGER.isErrorEnabled()) {
String msg = Messages.getString("util.TextUtil.logger1");
Object[] args = { strFile };
LOGGER.error(new MessageFormat(msg).format(args), e);
}
} catch (IOException e) {
if (LOGGER.isErrorEnabled()) {
String msg = Messages.getString("util.TextUtil.logger1");
Object[] args = { strFile };
LOGGER.error(new MessageFormat(msg).format(args), e);
}
} finally {
vg.clear();
}
}
use of com.ximpleware.NavException in project translationstudio8 by heartsome.
the class DatabaseConfiger method getServersConfigByType.
/**
* 获取指定类型数据库的所有服务器配置信息
* @param type
* 数据库类型
* @return ;
*/
public List<DatabaseModelBean> getServersConfigByType(String type) {
List<DatabaseModelBean> list = new ArrayList<DatabaseModelBean>();
try {
vu.getVTDNav().push();
ap.selectXPath("/servers/server[@type='" + type + "']");
while (ap.evalXPath() != -1) {
DatabaseModelBean dbm = new DatabaseModelBean();
dbm.setId(vu.getCurrentElementAttribut("id", ""));
dbm.setItlDBLocation(vu.getChildContent("location"));
dbm.setInstance(vu.getChildContent("instance"));
dbm.setHost(vu.getChildContent("host"));
dbm.setPort(vu.getChildContent("port"));
dbm.setUserName(vu.getChildContent("user"));
dbm.setPassword(DESImpl.decrypt(vu.getChildContent("password")));
dbm.setDbType(type);
list.add(dbm);
}
ap.resetXPath();
vu.getVTDNav().pop();
} catch (XPathParseException e) {
logger.error("", e);
} catch (XPathEvalException e) {
logger.error("", e);
} catch (NavException e) {
logger.error("", e);
}
return list;
}
Aggregations