Search in sources :

Example 16 with VTDNav

use of com.ximpleware.VTDNav 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();
    }
}
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 17 with VTDNav

use of com.ximpleware.VTDNav 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();
    }
}
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 18 with VTDNav

use of com.ximpleware.VTDNav 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 19 with VTDNav

use of com.ximpleware.VTDNav 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 20 with VTDNav

use of com.ximpleware.VTDNav 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)

Aggregations

VTDNav (com.ximpleware.VTDNav)206 AutoPilot (com.ximpleware.AutoPilot)177 NavException (com.ximpleware.NavException)128 XPathParseException (com.ximpleware.XPathParseException)115 XPathEvalException (com.ximpleware.XPathEvalException)110 VTDUtils (net.heartsome.xml.vtdimpl.VTDUtils)99 IOException (java.io.IOException)85 ModifyException (com.ximpleware.ModifyException)81 TranscodeException (com.ximpleware.TranscodeException)69 CoreException (org.eclipse.core.runtime.CoreException)69 XMLModifier (com.ximpleware.XMLModifier)53 UnsupportedEncodingException (java.io.UnsupportedEncodingException)49 FileNotFoundException (java.io.FileNotFoundException)46 VTDGen (com.ximpleware.VTDGen)45 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)43 XQException (javax.xml.xquery.XQException)37 LinkedHashMap (java.util.LinkedHashMap)27 ArrayList (java.util.ArrayList)26 HashMap (java.util.HashMap)25 LinkedList (java.util.LinkedList)23