use of com.ximpleware.AutoPilot in project translationstudio8 by heartsome.
the class ProjectConfiger method getTermBaseDbs.
/**
* 获取项目的所有术语库
* @param isDefault
* 是否获取默认术语库
* @return 数据库参数列表List<DatabaseModelBean> {@link DatabaseModelBean};;
*/
public List<DatabaseModelBean> getTermBaseDbs(boolean isDefault) {
List<DatabaseModelBean> dbList = new ArrayList<DatabaseModelBean>();
try {
AutoPilot ap = new AutoPilot(vu.getVTDNav());
if (isDefault) {
ap.selectXPath("/projectDescription/hs/tb/db[@default='Y']");
} else {
ap.selectXPath("/projectDescription/hs/tb/db");
}
while (ap.evalXPath() != -1) {
DatabaseModelBean dbm = new DatabaseModelBean();
String defaultAttr = vu.getCurrentElementAttribut("default", "N");
if (defaultAttr.equals("Y")) {
dbm.setDefault(true);
} else {
dbm.setDefault(false);
}
dbm.setDbType(vu.getChildContent("type"));
dbm.setDbName(vu.getChildContent("name"));
dbm.setItlDBLocation(vu.getChildContent("location"));
dbm.setInstance(vu.getChildContent("instance"));
dbm.setHost(vu.getChildContent("server"));
dbm.setPort(vu.getChildContent("port"));
dbm.setUserName(vu.getChildContent("user"));
dbm.setPassword(DESImpl.decrypt(vu.getChildContent("password")));
String hasMatch = vu.getChildContent("hasmatch");
if (hasMatch.equals("true")) {
dbm.setHasMatch(true);
} else {
dbm.setHasMatch(false);
}
dbList.add(dbm);
}
} catch (Exception e) {
logger.error(Messages.getString("file.ProjectConfiger.logger2"), e);
return dbList;
}
return dbList;
}
use of com.ximpleware.AutoPilot in project translationstudio8 by heartsome.
the class ProjectConfiger method getDefaultTMDb.
/**
* 获取当前项目的默认的记忆库,default='Y'
* @return 返回{@link DatabaseModelBean};
*/
public DatabaseModelBean getDefaultTMDb() {
try {
AutoPilot ap = new AutoPilot(vu.getVTDNav());
ap.selectXPath("/projectDescription/hs/tm/db[@default='Y']");
if (ap.evalXPath() != -1) {
DatabaseModelBean dbm = new DatabaseModelBean();
dbm.setDefault(true);
dbm.setDbType(vu.getChildContent("type"));
dbm.setDbName(vu.getChildContent("name"));
dbm.setItlDBLocation(vu.getChildContent("location"));
dbm.setInstance(vu.getChildContent("instance"));
dbm.setHost(vu.getChildContent("server"));
dbm.setPort(vu.getChildContent("port"));
dbm.setUserName(vu.getChildContent("user"));
dbm.setPassword(DESImpl.decrypt(vu.getChildContent("password")));
String hasMatch = vu.getChildContent("hasmatch");
if (hasMatch.equals("true")) {
dbm.setHasMatch(true);
} else {
dbm.setHasMatch(false);
}
return dbm;
}
} catch (Exception e) {
logger.error(Messages.getString("file.ProjectConfiger.logger4"), e);
return null;
}
return null;
}
use of com.ximpleware.AutoPilot in project translationstudio8 by heartsome.
the class ProjectConfiger method getFieldMap.
/**
* 获取配置文件中的项目文本字段信息
* @return
* @throws XPathParseException
* @throws XPathEvalException
* @throws NavException ;
*/
private LinkedHashMap<String, String> getFieldMap() throws XPathParseException, XPathEvalException, NavException {
AutoPilot ap = new AutoPilot(vu.getVTDNav());
Map<String, String> mapField = new HashMap<String, String>();
ap.selectXPath("/projectDescription/hs//fieldList/field");
while (ap.evalXPath() != -1) {
String fieldName = TextUtil.stringToXML(vu.getCurrentElementAttribut("name", ""));
String fieldValue = vu.getElementContent();
mapField.put(fieldName, fieldValue);
}
List<Entry<String, String>> lstAttr = new ArrayList<Entry<String, String>>(mapField.entrySet());
final Collator collatorChinese = Collator.getInstance(java.util.Locale.CHINA);
Collections.sort(lstAttr, new Comparator<Entry<String, String>>() {
public int compare(Entry<String, String> arg0, Entry<String, String> arg1) {
return collatorChinese.compare(arg0.getKey(), arg1.getKey());
}
});
LinkedHashMap<String, String> linkedMapAttr = new LinkedHashMap<String, String>();
for (Entry<String, String> entry : lstAttr) {
linkedMapAttr.put(entry.getKey(), entry.getValue());
}
return linkedMapAttr;
}
use of com.ximpleware.AutoPilot in project translationstudio8 by heartsome.
the class QAXmlHandler method getAllRowIdsByLanguages.
/**
* 通过源与目标语言得到所有当前打开的文件包含的 RowId
* ///xliff/file//descendant::trans-unit[(source/text()!='' or source/*)]
* @return ;
*/
public List<String> getAllRowIdsByLanguages(String srcLanguage, String tgtLanguage) {
List<String> allRowIds = new LinkedList<String>();
AutoPilot ap = new AutoPilot();
ap.declareXPathNameSpace("xml", VTDUtils.XML_NAMESPACE_URL);
ap.declareXPathNameSpace(hsNSPrefix, hsR7NSUrl);
VTDUtils vu = new VTDUtils();
for (Entry<String, VTDNav> entry : vnMap.entrySet()) {
String fileName = entry.getKey();
VTDNav vn = entry.getValue();
ap.bind(vn);
try {
vu.bind(vn);
// 查询相同目标与相同源文本的tu
String XPATH_ALL_TU_BYLANGUAGE = "/xliff/file[upper-case(@source-language)=''{0}'' and upper-case(@target-language)=''{1}'']/body/descendant::trans-unit[(source/text()!='''' or source/*)]";
String xpath = MessageFormat.format(XPATH_ALL_TU_BYLANGUAGE, new Object[] { srcLanguage, tgtLanguage });
ap.selectXPath(xpath);
while (ap.evalXPath() != -1) {
String rowId = RowIdUtil.getRowId(vn, fileName);
if (rowId != null) {
allRowIds.add(rowId);
}
}
} catch (NavException e) {
e.printStackTrace();
logger.error(Messages.getString("qa.QAXmlHandler.logger11"), e);
} catch (XPathParseException e) {
e.printStackTrace();
logger.error(Messages.getString("qa.QAXmlHandler.logger9"), e);
} catch (XPathEvalException e) {
e.printStackTrace();
logger.error(Messages.getString("qa.QAXmlHandler.logger10"), e);
}
}
return allRowIds;
}
use of com.ximpleware.AutoPilot in project translationstudio8 by heartsome.
the class QAXmlHandler method getFilteredTUContent.
/**
* 获取trans-unit节点过滤后的source和target节点的文本内容(不去掉标记),过滤条件为不包括上下文匹配,不包括完全匹配,不包括已锁文本,过滤条件在首选项中设置
* @return Map<String, String > 两个键值对,srcContent --> 源文本的文本,tarContent --> 目标文本的文本
* 如果返回的是null,则标志source节点无内容,这对与行号就不自增
*/
public Map<String, String> getFilteredTUContent(String xlfPath, String nodeXpath, Map<String, Boolean> filterMap) {
Map<String, String> tuTextMap = new HashMap<String, String>();
VTDNav vn = vnMap.get(xlfPath);
AutoPilot ap = new AutoPilot(vn);
Assert.isNotNull(vn, Messages.getString("qa.QAXmlHandler.msg1") + xlfPath);
AutoPilot childAp = new AutoPilot(vn);
try {
VTDUtils vUtils = new VTDUtils(vn);
ap.selectXPath(nodeXpath);
while (ap.evalXPath() != -1) {
vn.push();
//取出源文本的纯文本之前,先查看其内容是否为空,若为空,则返回,没有source节点,也返回null
childAp.selectXPath("./source");
if (childAp.evalXPath() != -1) {
//因为标准里面只有一个source,因此此处用if不用while
String srcContent = vUtils.getElementContent();
//如果源文本为空或无值,则返回null
if (srcContent == null || "".equals(srcContent)) {
return null;
}
} else {
return null;
}
childAp.resetXPath();
vn.pop();
//首先过滤,如果有不应包括的文本段,则返回空
if (!filterTheTU(vn, filterMap)) {
return tuTextMap;
}
//下面获取目标文本的纯文本,在之前先检查目标文本是否为空或为空值,若是,则返回null,若没有target节点,也返回空
childAp.selectXPath("./target");
if (childAp.evalXPath() != -1) {
//因为标准里面只有一个target,因此此处用if不用while
String tarContent = vUtils.getElementContent();
//如果源文本为空或无值,则返回null
if (tarContent == null || "".equals(tarContent)) {
return tuTextMap;
} else {
//两个检查项中的忽略标记,若有一项为true,那么就必须获取纯文本
tuTextMap.clear();
}
} else {
return tuTextMap;
}
childAp.resetXPath();
}
} catch (Exception e) {
logger.error(Messages.getString("qa.QAXmlHandler.logger13"), e);
}
return tuTextMap;
}
Aggregations