Search in sources :

Example 36 with AutoPilot

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();
    }
}
Also used : MessageFormat(java.text.MessageFormat) EncodingException(com.ximpleware.EncodingException) NavException(com.ximpleware.NavException) XPathEvalException(com.ximpleware.XPathEvalException) EntityException(com.ximpleware.EntityException) VTDGen(com.ximpleware.VTDGen) IOException(java.io.IOException) XPathParseException(com.ximpleware.XPathParseException) VTDUtils(net.heartsome.xml.vtdimpl.VTDUtils) AutoPilot(com.ximpleware.AutoPilot) EOFException(com.ximpleware.EOFException) XPathParseException(com.ximpleware.XPathParseException) ParseException(com.ximpleware.ParseException) VTDNav(com.ximpleware.VTDNav)

Example 37 with AutoPilot

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;
}
Also used : Hashtable(java.util.Hashtable) AutoPilot(com.ximpleware.AutoPilot) VTDGen(com.ximpleware.VTDGen) VTDNav(com.ximpleware.VTDNav)

Example 38 with AutoPilot

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);
            }
        }
    });
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IFile(org.eclipse.core.resources.IFile) ArrayList(java.util.ArrayList) VTDGen(com.ximpleware.VTDGen) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) ExecutionException(org.eclipse.core.commands.ExecutionException) IEditorReference(org.eclipse.ui.IEditorReference) AutoPilot(com.ximpleware.AutoPilot) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) VTDNav(com.ximpleware.VTDNav) IResource(org.eclipse.core.resources.IResource) IEditorInput(org.eclipse.ui.IEditorInput) IFolder(org.eclipse.core.resources.IFolder)

Example 39 with AutoPilot

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;
    }
}
Also used : Language(net.heartsome.cat.common.locale.Language) VTDUtils(net.heartsome.xml.vtdimpl.VTDUtils) AutoPilot(com.ximpleware.AutoPilot) ArrayList(java.util.ArrayList) VTDGen(com.ximpleware.VTDGen) VTDNav(com.ximpleware.VTDNav)

Example 40 with AutoPilot

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;
}
Also used : AutoPilot(com.ximpleware.AutoPilot) VTDGen(com.ximpleware.VTDGen) VTDNav(com.ximpleware.VTDNav) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Aggregations

AutoPilot (com.ximpleware.AutoPilot)308 VTDNav (com.ximpleware.VTDNav)173 NavException (com.ximpleware.NavException)150 XPathParseException (com.ximpleware.XPathParseException)145 XPathEvalException (com.ximpleware.XPathEvalException)137 VTDUtils (net.heartsome.xml.vtdimpl.VTDUtils)112 IOException (java.io.IOException)103 ModifyException (com.ximpleware.ModifyException)95 TranscodeException (com.ximpleware.TranscodeException)82 CoreException (org.eclipse.core.runtime.CoreException)76 UnsupportedEncodingException (java.io.UnsupportedEncodingException)58 VTDGen (com.ximpleware.VTDGen)50 FileNotFoundException (java.io.FileNotFoundException)49 XMLModifier (com.ximpleware.XMLModifier)46 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)44 ArrayList (java.util.ArrayList)42 HashMap (java.util.HashMap)39 XQException (javax.xml.xquery.XQException)37 LinkedHashMap (java.util.LinkedHashMap)34 LinkedList (java.util.LinkedList)25