use of com.ximpleware.NavException in project translationstudio8 by heartsome.
the class DeleteSelectionSegmentNotesHandler method execute.
public Object execute(ExecutionEvent event) throws ExecutionException {
IEditorPart editor = HandlerUtil.getActiveEditor(event);
if (!(editor instanceof XLIFFEditorImplWithNatTable)) {
return null;
}
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
boolean res = MessageDialog.openConfirm(window.getShell(), Messages.getString("handler.DeleteSelectionSegmentNotesHandler.msgTitle1"), Messages.getString("handler.DeleteSelectionSegmentNotesHandler.msg1"));
if (res) {
XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor;
XLFHandler handler = xliffEditor.getXLFHandler();
List<String> lstRowId = xliffEditor.getSelectedRowIds();
// 先将应用范围为当前文本段的批注删除
handler.deleteEditableSegmentNote(lstRowId);
try {
HashMap<String, Vector<NoteBean>> mapNote = new HashMap<String, Vector<NoteBean>>();
for (String rowId : lstRowId) {
// 删除应用范围为所有文本段的批注
Vector<NoteBean> noteBeans = xliffEditor.getXLFHandler().getNotes(rowId);
if (noteBeans != null && noteBeans.size() > 0) {
mapNote.put(rowId, noteBeans);
}
}
xliffEditor.getXLFHandler().deleteNote(mapNote);
} catch (NavException e) {
LOGGER.error("", e);
MessageDialog.openInformation(HandlerUtil.getActiveShell(event), Messages.getString("handler.DeleteSelectionSegmentNotesHandler.msgTitle2"), Messages.getString("handler.DeleteSelectionSegmentNotesHandler.msg2"));
} catch (XPathParseException e) {
LOGGER.error("", e);
MessageDialog.openInformation(HandlerUtil.getActiveShell(event), Messages.getString("handler.DeleteSelectionSegmentNotesHandler.msgTitle2"), Messages.getString("handler.DeleteSelectionSegmentNotesHandler.msg2"));
} catch (XPathEvalException e) {
LOGGER.error("", e);
MessageDialog.openInformation(HandlerUtil.getActiveShell(event), Messages.getString("handler.DeleteSelectionSegmentNotesHandler.msgTitle2"), Messages.getString("handler.DeleteSelectionSegmentNotesHandler.msg2"));
} finally {
xliffEditor.refresh();
}
}
return null;
}
use of com.ximpleware.NavException in project translationstudio8 by heartsome.
the class QAXmlHandler method getLanguages.
/**
* 得到所有语言对 备注:重复,从XLFHandler.java中拷取
* @return 语言对的Map<br/>
* key: 源语言;value: 对应的目标语言(可以是多个)
*/
public Map<String, ArrayList<String>> getLanguages() {
TreeMap<String, ArrayList<String>> languages = new TreeMap<String, ArrayList<String>>();
AutoPilot ap = new AutoPilot();
ap.declareXPathNameSpace("xml", VTDUtils.XML_NAMESPACE_URL);
ap.declareXPathNameSpace(hsNSPrefix, hsR7NSUrl);
VTDUtils vu = new VTDUtils();
for (VTDNav vn : vnMap.values()) {
ap.bind(vn);
try {
vu.bind(vn);
ap.selectXPath("/xliff/file");
while (ap.evalXPath() != -1) {
String srcLanguage = vu.getCurrentElementAttribut("source-language", null);
String tgtLanguage = vu.getCurrentElementAttribut("target-language", null);
if (srcLanguage == null) {
// TODO 该file节点不存在“source-language”属性,提醒添加
continue;
}
if (tgtLanguage == null) {
// TODO 该file节点不存在“target-language”属性,提醒添加
continue;
}
ArrayList<String> tgtLanguages = languages.get(srcLanguage);
if (tgtLanguages == null) {
tgtLanguages = new ArrayList<String>();
languages.put(srcLanguage, tgtLanguages);
}
if (!tgtLanguages.contains(tgtLanguage)) {
// 未包含,就添加进去
tgtLanguages.add(tgtLanguage);
}
}
} 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);
} catch (NavException e) {
e.printStackTrace();
logger.error(Messages.getString("qa.QAXmlHandler.logger11"), e);
}
}
return languages;
}
use of com.ximpleware.NavException in project translationstudio8 by heartsome.
the class XLFHandler method getNatTableColumnName.
/**
* 动态取得列名 规则:多个file中如果有相同的source-language和target-language则返回它们的属性值
* 多个file中如果有不同的source-language和target-language则返回“源”和“目标”
* @return source和target的列名集合;
*/
public Hashtable<String, String> getNatTableColumnName() {
Hashtable<String, String> re = new Hashtable<String, String>(2);
AutoPilot ap = new AutoPilot();
ap.declareXPathNameSpace("xml", VTDUtils.XML_NAMESPACE_URL);
ap.declareXPathNameSpace(hsNSPrefix, hsR7NSUrl);
for (VTDNav vn : vnMap.values()) {
ap.bind(vn);
try {
ap.selectXPath("//file");
boolean flag1 = true;
boolean flag2 = true;
String source = null;
String target = null;
while (ap.evalXPath() != -1) {
if (flag1) {
int index1 = vn.getAttrVal("source-language");
if (index1 != -1) {
String tempSource = vn.toNormalizedString(index1);
if (tempSource != null) {
if (source == null) {
source = tempSource;
} else {
if (source.equals(tempSource)) {
flag1 = true;
} else {
source = "源";
flag1 = false;
}
}
}
} else {
source = "源";
flag1 = false;
}
}
if (flag2) {
int index2 = vn.getAttrVal("target-language");
if (index2 != -1) {
String tempTarget = vn.toNormalizedString(index2);
if (tempTarget != null) {
if (target == null) {
target = tempTarget;
} else {
if (target.equals(tempTarget)) {
flag1 = true;
} else {
target = "目标";
flag2 = false;
}
}
}
} else {
target = "目标";
flag2 = false;
}
}
}
re.put("source", source);
re.put("target", target);
return re;
} catch (XPathEvalException e) {
String errorMsg = Messages.getString("file.XLFHandler.logger5");
LOGGER.error(errorMsg, e);
} catch (NavException e) {
String errorMsg = Messages.getString("file.XLFHandler.logger6");
LOGGER.error(errorMsg, e);
} catch (XPathParseException e) {
String errorMsg = Messages.getString("file.XLFHandler.logger7");
LOGGER.error(errorMsg, e);
}
}
return null;
}
use of com.ximpleware.NavException in project translationstudio8 by heartsome.
the class XLFHandler method getAllRowIds.
/**
* 得到所有当前打开的文件包含的 RowId
* @return ;
*/
public List<String> getAllRowIds() {
HashSet<String> allRowIds = new HashSet<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);
ap.selectXPath(XPATH_ALL_TU);
while (ap.evalXPath() != -1) {
String rowId = RowIdUtil.getRowId(vn, fileName);
if (rowId != null) {
allRowIds.add(rowId);
}
}
} catch (NavException e) {
LOGGER.error("", e);
e.printStackTrace();
} catch (XPathParseException e) {
LOGGER.error("", e);
e.printStackTrace();
} catch (XPathEvalException e) {
LOGGER.error("", e);
e.printStackTrace();
}
}
return new ArrayList<String>(allRowIds);
}
use of com.ximpleware.NavException in project translationstudio8 by heartsome.
the class XLFHandler method validateSplitXlf.
/**
* 验证该文件是否符合xliff标准,主要是查看其根元素是否是xliff
* @param xlfPath
* 要验证的Xliff文件路径
* @return robert 2011-10-19
*/
public boolean validateSplitXlf(String xlfPath) {
VTDNav vn = vnMap.get(xlfPath);
Assert.isNotNull(vn, Messages.getString("file.XLFHandler.msg4") + xlfPath);
try {
AutoPilot ap = new AutoPilot(vn);
ap.declareXPathNameSpace(hsNSPrefix, hsR7NSUrl);
ap.selectXPath("/*");
while (ap.evalXPath() != -1) {
if ("xliff".equals(vn.toString(vn.getCurrentIndex()))) {
return true;
}
}
return false;
} catch (XPathParseException e) {
LOGGER.error("", e);
e.printStackTrace();
} catch (XPathEvalException e) {
LOGGER.error("", e);
e.printStackTrace();
} catch (NavException e) {
LOGGER.error("", e);
e.printStackTrace();
}
return false;
}
Aggregations