Search in sources :

Example 26 with XPathParseException

use of com.ximpleware.XPathParseException in project translationstudio8 by heartsome.

the class PreTranslation method executeTranslation.

/**
	 * 根据构建参数执行预翻译 ;
	 * @throws InterruptedException
	 */
public List<PreTranslationCounter> executeTranslation(IProgressMonitor monitor) throws InterruptedException {
    if (monitor == null) {
        monitor = new NullProgressMonitor();
    }
    monitor.beginTask("", this.xlfFiles.size());
    monitor.setTaskName(Messages.getString("pretranslation.PreTranslation.task1"));
    try {
        for (String xlfPath : xlfFiles) {
            if (monitor != null && monitor.isCanceled()) {
                throw new InterruptedException();
            }
            currentCounter = new PreTranslationCounter(xlfPath);
            this.transCounters.add(currentCounter);
            VTDNav vn = xlfHandler.getVnMap().get(xlfPath);
            VTDUtils vu = new VTDUtils(vn);
            AutoPilot ap = new AutoPilot(vu.getVTDNav());
            int tuNumber = xlfHandler.getNodeCount(xlfPath, "/xliff/file//descendant::trans-unit[(source/text()!='' or source/*)]");
            currentCounter.setTuNumber(tuNumber);
            ap.selectXPath("/xliff/file");
            String srcLang = "";
            String tgtLang = "";
            XMLModifier xm = new XMLModifier(vn);
            IProgressMonitor monitor2 = new SubProgressMonitor(monitor, 1);
            monitor2.beginTask(Messages.getString("pretranslation.PreTranslation.task2"), tuNumber);
            while (ap.evalXPath() != -1) {
                // 循环 file 节点
                String _srcLang = vu.getCurrentElementAttribut("source-language", "");
                String _tgtLang = vu.getCurrentElementAttribut("target-language", "");
                if (!_srcLang.equals("")) {
                    srcLang = _srcLang;
                }
                if (!_tgtLang.equals("")) {
                    tgtLang = _tgtLang;
                }
                if (srcLang.equals("") || tgtLang.equals("")) {
                    continue;
                }
                if (updateStrategy == PreTransParameters.KEEP_OLD_TARGET) {
                    keepCurrentMatchs(vu, _srcLang, _tgtLang, xm, monitor2);
                } else if (updateStrategy == PreTransParameters.KEEP_BEST_MATCH_TARGET) {
                    keepHigherMatchs(vu, _srcLang, _tgtLang, xm, monitor2);
                } else if (updateStrategy == PreTransParameters.KEEP_NEW_TARGET) {
                    overwriteMatchs(vu, srcLang, tgtLang, xm, monitor2);
                }
            }
            monitor2.done();
            FileOutputStream fos = new FileOutputStream(xlfPath);
            BufferedOutputStream bos = new BufferedOutputStream(fos);
            // 写入文件
            xm.output(bos);
            bos.close();
            fos.close();
        }
    } catch (XPathParseException e) {
        logger.error("", e);
        e.printStackTrace();
    } catch (NavException e) {
        logger.error("", e);
        e.printStackTrace();
    } catch (ModifyException e) {
        logger.error("", e);
        e.printStackTrace();
    } catch (XPathEvalException e) {
        logger.error("", e);
        e.printStackTrace();
    } catch (UnsupportedEncodingException e) {
        logger.error("", e);
        e.printStackTrace();
    } catch (FileNotFoundException e) {
        logger.error("", e);
        e.printStackTrace();
    } catch (TranscodeException e) {
        logger.error("", e);
        e.printStackTrace();
    } catch (IOException e) {
        logger.error("", e);
        e.printStackTrace();
    }
    monitor.done();
    return this.transCounters;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) XMLModifier(com.ximpleware.XMLModifier) NavException(com.ximpleware.NavException) XPathEvalException(com.ximpleware.XPathEvalException) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) TranscodeException(com.ximpleware.TranscodeException) XPathParseException(com.ximpleware.XPathParseException) PreTranslationCounter(net.heartsome.cat.ts.pretranslation.bean.PreTranslationCounter) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) VTDUtils(net.heartsome.xml.vtdimpl.VTDUtils) AutoPilot(com.ximpleware.AutoPilot) FileOutputStream(java.io.FileOutputStream) ModifyException(com.ximpleware.ModifyException) VTDNav(com.ximpleware.VTDNav) BufferedOutputStream(java.io.BufferedOutputStream)

Example 27 with XPathParseException

use of com.ximpleware.XPathParseException in project translationstudio8 by heartsome.

the class ImportExternalDialog method testUncelan.

private int testUncelan(String path) {
    VTDGen vg = new VTDGen();
    if (!vg.parseZIPFile(path, "word/styles.xml", true)) {
        alertParseError(path);
        return -2;
    }
    VTDNav vn = vg.getNav();
    AutoPilot ap = new AutoPilot(vn);
    ap.declareXPathNameSpace("w", ExportExternal.NAMESPACE_W);
    try {
        ap.selectXPath("/w:styles/w:style[@w:styleId=\"tw4winMark\"]");
    } catch (XPathParseException e) {
        LOGGER.error("", e);
        return -2;
    }
    return ap.evalXPathToBoolean() ? ExportExternal.EXPORT_SDLUNCLEAN : -1;
}
Also used : XPathParseException(com.ximpleware.XPathParseException) AutoPilot(com.ximpleware.AutoPilot) VTDGen(com.ximpleware.VTDGen) VTDNav(com.ximpleware.VTDNav)

Example 28 with XPathParseException

use of com.ximpleware.XPathParseException in project translationstudio8 by heartsome.

the class ColumnTypeDialog method initListener.

/**
	 * 初始化加载配置和保存配置按钮的监听 ;
	 */
private void initListener() {
    btnLoadConfiguration.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent event) {
            FileDialog fd = new FileDialog(getShell(), SWT.OPEN);
            fd.setText(Messages.getString("dialog.ColumnTypeDialog.fdTitle"));
            //$NON-NLS-1$ //$NON-NLS-2$
            String[] extensions = { "*.ctc", "*" };
            String[] names = { Messages.getString("dialog.ColumnTypeDialog.filterName1"), //$NON-NLS-1$ //$NON-NLS-2$
            Messages.getString("dialog.ColumnTypeDialog.filterName2") };
            fd.setFilterExtensions(extensions);
            fd.setFilterNames(names);
            fd.setFilterPath(System.getProperty("user.home"));
            String name = fd.open();
            if (name == null) {
                return;
            }
            try {
                VTDGen vg = new VTDGen();
                if (vg.parseFile(name, true)) {
                    VTDNav vn = vg.getNav();
                    VTDUtils vu = new VTDUtils(vn);
                    AutoPilot ap = new AutoPilot(vn);
                    ap.selectXPath("/CSV2TBX-configuration");
                    ap.evalXPath();
                    int count = vu.getChildElementsCount();
                    if (count != arrCmbLangs.length) {
                        MessageDialog.openInformation(getShell(), Messages.getString("dialog.ColumnTypeDialog.msgTitle"), Messages.getString("dialog.ColumnTypeDialog.msg1"));
                        return;
                    }
                    String xpath = "/CSV2TBX-configuration/item";
                    ap.selectXPath(xpath);
                    int i = 0;
                    while (ap.evalXPath() != -1) {
                        String propLevel = vu.getCurrentElementAttribut("propLevel", "");
                        //$NON-NLS-1$ //$NON-NLS-2$
                        String propType = vu.getCurrentElementAttribut("propType", "");
                        //$NON-NLS-1$ //$NON-NLS-2$
                        String lang = vu.getCurrentElementAttribut("propLang", "");
                        String propName = vu.getCurrentElementAttribut("propName", "");
                        arrCmbPropsLevel[i].setItems(levelValues);
                        arrCmbPropsLevel[i].select(0);
                        if (!propLevel.equals("")) {
                            //$NON-NLS-1$
                            arrCmbPropsLevel[i].setText(propLevel);
                            if (propLevel.equals(ColProperties.conceptLevel)) {
                                arrCmbLangs[i].setEnabled(false);
                                arrCmbPropsName[i].setItems(conceptPropValues);
                                arrCmbPropsName[i].select(0);
                                arrCmbPropsType[i].setItems(conceptPropTypeValues);
                                arrCmbPropsType[i].select(0);
                            }
                            if (propLevel.equals(ColProperties.langLevel)) {
                                arrCmbLangs[i].setEnabled(true);
                                arrCmbPropsName[i].setItems(TranslationPropValues);
                                arrCmbPropsName[i].select(0);
                                arrCmbPropsType[i].setItems(termDescripPropTypeValues);
                                arrCmbPropsType[i].select(0);
                            }
                        }
                        // Update content for Prop Name combo
                        if (!propName.equals("")) {
                            //$NON-NLS-1$
                            arrCmbPropsName[i].setText(propName);
                        }
                        if (!propLevel.equals("")) {
                            //$NON-NLS-1$
                            if (propLevel.equals(ColProperties.conceptLevel)) {
                                arrCmbPropsType[i].setEnabled(propName.equals(ColProperties.descripName));
                                arrCmbPropsType[i].setItems(conceptPropTypeValues);
                                arrCmbPropsType[i].select(0);
                            }
                            if (propLevel.equals(ColProperties.langLevel)) {
                                arrCmbPropsType[i].setEnabled(!propName.equals(ColProperties.termName));
                                if (propName.equals(ColProperties.descripName)) {
                                    arrCmbPropsType[i].setItems(termDescripPropTypeValues);
                                } else {
                                    arrCmbPropsType[i].setItems(termTermNotePropTypeValues);
                                }
                                arrCmbPropsType[i].select(0);
                            }
                        }
                        // Update content for Prop Type combo
                        if (!propType.equals("")) {
                            //$NON-NLS-1$
                            arrCmbPropsType[i].setText(propType);
                        }
                        // Update content for Language Combo
                        arrCmbLangs[i].setItems(LocaleService.getLanguages());
                        arrCmbLangs[i].select(0);
                        if (!lang.equals("")) {
                            //$NON-NLS-1$
                            arrCmbLangs[i].setText(lang);
                        }
                        i++;
                    }
                }
            } catch (XPathParseException e) {
                LOGGER.error(Messages.getString("dialog.ColumnTypeDialog.logger1"), e);
            } catch (NavException e) {
                LOGGER.error(Messages.getString("dialog.ColumnTypeDialog.logger1"), e);
            } catch (XPathEvalException e) {
                LOGGER.error(Messages.getString("dialog.ColumnTypeDialog.logger1"), e);
            }
        }

        public void widgetDefaultSelected(SelectionEvent e) {
        }
    });
    btnSaveConfiguration.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent e) {
            FileDialog fd = new FileDialog(getShell(), SWT.SAVE);
            fd.setText(Messages.getString("dialog.ColumnTypeDialog.savefdTitle"));
            //$NON-NLS-1$ //$NON-NLS-2$
            String[] extensions = { "*.ctc", "*.*" };
            String[] names = { Messages.getString("dialog.ColumnTypeDialog.filterName1"), //$NON-NLS-1$ //$NON-NLS-2$
            Messages.getString("dialog.ColumnTypeDialog.filterName2") };
            fd.setFilterExtensions(extensions);
            fd.setFilterNames(names);
            fd.setFilterPath(System.getProperty("user.home"));
            String name = fd.open();
            if (name == null) {
                return;
            }
            try {
                FileOutputStream output = new FileOutputStream(name);
                //$NON-NLS-1$ //$NON-NLS-2$
                output.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n".getBytes("UTF-8"));
                //$NON-NLS-1$ //$NON-NLS-2$
                output.write("<CSV2TBX-configuration>\n".getBytes("UTF-8"));
                for (int i = 0; i < arrCmbLangs.length; i++) {
                    String strItem = //$NON-NLS-1$
                    "<item propLang=\"" + arrCmbLangs[i].getText() + "\" propName=\"" + //$NON-NLS-1$
                    arrCmbPropsName[i].getText() + "\" propType=\"" + //$NON-NLS-1$
                    arrCmbPropsType[i].getText() + "\" propLevel=\"" + //$NON-NLS-1$
                    arrCmbPropsLevel[i].getText() + //$NON-NLS-1$
                    "\"/>\n";
                    //$NON-NLS-1$
                    output.write(strItem.getBytes("UTF-8"));
                }
                //$NON-NLS-1$ //$NON-NLS-2$
                output.write("</CSV2TBX-configuration>\n".getBytes("UTF-8"));
                output.close();
            } catch (FileNotFoundException e1) {
                LOGGER.error(Messages.getString("dialog.ColumnTypeDialog.logger2"), e);
            } catch (UnsupportedEncodingException e1) {
                LOGGER.error(Messages.getString("dialog.ColumnTypeDialog.logger2"), e);
            } catch (IOException e1) {
                LOGGER.error(Messages.getString("dialog.ColumnTypeDialog.logger2"), e);
            }
        }

        public void widgetDefaultSelected(SelectionEvent e) {
        }
    });
}
Also used : NavException(com.ximpleware.NavException) XPathEvalException(com.ximpleware.XPathEvalException) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) VTDGen(com.ximpleware.VTDGen) IOException(java.io.IOException) XPathParseException(com.ximpleware.XPathParseException) VTDUtils(net.heartsome.xml.vtdimpl.VTDUtils) AutoPilot(com.ximpleware.AutoPilot) FileOutputStream(java.io.FileOutputStream) SelectionEvent(org.eclipse.swt.events.SelectionEvent) FileDialog(org.eclipse.swt.widgets.FileDialog) VTDNav(com.ximpleware.VTDNav) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 29 with XPathParseException

use of com.ximpleware.XPathParseException in project translationstudio8 by heartsome.

the class AddTermToTBDialog method initProperty.

/**
	 * 初始化各个控件的值 ;
	 */
public void initProperty() {
    if (srcText != null && !srcText.equals("")) {
        txtSrc.setText(srcText);
        txtSrc.setSelection(0, srcText.length());
        txtSrc.setFocus();
    }
    if (tgtText != null && !tgtText.equals("")) {
        txtTgt.setText(tgtText);
        txtTgt.setSelection(0, tgtText.length());
        txtTgt.setFocus();
    }
    if (getPropertyValue() != null) {
        txtProperty.setText(getPropertyValue());
    }
    ProjectConfiger projectConfig = ProjectConfigerFactory.getProjectConfiger(project);
    List<Language> rsLstSrcLangs = new ArrayList<Language>();
    List<Language> rsLstTgtLangs = null;
    try {
        rsLstSrcLangs.add(projectConfig.getSourceLanguage());
        rsLstTgtLangs = projectConfig.getTargetlanguages();
    } catch (XPathParseException e) {
        LOGGER.error(Messages.getString("dialog.AddTermToTBDialog.logger"), e);
    } catch (NavException e) {
        LOGGER.error(Messages.getString("dialog.AddTermToTBDialog.logger"), e);
    } catch (XPathEvalException e) {
        LOGGER.error(Messages.getString("dialog.AddTermToTBDialog.logger"), e);
    }
    ArrayList<String> lstTgtLangs = new ArrayList<String>();
    if (rsLstTgtLangs != null) {
        for (Language lang : rsLstTgtLangs) {
            lstTgtLangs.add(lang.getCode());
        }
    }
    cmbSrcLang.setLabelProvider(new LanguageLabelProvider());
    cmbSrcLang.setInput(rsLstSrcLangs);
    cmbSrcLang.getTableCombo().select(0);
    cmbTgtLang.setLabelProvider(new LanguageLabelProvider());
    cmbTgtLang.setInput(rsLstTgtLangs);
    if (tgtLang != null) {
        cmbTgtLang.getTableCombo().select(lstTgtLangs.indexOf(tgtLang));
    }
}
Also used : XPathParseException(com.ximpleware.XPathParseException) Language(net.heartsome.cat.common.locale.Language) ProjectConfiger(net.heartsome.cat.ts.core.file.ProjectConfiger) LanguageLabelProvider(net.heartsome.cat.ts.ui.composite.LanguageLabelProvider) ArrayList(java.util.ArrayList) NavException(com.ximpleware.NavException) XPathEvalException(com.ximpleware.XPathEvalException)

Example 30 with XPathParseException

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

Aggregations

XPathParseException (com.ximpleware.XPathParseException)71 NavException (com.ximpleware.NavException)66 XPathEvalException (com.ximpleware.XPathEvalException)66 AutoPilot (com.ximpleware.AutoPilot)65 VTDNav (com.ximpleware.VTDNav)46 VTDUtils (net.heartsome.xml.vtdimpl.VTDUtils)36 ModifyException (com.ximpleware.ModifyException)17 ArrayList (java.util.ArrayList)17 XMLModifier (com.ximpleware.XMLModifier)15 IOException (java.io.IOException)15 VTDGen (com.ximpleware.VTDGen)14 UnsupportedEncodingException (java.io.UnsupportedEncodingException)13 HashMap (java.util.HashMap)9 ParseException (com.ximpleware.ParseException)8 TranscodeException (com.ximpleware.TranscodeException)7 FileNotFoundException (java.io.FileNotFoundException)7 FileOutputStream (java.io.FileOutputStream)6 EOFException (com.ximpleware.EOFException)5 EncodingException (com.ximpleware.EncodingException)5 EntityException (com.ximpleware.EntityException)5