use of com.ximpleware.AutoPilot 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.AutoPilot in project translationstudio8 by heartsome.
the class TextUtil method plugin_loadCoutries.
/**
* 加载国家名称,针对插件开发模块 robert 2012-03-15
* @param langXMlLC
* @param _languages
* @throws Exception
*/
public static Hashtable<String, String> plugin_loadCoutries() throws Exception {
// 国家文件位置
String countryXmlLC = CoreActivator.ISO3166_1_PAHT;
Hashtable<String, String> _countries = new Hashtable<String, String>();
VTDGen vg = new VTDGen();
vg.setDoc(readBytesFromIS(CoreActivator.getConfigurationFileInputStream(countryXmlLC)));
vg.parse(true);
VTDNav vn = vg.getNav();
AutoPilot ap = new AutoPilot(vn);
AutoPilot childAP = new AutoPilot(vn);
ap.selectXPath("/ISO_3166-1_List_en/ISO_3166-1_Entry");
while (ap.evalXPath() != -1) {
String code = "";
String name = "";
int index;
vn.push();
childAP.selectXPath("./ISO_3166-1_Alpha-2_Code_element");
if (childAP.evalXPath() != -1) {
if ((index = vn.getText()) != -1) {
code = vn.toString(index).trim().toUpperCase();
}
}
vn.pop();
vn.push();
childAP.selectXPath("./ISO_3166-1_Country_name");
if (childAP.evalXPath() != -1) {
if ((index = vn.getText()) != -1) {
name = vn.toString(index).trim();
}
}
vn.pop();
if (!"".equals(code) && !"".equals(name)) {
_countries.put(code, name);
}
}
return _countries;
}
use of com.ximpleware.AutoPilot in project translationstudio8 by heartsome.
the class DeleteResourceAndCloseEditorAction method closeRelatedEditors.
/**
* 删除文件时,如果文件在编辑器中已打开,则关闭此文件。 ;
*/
private void closeRelatedEditors() {
IWorkbenchPage page = null;
for (IWorkbenchWindow window : PlatformUI.getWorkbench().getWorkbenchWindows()) {
if (window != null) {
page = window.getActivePage();
break;
}
}
if (page == null) {
return;
}
IEditorReference[] editorReferences = page.getEditorReferences();
final List<IResource> selectionResource = getSelectedResources();
final List<IEditorReference> lstCloseEditor = new ArrayList<IEditorReference>();
final VTDGen vg = new VTDGen();
final AutoPilot ap = new AutoPilot();
final List<IEditorInput> inputList = new ArrayList<IEditorInput>();
for (final IEditorReference reference : editorReferences) {
Display.getDefault().asyncExec(new Runnable() {
public void run() {
IFile file = ((FileEditorInput) reference.getEditor(true).getEditorInput()).getFile();
if ("xlp".equals(file.getFileExtension())) {
if (vg.parseFile(file.getLocation().toOSString(), true)) {
VTDNav vn = vg.getNav();
ap.bind(vn);
try {
ap.selectXPath("/mergerFiles/mergerFile/@filePath");
int index = -1;
merge: while ((index = ap.evalXPath()) != -1) {
String fileLC = vn.toString(index + 1);
if (fileLC != null && !"".equals(fileLC)) {
for (IResource resource : selectionResource) {
if (resource instanceof IProject || resource instanceof IFolder) {
if (fileLC.startsWith(resource.getLocation().toOSString() + File.separator)) {
lstCloseEditor.add(reference);
inputList.add(reference.getEditorInput());
break merge;
}
} else if (resource instanceof IFile) {
if (resource.getLocation().toOSString().equals(fileLC)) {
lstCloseEditor.add(reference);
inputList.add(reference.getEditorInput());
break merge;
}
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
} else {
try {
for (IResource resource : selectionResource) {
if (resource instanceof IProject) {
if (resource.getLocation().toOSString().equals(file.getProject().getLocation().toOSString())) {
lstCloseEditor.add(reference);
inputList.add(reference.getEditorInput());
break;
}
} else if (resource instanceof IFolder) {
if (file.getLocation().toOSString().startsWith(resource.getLocation().toOSString() + File.separator)) {
lstCloseEditor.add(reference);
inputList.add(reference.getEditorInput());
break;
}
} else if (resource instanceof IFile) {
if (resource.getLocation().toOSString().equals(file.getLocation().toOSString())) {
lstCloseEditor.add(reference);
inputList.add(reference.getEditorInput());
break;
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
});
}
final IWorkbenchPage page2 = page;
Display.getDefault().asyncExec(new Runnable() {
public void run() {
IEditorReference[] arrEditorReference = new IEditorReference[lstCloseEditor.size()];
page2.closeEditors(lstCloseEditor.toArray(arrEditorReference), false);
// 删除文件时,刷新访问记录 robert 2012-11-20
for (IEditorInput input : inputList) {
System.out.println("input = " + input);
CommonFunction.refreshHistoryWhenDelete(input);
}
}
});
}
use of com.ximpleware.AutoPilot in project translationstudio8 by heartsome.
the class XLFValidator method getProjectLang.
/**
* 获取 iFile 所在项目的源语言与目标语言
* @param iFile
* @return 数组中的第一个值为源语言,类型为 Language;第二个值为目标语言集合,类型为 List<Language>
* @throws NavException
* @throws XPathParseException
* @throws XPathEvalException
* ;
*/
private static Object[] getProjectLang(IFile iFile) throws NavException, XPathParseException, XPathEvalException {
String projectFilePath = iFile.getProject().getLocation().toOSString() + System.getProperty("file.separator") + ".config";
if (mapProjectLang.containsKey(projectFilePath)) {
return mapProjectLang.get(projectFilePath);
}
VTDGen vg = new VTDGen();
if (vg.parseFile(projectFilePath, true)) {
VTDNav vn = vg.getNav();
VTDUtils vu = new VTDUtils(vn);
AutoPilot ap = new AutoPilot(vn);
ap.selectXPath("/projectDescription/hs/language/source");
Object[] arrObj = new Object[2];
if (ap.evalXPath() != -1) {
String code = vu.getCurrentElementAttribut("code", "");
String name = vu.getElementContent();
String image = vu.getCurrentElementAttribut("image", "");
String isBidi = vu.getCurrentElementAttribut("isbidi", "No");
arrObj[0] = new Language(code, name, image, isBidi.equals("NO") ? false : true);
}
ap.selectXPath("/projectDescription/hs/language/target");
List<Language> targetLangs = new ArrayList<Language>();
while (ap.evalXPath() != -1) {
String code = vu.getCurrentElementAttribut("code", "");
String name = vu.getElementContent();
String image = vu.getCurrentElementAttribut("image", "");
String isBidi = vu.getCurrentElementAttribut("isbidi", "false");
targetLangs.add(new Language(code, name, image, isBidi.equals("false") ? false : true));
}
arrObj[1] = targetLangs;
return arrObj;
} else {
return null;
}
}
use of com.ximpleware.AutoPilot in project translationstudio8 by heartsome.
the class Txt2Tmx method getSrclangAndTuOffset.
/**
* 获取源语言,计算 tmx 文档的 最后 tu 的偏移,以便附加新内容
* @param file
* @return
*/
private void getSrclangAndTuOffset(String file) throws Exception {
// 检测追加文件的源语言
String appendFileSrcLang = "";
VTDGen vg = new VTDGen();
if (!vg.parseFile(file, true)) {
Exception e = new Exception(Messages.getString("tmxdata.TmxFileContainer.parseTmxFileError"));
LOGGER.error(e.getMessage());
throw e;
}
try {
VTDNav vn = vg.getNav();
AutoPilot ap = new AutoPilot(vn);
ap.selectXPath("/tmx/header/@srclang");
if (ap.evalXPath() != -1) {
appendFileSrcLang = vn.toString(vn.getCurrentIndex() + 1);
} else {
LOGGER.error(Messages.getString("tmxdata.TmxFileContainer.parseTmxFileContentError"));
}
ap.resetXPath();
ap.selectXPath("/tmx/body/tu[last()]");
if (ap.evalXPath() != -1) {
long l = vn.getElementFragment();
int offset = (int) l;
int length = (int) (l >> 32);
appendOffset = offset + length;
}
} catch (Exception e) {
LOGGER.error("程序错误", e);
}
appendSrclang = appendFileSrcLang;
}
Aggregations