Search in sources :

Example 1 with NoteBean

use of net.heartsome.cat.ts.core.bean.NoteBean in project translationstudio8 by heartsome.

the class TSFileHandler method getNotes.

// 获取当前节点的所有批注。
private Vector<NoteBean> getNotes(VTDUtils vu) throws XPathEvalException, NavException, XPathParseException {
    Vector<NoteBean> notes = new Vector<NoteBean>();
    VTDNav vn = vu.getVTDNav();
    AutoPilot ap = new AutoPilot(vn);
    ap.selectXPath("./note");
    while (ap.evalXPath() != -1) {
        NoteBean note = new NoteBean(vu.getElementContent());
        int attInx = vn.getAttrVal("xml:lang");
        if (attInx != -1) {
            note.setLang(vn.toString(attInx));
        }
        attInx = vn.getAttrVal("from");
        if (attInx != -1) {
            note.setFrom(vn.toString(attInx));
        }
        attInx = vn.getAttrVal("priority");
        if (attInx != -1) {
            note.setPriority(vn.toString(attInx));
        }
        attInx = vn.getAttrVal("annotates");
        if (attInx != -1) {
            note.setAnnotates(vn.toString(attInx));
        }
        notes.add(note);
    }
    if (notes.isEmpty()) {
        notes = null;
    }
    return notes;
}
Also used : NoteBean(net.heartsome.cat.ts.core.bean.NoteBean) AutoPilot(com.ximpleware.AutoPilot) Vector(java.util.Vector) VTDNav(com.ximpleware.VTDNav)

Example 2 with NoteBean

use of net.heartsome.cat.ts.core.bean.NoteBean in project translationstudio8 by heartsome.

the class XLFHandler method getNotes.

// 获取当前节点的所有批注。
private Vector<NoteBean> getNotes(VTDUtils vu) throws XPathEvalException, NavException, XPathParseException {
    Vector<NoteBean> notes = new Vector<NoteBean>();
    VTDNav vn = vu.getVTDNav();
    AutoPilot ap = new AutoPilot(vn);
    ap.declareXPathNameSpace("xml", VTDUtils.XML_NAMESPACE_URL);
    ap.declareXPathNameSpace(hsNSPrefix, hsR7NSUrl);
    ap.selectXPath("./note");
    while (ap.evalXPath() != -1) {
        NoteBean note = new NoteBean(vu.getElementContent());
        note.setLang(vu.getCurrentElementAttribut("xml:lang", null));
        note.setFrom(vu.getCurrentElementAttribut("from", null));
        note.setPriority(vu.getCurrentElementAttribut("priority", null));
        note.setAnnotates(vu.getCurrentElementAttribut("annotates", null));
        note.setApplyCurrent(vu.getCurrentElementAttribut("hs:apply-current", "Yes"));
        notes.add(0, note);
    }
    if (notes.isEmpty()) {
        notes = null;
    }
    return notes;
}
Also used : NoteBean(net.heartsome.cat.ts.core.bean.NoteBean) AutoPilot(com.ximpleware.AutoPilot) Vector(java.util.Vector) VTDNav(com.ximpleware.VTDNav)

Example 3 with NoteBean

use of net.heartsome.cat.ts.core.bean.NoteBean in project translationstudio8 by heartsome.

the class XLFHandler method getNotes.

public Vector<NoteBean> getNotes(String rowId) throws NavException, XPathParseException, XPathEvalException {
    Vector<NoteBean> notes = new Vector<NoteBean>();
    VTDNav vn = getVTDNavByRowId(rowId);
    VTDUtils vu = new VTDUtils(vn);
    AutoPilot ap = new AutoPilot(vn);
    ap.declareXPathNameSpace("xml", VTDUtils.XML_NAMESPACE_URL);
    ap.declareXPathNameSpace(hsNSPrefix, hsR7NSUrl);
    String tuXPath = RowIdUtil.parseRowIdToXPath(rowId);
    ap.selectXPath(tuXPath + "/note");
    while (ap.evalXPath() != -1) {
        NoteBean note = new NoteBean(vu.getElementContent());
        note.setLang(vu.getCurrentElementAttribut("xml:lang", null));
        note.setFrom(vu.getCurrentElementAttribut("from", null));
        note.setPriority(vu.getCurrentElementAttribut("priority", null));
        note.setAnnotates(vu.getCurrentElementAttribut("annotates", null));
        note.setApplyCurrent(vu.getCurrentElementAttribut("hs:apply-current", "Yes"));
        notes.add(0, note);
    }
    if (notes.isEmpty()) {
        notes = null;
    }
    return notes;
}
Also used : NoteBean(net.heartsome.cat.ts.core.bean.NoteBean) VTDUtils(net.heartsome.xml.vtdimpl.VTDUtils) AutoPilot(com.ximpleware.AutoPilot) Vector(java.util.Vector) VTDNav(com.ximpleware.VTDNav)

Example 4 with NoteBean

use of net.heartsome.cat.ts.core.bean.NoteBean in project translationstudio8 by heartsome.

the class UpdateNoteDialog method initTable.

private void initTable() {
    Vector<NoteBean> noteBeans = xliffEditor.getRowTransUnitBean(rowIndex).getNotes();
    if (noteBeans != null && noteBeans.size() > 0) {
        String[][] arrTableItem = new String[noteBeans.size()][];
        for (int i = 0; i < noteBeans.size(); i++) {
            NoteBean bean = noteBeans.get(i);
            String strNote = bean.getNoteText();
            String date = "";
            String strText = "";
            if (strNote != null) {
                //						Bug #2334:添加批注包含特殊字符保存失败
                strNote = TextUtil.resetSpecialString(strNote);
                if (strNote.indexOf(":") != -1) {
                    date = strNote.substring(0, strNote.indexOf(":"));
                    if (validData(date)) {
                        strText = strNote.substring(strNote.indexOf(":") + 1);
                    } else {
                        date = "";
                        strText = strNote;
                    }
                } else {
                    strText = strNote;
                }
            }
            String strCurrent = bean.getApplyCurrent();
            if (strCurrent == null || strCurrent.equals("Yes")) {
                strCurrent = NatTableConstant.CURRENT_TEXT;
            } else {
                strCurrent = NatTableConstant.ALL_TEXT;
            }
            arrTableItem[i] = new String[] { String.valueOf(i + 1), bean.getFrom(), date, strText, strCurrent };
        }
        tableViewer.setInput(arrTableItem);
    } else {
        tableViewer.setInput(null);
    }
}
Also used : NoteBean(net.heartsome.cat.ts.core.bean.NoteBean)

Example 5 with NoteBean

use of net.heartsome.cat.ts.core.bean.NoteBean 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)

Aggregations

NoteBean (net.heartsome.cat.ts.core.bean.NoteBean)9 Vector (java.util.Vector)6 AutoPilot (com.ximpleware.AutoPilot)5 VTDNav (com.ximpleware.VTDNav)5 NavException (com.ximpleware.NavException)4 XPathEvalException (com.ximpleware.XPathEvalException)3 XPathParseException (com.ximpleware.XPathParseException)3 HashMap (java.util.HashMap)3 VTDUtils (net.heartsome.xml.vtdimpl.VTDUtils)3 XLIFFEditorImplWithNatTable (net.heartsome.cat.ts.ui.xliffeditor.nattable.editor.XLIFFEditorImplWithNatTable)2 ModifyException (com.ximpleware.ModifyException)1 XMLModifier (com.ximpleware.XMLModifier)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Entry (java.util.Map.Entry)1 XLFHandler (net.heartsome.cat.ts.core.file.XLFHandler)1 UpdateNoteDialog (net.heartsome.cat.ts.ui.xliffeditor.nattable.dialog.UpdateNoteDialog)1 LayerCell (net.sourceforge.nattable.layer.cell.LayerCell)1