use of com.ximpleware.AutoPilot in project translationstudio8 by heartsome.
the class ApplicationWorkbenchWindowAdvisor method restorEditorHistory.
/**
* 重新恢复产品上次退时出所保存的编辑器,此修复针对 mac 下的 bug 2998 启动:某客户安装的软件只能使用一次. robert 2013-05-21
*/
private void restorEditorHistory() {
// 只针对 mac 下的用户
if (System.getProperty("os.name").indexOf("Mac") == -1) {
return;
}
final WorkbenchPage page = (WorkbenchPage) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IRunnableWithProgress runnable = new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
monitor.beginTask("", 10);
String tempEditorHistoryLC = ResourcesPlugin.getWorkspace().getRoot().getLocation().append(Constant.TEMP_EDITOR_HISTORY).toOSString();
File tempEditorHistoryFile = new File(tempEditorHistoryLC);
if (!tempEditorHistoryFile.exists()) {
return;
}
monitor.worked(1);
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
VTDGen vg = new VTDGen();
try {
boolean parseResult = vg.parseFile(tempEditorHistoryLC, true);
if (!parseResult) {
return;
}
VTDNav vn = vg.getNav();
AutoPilot ap = new AutoPilot(vn);
int storeFileSum = 0;
ap.selectXPath("count(/editors/editor)");
storeFileSum = (int) ap.evalXPathToNumber();
IProgressMonitor subMonitor = new SubProgressMonitor(monitor, 9, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK);
subMonitor.beginTask("", storeFileSum);
ap.selectXPath("/editors/editor");
String editorId = null;
String localFilePath = null;
boolean activate = false;
IEditorReference activateEditorRefe = null;
IEditorReference firstEditor = null;
IFile curIFile = null;
int index = -1;
while (ap.evalXPath() != -1) {
activate = false;
editorId = null;
localFilePath = null;
if ((index = vn.getAttrVal("id")) != -1) {
editorId = vn.toRawString(index);
}
if ((index = vn.getAttrVal("path")) != -1) {
localFilePath = vn.toRawString(index);
}
if (editorId == null || editorId.trim().length() <= 0 || localFilePath == null || localFilePath.trim().length() <= 0) {
continue;
}
if ((index = vn.getAttrVal("active")) != -1) {
if ("true".equals(vn.toRawString(index))) {
activate = true;
}
}
curIFile = root.getFileForLocation(new Path(localFilePath));
if (!curIFile.exists()) {
subMonitor.worked(1);
continue;
}
if (activate) {
activateEditorRefe = page.getEditorManager().openEditor(editorId, new FileEditorInput(curIFile), false, null);
PlatformUI.getWorkbench().getActiveWorkbenchWindow().setActivePage(page);
} else {
if (firstEditor == null) {
firstEditor = page.getEditorManager().openEditor(editorId, new FileEditorInput(curIFile), false, null);
} else {
page.getEditorManager().openEditor(editorId, new FileEditorInput(curIFile), false, null);
}
PlatformUI.getWorkbench().getActiveWorkbenchWindow().setActivePage(page);
}
subMonitor.worked(1);
}
PlatformUI.getWorkbench().getActiveWorkbenchWindow().setActivePage(page);
if (activateEditorRefe != null) {
if (firstEditor != null) {
page.activate(firstEditor.getEditor(true));
}
page.activate(activateEditorRefe.getEditor(true));
}
subMonitor.done();
monitor.done();
} catch (Exception e) {
LOGGER.error("restore editor file error", e);
}
}
};
try {
new ProgressMonitorDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell()).run(true, true, runnable);
} catch (Exception e) {
LOGGER.error("restore editor file error", e);
}
}
use of com.ximpleware.AutoPilot in project translationstudio8 by heartsome.
the class Application method deleteErrorMemoryInfo.
/**
* 删除错误记录文件,以修改产品第一次运行后,存储错误信息导致第二次打不开的情况 robert 2013-05-15
*/
private static void deleteErrorMemoryInfo() {
// 只针对 mac 下的用户
if (System.getProperty("os.name").indexOf("Mac") == -1) {
return;
}
String workbenchXmlPath = ResourcesPlugin.getWorkspace().getRoot().getLocation().append(".metadata/.plugins/org.eclipse.ui.workbench/workbench.xml").toOSString();
VTDGen vg = new VTDGen();
boolean result = vg.parseFile(workbenchXmlPath, true);
if (!result) {
new File(workbenchXmlPath).delete();
return;
}
VTDNav vn = vg.getNav();
AutoPilot ap = new AutoPilot(vn);
FileOutputStream stream = null;
try {
XMLModifier xm = new XMLModifier(vn);
// 删除节点 editor
ap.selectXPath("/workbench/window/page/editors/editor");
while (ap.evalXPath() != -1) {
xm.remove();
}
// 删除其他记录
ap.selectXPath("/workbench/window/page/navigationHistory");
if (ap.evalXPath() != -1) {
xm.remove();
}
xm.output(workbenchXmlPath);
} catch (Exception e) {
// do nothing
} finally {
if (stream != null) {
try {
stream.close();
} catch (Exception e2) {
}
}
}
}
use of com.ximpleware.AutoPilot in project translationstudio8 by heartsome.
the class OpenFileWithValidAction method validIsopened.
/**
* 验证是否已经被打开
* @param iFile
* @return 如果当前要打开的文件未被打开,那么验证通过,返回true,否则返回false。
*/
private boolean validIsopened(IFile iFile) throws Exception {
String extention = iFile.getFileExtension();
if (IDE.getDefaultEditor(iFile, true) != null && XLIFF_EDITOR_ID.equals(IDE.getDefaultEditor(iFile, true).getId()) && CommonFunction.validXlfExtension(extention)) {
IEditorReference[] editorRes = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getEditorReferences();
IEditorPart editor = null;
IFile openIFile = null;
String needOpenIfileLc = iFile.getLocation().toOSString();
for (int i = 0; i < editorRes.length; i++) {
if (editorRes[i].getId().equals(XLIFF_EDITOR_ID)) {
// 备注:这里的两行代码已经被注释了,原因是因为 getEditor 方法会让每一个 editor 都初始一次,这并不是本次需求所要的。注意。 2013-01-04
//editor = editorRes[i].getEditor(true);
//openIFile = ((IFileEditorInput) editor.getEditorInput()).getFile();
openIFile = ((IFileEditorInput) editorRes[i].getEditorInput()).getFile();
// 判断是否是合并打开,后缀名为xlp为合并打开,后缀名为xlf为单一打开
if ("xlp".equals(openIFile.getFileExtension())) {
// 开始解析这个合并打开临时文件,获取合并打开的文件。
VTDGen vg = new VTDGen();
if (vg.parseFile(openIFile.getLocation().toOSString(), true)) {
VTDNav vn = vg.getNav();
AutoPilot ap = new AutoPilot(vn);
try {
ap.selectXPath("/mergerFiles/mergerFile/@filePath");
int index = -1;
while ((index = ap.evalXPath()) != -1) {
String fileLC = vn.toString(index + 1);
if (fileLC != null && !"".equals(fileLC)) {
if (fileLC.equals(needOpenIfileLc)) {
editor = editorRes[i].getEditor(true);
page.activate(editor);
return false;
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
} else {
return false;
}
}
}
}
}
return true;
}
use of com.ximpleware.AutoPilot 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.AutoPilot 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();
}
}
Aggregations