use of com.ximpleware.XPathEvalException in project translationstudio8 by heartsome.
the class XLFHandler method saveAsHtml.
/**
* 存为HTML
* @param fileName
* @param out
* @param elementName
* @return ;
*/
public boolean saveAsHtml(String fileName, String out, String elementName) {
BufferedOutputStream bos = null;
try {
bos = new BufferedOutputStream(new FileOutputStream(out));
//$NON-NLS-1$
bos.write("<html>\n".getBytes());
//$NON-NLS-1$
bos.write(" <head>\n".getBytes());
//$NON-NLS-1$
bos.write(" <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\n".getBytes());
//$NON-NLS-1$ //$NON-NLS-2$
bos.write((" <title>" + fileName + "</title>\n").getBytes());
//$NON-NLS-1$
bos.write(" </head>\n".getBytes());
//$NON-NLS-1$
bos.write("<body>\n".getBytes());
VTDNav vn = vnMap.get(fileName);
AutoPilot ap = new AutoPilot(vn);
VTDUtils vu = new VTDUtils(vn);
ap.selectXPath("/xliff/file");
while (ap.evalXPath() != -1) {
AutoPilot subAp = new AutoPilot(vn);
subAp.selectXPath("descendant::trans-unit[source/text()!='']");
while (subAp.evalXPath() != -1) {
if ("target".equals(elementName)) {
String approvedValue = vu.getValue("./@approved");
approvedValue = approvedValue == null ? "no" : approvedValue;
if (!"yes".equalsIgnoreCase(approvedValue)) {
// 未批准
continue;
}
}
String value = vu.getValue("./" + elementName + "/text()");
if (value != null) {
bos.write(("<p>" + value + "</p>\n").getBytes());
}
}
}
bos.write("</body>\n</html>\n".getBytes());
return true;
} catch (FileNotFoundException e) {
LOGGER.error("", e);
e.printStackTrace();
return false;
} catch (IOException e) {
LOGGER.error("", e);
e.printStackTrace();
return false;
} catch (NavException e) {
LOGGER.error("", e);
e.printStackTrace();
return false;
} catch (XPathParseException e) {
LOGGER.error("", e);
e.printStackTrace();
return false;
} catch (XPathEvalException e) {
LOGGER.error("", e);
e.printStackTrace();
return false;
} finally {
if (bos != null) {
try {
bos.close();
} catch (IOException e) {
LOGGER.error("", e);
e.printStackTrace();
}
}
}
}
use of com.ximpleware.XPathEvalException in project translationstudio8 by heartsome.
the class XLFHandler method getCaseTgtContent.
/** burke 为修改锁定行目标文本不能修改其大小写添加 getCaseTgtContent方法 */
/**
* 获取要改变大小写的target中的文本内容
* @param rowId
* @return
*/
public String getCaseTgtContent(String rowId) {
AutoPilot ap = new AutoPilot();
VTDNav vn = null;
vn = getVTDNavByRowId(rowId);
ap.bind(vn);
try {
String tuXPath = RowIdUtil.parseRowIdToXPath(rowId);
ap.selectXPath(tuXPath);
if (ap.evalXPath() != -1) {
int attrIndex = vn.getAttrVal("translate");
if (attrIndex != -1) {
String attrValue = vn.toString(attrIndex);
if (attrValue.equals("no")) {
return "no";
}
}
}
ap.resetXPath();
} catch (XPathEvalException e) {
LOGGER.error("", e);
e.printStackTrace();
} catch (NavException e) {
LOGGER.error("", e);
e.printStackTrace();
} catch (XPathParseException e) {
LOGGER.error("", e);
e.printStackTrace();
}
String tgt = getTgtContent(rowId);
return tgt;
}
use of com.ximpleware.XPathEvalException in project translationstudio8 by heartsome.
the class ProjectConfiger method getCurrentProjectConfig.
/**
* 获取项目配置信息
* @return 指定项目配置文件中的所有信息;
*/
public ProjectInfoBean getCurrentProjectConfig() {
ProjectInfoBean bean = new ProjectInfoBean();
vu.getVTDNav().push();
AutoPilot hsAp = new AutoPilot(vu.getVTDNav());
try {
hsAp.selectXPath("/projectDescription/hs");
if (hsAp.evalXPath() != -1) {
bean.setProjectName(getProjectName());
bean.setMapField(getFieldMap());
bean.setMapAttr(getAttrMap());
bean.setSourceLang(getSourceLanguage());
bean.setTargetLang(getTargetlanguages());
bean.setTmDb(getAllTmDbs());
bean.setTbDb(getTermBaseDbs(false));
}
} catch (XPathParseException e) {
logger.error("", e);
} catch (XPathEvalException e) {
logger.error("", e);
} catch (NavException e) {
logger.error("", e);
}
vu.getVTDNav().pop();
return bean;
}
use of com.ximpleware.XPathEvalException 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.XPathEvalException 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;
}
Aggregations