Search in sources :

Example 46 with XPathEvalException

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

the class XLFHandler method saveAsHtml.

/**
	 * 存为HTML
	 * @param fileName
	 * @param out
	 * @param elementName
	 * @return ;
	 */
public boolean saveAsHtml(String fileName, String out, String elementName) {
    BufferedOutputStream bos = null;
    try {
        bos = new BufferedOutputStream(new FileOutputStream(out));
        //$NON-NLS-1$
        bos.write("<html>\n".getBytes());
        //$NON-NLS-1$
        bos.write("  <head>\n".getBytes());
        //$NON-NLS-1$
        bos.write("    <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\n".getBytes());
        //$NON-NLS-1$ //$NON-NLS-2$
        bos.write(("    <title>" + fileName + "</title>\n").getBytes());
        //$NON-NLS-1$
        bos.write("  </head>\n".getBytes());
        //$NON-NLS-1$
        bos.write("<body>\n".getBytes());
        VTDNav vn = vnMap.get(fileName);
        AutoPilot ap = new AutoPilot(vn);
        VTDUtils vu = new VTDUtils(vn);
        ap.selectXPath("/xliff/file");
        while (ap.evalXPath() != -1) {
            AutoPilot subAp = new AutoPilot(vn);
            subAp.selectXPath("descendant::trans-unit[source/text()!='']");
            while (subAp.evalXPath() != -1) {
                if ("target".equals(elementName)) {
                    String approvedValue = vu.getValue("./@approved");
                    approvedValue = approvedValue == null ? "no" : approvedValue;
                    if (!"yes".equalsIgnoreCase(approvedValue)) {
                        // 未批准
                        continue;
                    }
                }
                String value = vu.getValue("./" + elementName + "/text()");
                if (value != null) {
                    bos.write(("<p>" + value + "</p>\n").getBytes());
                }
            }
        }
        bos.write("</body>\n</html>\n".getBytes());
        return true;
    } catch (FileNotFoundException e) {
        LOGGER.error("", e);
        e.printStackTrace();
        return false;
    } catch (IOException e) {
        LOGGER.error("", e);
        e.printStackTrace();
        return false;
    } catch (NavException e) {
        LOGGER.error("", e);
        e.printStackTrace();
        return false;
    } catch (XPathParseException e) {
        LOGGER.error("", e);
        e.printStackTrace();
        return false;
    } catch (XPathEvalException e) {
        LOGGER.error("", e);
        e.printStackTrace();
        return false;
    } finally {
        if (bos != null) {
            try {
                bos.close();
            } catch (IOException e) {
                LOGGER.error("", e);
                e.printStackTrace();
            }
        }
    }
}
Also used : XPathParseException(com.ximpleware.XPathParseException) VTDUtils(net.heartsome.xml.vtdimpl.VTDUtils) AutoPilot(com.ximpleware.AutoPilot) FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) NavException(com.ximpleware.NavException) XPathEvalException(com.ximpleware.XPathEvalException) IOException(java.io.IOException) BufferedOutputStream(java.io.BufferedOutputStream) VTDNav(com.ximpleware.VTDNav)

Example 47 with XPathEvalException

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

the class XLFHandler method getCaseTgtContent.

/** burke 为修改锁定行目标文本不能修改其大小写添加 getCaseTgtContent方法 */
/**
	 * 获取要改变大小写的target中的文本内容
	 * @param rowId
	 * @return
	 */
public String getCaseTgtContent(String rowId) {
    AutoPilot ap = new AutoPilot();
    VTDNav vn = null;
    vn = getVTDNavByRowId(rowId);
    ap.bind(vn);
    try {
        String tuXPath = RowIdUtil.parseRowIdToXPath(rowId);
        ap.selectXPath(tuXPath);
        if (ap.evalXPath() != -1) {
            int attrIndex = vn.getAttrVal("translate");
            if (attrIndex != -1) {
                String attrValue = vn.toString(attrIndex);
                if (attrValue.equals("no")) {
                    return "no";
                }
            }
        }
        ap.resetXPath();
    } catch (XPathEvalException e) {
        LOGGER.error("", e);
        e.printStackTrace();
    } catch (NavException e) {
        LOGGER.error("", e);
        e.printStackTrace();
    } catch (XPathParseException e) {
        LOGGER.error("", e);
        e.printStackTrace();
    }
    String tgt = getTgtContent(rowId);
    return tgt;
}
Also used : XPathParseException(com.ximpleware.XPathParseException) AutoPilot(com.ximpleware.AutoPilot) XPathEvalException(com.ximpleware.XPathEvalException) NavException(com.ximpleware.NavException) VTDNav(com.ximpleware.VTDNav)

Example 48 with XPathEvalException

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

the class ProjectConfiger method getCurrentProjectConfig.

/**
	 * 获取项目配置信息
	 * @return 指定项目配置文件中的所有信息;
	 */
public ProjectInfoBean getCurrentProjectConfig() {
    ProjectInfoBean bean = new ProjectInfoBean();
    vu.getVTDNav().push();
    AutoPilot hsAp = new AutoPilot(vu.getVTDNav());
    try {
        hsAp.selectXPath("/projectDescription/hs");
        if (hsAp.evalXPath() != -1) {
            bean.setProjectName(getProjectName());
            bean.setMapField(getFieldMap());
            bean.setMapAttr(getAttrMap());
            bean.setSourceLang(getSourceLanguage());
            bean.setTargetLang(getTargetlanguages());
            bean.setTmDb(getAllTmDbs());
            bean.setTbDb(getTermBaseDbs(false));
        }
    } catch (XPathParseException e) {
        logger.error("", e);
    } catch (XPathEvalException e) {
        logger.error("", e);
    } catch (NavException e) {
        logger.error("", e);
    }
    vu.getVTDNav().pop();
    return bean;
}
Also used : XPathParseException(com.ximpleware.XPathParseException) ProjectInfoBean(net.heartsome.cat.common.bean.ProjectInfoBean) AutoPilot(com.ximpleware.AutoPilot) XPathEvalException(com.ximpleware.XPathEvalException) NavException(com.ximpleware.NavException)

Example 49 with XPathEvalException

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

the class DeleteSelectionSegmentNotesHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    IEditorPart editor = HandlerUtil.getActiveEditor(event);
    if (!(editor instanceof XLIFFEditorImplWithNatTable)) {
        return null;
    }
    IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
    boolean res = MessageDialog.openConfirm(window.getShell(), Messages.getString("handler.DeleteSelectionSegmentNotesHandler.msgTitle1"), Messages.getString("handler.DeleteSelectionSegmentNotesHandler.msg1"));
    if (res) {
        XLIFFEditorImplWithNatTable xliffEditor = (XLIFFEditorImplWithNatTable) editor;
        XLFHandler handler = xliffEditor.getXLFHandler();
        List<String> lstRowId = xliffEditor.getSelectedRowIds();
        // 先将应用范围为当前文本段的批注删除
        handler.deleteEditableSegmentNote(lstRowId);
        try {
            HashMap<String, Vector<NoteBean>> mapNote = new HashMap<String, Vector<NoteBean>>();
            for (String rowId : lstRowId) {
                // 删除应用范围为所有文本段的批注
                Vector<NoteBean> noteBeans = xliffEditor.getXLFHandler().getNotes(rowId);
                if (noteBeans != null && noteBeans.size() > 0) {
                    mapNote.put(rowId, noteBeans);
                }
            }
            xliffEditor.getXLFHandler().deleteNote(mapNote);
        } catch (NavException e) {
            LOGGER.error("", e);
            MessageDialog.openInformation(HandlerUtil.getActiveShell(event), Messages.getString("handler.DeleteSelectionSegmentNotesHandler.msgTitle2"), Messages.getString("handler.DeleteSelectionSegmentNotesHandler.msg2"));
        } catch (XPathParseException e) {
            LOGGER.error("", e);
            MessageDialog.openInformation(HandlerUtil.getActiveShell(event), Messages.getString("handler.DeleteSelectionSegmentNotesHandler.msgTitle2"), Messages.getString("handler.DeleteSelectionSegmentNotesHandler.msg2"));
        } catch (XPathEvalException e) {
            LOGGER.error("", e);
            MessageDialog.openInformation(HandlerUtil.getActiveShell(event), Messages.getString("handler.DeleteSelectionSegmentNotesHandler.msgTitle2"), Messages.getString("handler.DeleteSelectionSegmentNotesHandler.msg2"));
        } finally {
            xliffEditor.refresh();
        }
    }
    return null;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) XLIFFEditorImplWithNatTable(net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable) HashMap(java.util.HashMap) NavException(com.ximpleware.NavException) XPathEvalException(com.ximpleware.XPathEvalException) IEditorPart(org.eclipse.ui.IEditorPart) XPathParseException(com.ximpleware.XPathParseException) NoteBean(net.heartsome.cat.ts.core.bean.NoteBean) Vector(java.util.Vector) XLFHandler(net.heartsome.cat.ts.core.file.XLFHandler)

Example 50 with XPathEvalException

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

the class QAXmlHandler method getLanguages.

/**
	 * 得到所有语言对 备注:重复,从XLFHandler.java中拷取
	 * @return 语言对的Map<br/>
	 *         key: 源语言;value: 对应的目标语言(可以是多个)
	 */
public Map<String, ArrayList<String>> getLanguages() {
    TreeMap<String, ArrayList<String>> languages = new TreeMap<String, ArrayList<String>>();
    AutoPilot ap = new AutoPilot();
    ap.declareXPathNameSpace("xml", VTDUtils.XML_NAMESPACE_URL);
    ap.declareXPathNameSpace(hsNSPrefix, hsR7NSUrl);
    VTDUtils vu = new VTDUtils();
    for (VTDNav vn : vnMap.values()) {
        ap.bind(vn);
        try {
            vu.bind(vn);
            ap.selectXPath("/xliff/file");
            while (ap.evalXPath() != -1) {
                String srcLanguage = vu.getCurrentElementAttribut("source-language", null);
                String tgtLanguage = vu.getCurrentElementAttribut("target-language", null);
                if (srcLanguage == null) {
                    // TODO 该file节点不存在“source-language”属性,提醒添加
                    continue;
                }
                if (tgtLanguage == null) {
                    // TODO 该file节点不存在“target-language”属性,提醒添加
                    continue;
                }
                ArrayList<String> tgtLanguages = languages.get(srcLanguage);
                if (tgtLanguages == null) {
                    tgtLanguages = new ArrayList<String>();
                    languages.put(srcLanguage, tgtLanguages);
                }
                if (!tgtLanguages.contains(tgtLanguage)) {
                    // 未包含,就添加进去
                    tgtLanguages.add(tgtLanguage);
                }
            }
        } catch (XPathParseException e) {
            e.printStackTrace();
            logger.error(Messages.getString("qa.QAXmlHandler.logger9"), e);
        } catch (XPathEvalException e) {
            e.printStackTrace();
            logger.error(Messages.getString("qa.QAXmlHandler.logger10"), e);
        } catch (NavException e) {
            e.printStackTrace();
            logger.error(Messages.getString("qa.QAXmlHandler.logger11"), e);
        }
    }
    return languages;
}
Also used : XPathParseException(com.ximpleware.XPathParseException) VTDUtils(net.heartsome.xml.vtdimpl.VTDUtils) AutoPilot(com.ximpleware.AutoPilot) ArrayList(java.util.ArrayList) XPathEvalException(com.ximpleware.XPathEvalException) NavException(com.ximpleware.NavException) TreeMap(java.util.TreeMap) VTDNav(com.ximpleware.VTDNav)

Aggregations

NavException (com.ximpleware.NavException)65 XPathEvalException (com.ximpleware.XPathEvalException)65 XPathParseException (com.ximpleware.XPathParseException)65 AutoPilot (com.ximpleware.AutoPilot)59 VTDNav (com.ximpleware.VTDNav)44 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 UnsupportedEncodingException (java.io.UnsupportedEncodingException)13 VTDGen (com.ximpleware.VTDGen)11 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