Search in sources :

Example 1 with Table

use of net.heartsome.cat.converter.mif.bean.Table in project translationstudio8 by heartsome.

the class MifParser method parseTables.

private Table parseTables() throws EOFException, MifParseException {
    Table tbl = new Table();
    tbl.setOffset(sos);
    tbl.setEndOffset(eos);
    ch = r.getCharAfterIgnore();
    while (true) {
        switch(ch) {
            case '<':
                String name = getStatmentName();
                nameStack.push(name);
                if (name.equals("tblid")) {
                    String content = getContentEndBy('>');
                    // clear the space
                    content = content.trim();
                    tbl.setId(content);
                }
                break;
            case '`':
                getValue();
                break;
            case '>':
                if (doc[sos - 2] == '\\') {
                    break;
                }
                if (nameStack.isEmpty()) {
                    throw new MifParseException(Messages.getString("mif.Mif2Xliff.mismatchStartOrEndTag") + formatLineNumber());
                }
                nameStack.pop();
                break;
            default:
                break;
        }
        if (sos == eos) {
            return tbl;
        }
        ch = r.getChar();
    }
}
Also used : Table(net.heartsome.cat.converter.mif.bean.Table) MifParseException(net.heartsome.cat.converter.mif.common.MifParseException)

Example 2 with Table

use of net.heartsome.cat.converter.mif.bean.Table in project translationstudio8 by heartsome.

the class MifParser method parse.

public void parse() throws EOFException, MifParseException {
    ch = r.getCharAfterIgnore();
    // the top level element start offset
    int start = 0;
    // the embed element start offset
    int markerFlg = 0;
    while (true) {
        switch(ch) {
            case '<':
                // the statement start offset
                tos = sos - 1;
                String name = getStatmentName();
                nameStack.push(name);
                // System.out.println(name);
                if (name.equals("aframes")) {
                    start = tos;
                } else if (name.equals("tbl")) {
                    start = tos;
                } else if (name.equals("page")) {
                    start = tos;
                } else if (name.equals("textflow")) {
                    start = tos;
                } else if (name.equals("importobject")) {
                    // the ImportObject statement individual parse
                    // the ImportObject statement contained specification of object data
                    parseImportObejct();
                } else if (name.equals("marker")) {
                    // parse the marker element and get the index and cross-ref info
                    // This implement at 2012-08-15 for new requirement of extract the index text
                    markerFlg = tos;
                } else if (name.equals("mtype") && markerFlg != 0) {
                    // check marker type
                    String v = getContentEndBy('>').trim();
                    if (!v.equals("2")) {
                        // 9: cross-ref , 2 : index
                        markerFlg = 0;
                    }
                } else if (name.equals("mtext") && markerFlg != 0) {
                    // extract marker text
                    ch = r.getCharAfterIgnore();
                    if (ch == '`') {
                        int strsos = sos;
                        String text = getValue();
                        int streos = sos;
                        if (text.length() != 0) {
                            Marker m = new Marker(strsos, streos, text);
                            mpbf.appendMarker(m);
                            markerFlg = 0;
                        }
                    }
                }
                break;
            case '`':
                // skip the value
                getValue();
                break;
            case '>':
                if (doc[sos - 2] == '\\') {
                    break;
                }
                if (nameStack.isEmpty()) {
                    throw new MifParseException(Messages.getString("mif.Mif2Xliff.mismatchStartOrEndTag") + formatLineNumber());
                }
                name = nameStack.pop();
                if (name.equals("aframes")) {
                    // System.out.println(new String(doc,start,sos - start));
                    int tempEos = eos;
                    eos = sos;
                    sos = start;
                    parseAframes();
                    eos = tempEos;
                    // rest the record
                    start = 0;
                } else if (name.equals("tbl")) {
                    int tempEos = eos;
                    eos = sos;
                    sos = start;
                    Table tbl = parseTables();
                    if (tbl.validate()) {
                        mpbf.appendTbale(tbl);
                    }
                    eos = tempEos;
                    // rest the record
                    start = 0;
                } else if (name.equals("page")) {
                    int tempEos = eos;
                    eos = sos;
                    sos = start;
                    Page page = parsePage();
                    if (page.validate()) {
                        mpbf.appendPage(page);
                    }
                    eos = tempEos;
                    // rest the record
                    start = 0;
                } else if (name.equals("textflow")) {
                    int tempEos = eos;
                    eos = sos;
                    sos = start;
                    TextFlow tf = parseTextFlow();
                    if (tf.validate()) {
                        mpbf.appendTextFlow(tf);
                    }
                    eos = tempEos;
                    // rest the record
                    start = 0;
                }
                break;
            default:
                break;
        }
        if (sos == eos) {
            return;
        }
        ch = r.getChar();
    }
}
Also used : Table(net.heartsome.cat.converter.mif.bean.Table) MifParseException(net.heartsome.cat.converter.mif.common.MifParseException) Page(net.heartsome.cat.converter.mif.bean.Page) TextFlow(net.heartsome.cat.converter.mif.bean.TextFlow) Marker(net.heartsome.cat.converter.mif.bean.Marker)

Example 3 with Table

use of net.heartsome.cat.converter.mif.bean.Table in project translationstudio8 by heartsome.

the class XliffReader method readParalines.

private void readParalines(int plNum) throws MifParseException, IOException {
    ch = r.getCharAfterIgnore();
    // string statement start offset
    int strsos = 0;
    // string statement end offset
    int streos = 0;
    // the index of tag
    int tagIdex = 1;
    int tagsos = 0;
    int tageos = 0;
    // the string statement counter,Count is greater
    int strCounter = 0;
    // than 1
    // will segment the content
    StringBuffer extraValBf = new StringBuffer();
    // StringBuffer tagValBf = new StringBuffer();
    while (true) {
        switch(ch) {
            case '<':
                tempos = sos - 1;
                String name = getStatmentName();
                nameStack.push(name);
                if (name.equals("paraline")) {
                    // flag = false;
                    tagsos = 0;
                    tageos = 0;
                }
                if (name.equals("string")) {
                    // start to extraction text content
                    ch = r.getCharAfterIgnore();
                    String text = getValue();
                    if (extraValBf.length() == 0) {
                        // the first of string statement
                        strsos = tempos;
                    } else {
                        tageos = tempos;
                    }
                    if (tagsos != 0 && tageos != 0 && tagsos != tageos) {
                        //						System.out.println(formatLineNumber(tagsos) +" "+ formatLineNumber(tageos));
                        String tag = new String(doc, tagsos, tageos - tagsos);
                        if (tag.trim().length() != 0) {
                            extraValBf.append("<ph id=\"" + tagIdex++ + "\">");
                            extraValBf.append(rUtil.cleanTag(tag));
                            extraValBf.append("</ph>");
                        }
                        tagsos = 0;
                        tageos = 0;
                    }
                    extraValBf.append(rUtil.cleanString(text));
                    strCounter++;
                }
                if (name.equals("char")) {
                    String val = getContentEndBy('>');
                    if (val.equals("HardReturn") && extraValBf.length() != 0) {
                        outputSegmenet(extraValBf.toString(), strsos, streos, strCounter);
                        strsos = 0;
                        streos = 0;
                        extraValBf.delete(0, extraValBf.length());
                        tagsos = 0;
                        tageos = 0;
                        strCounter = 0;
                    }
                }
                if (name.equals("aframe")) {
                    String id = getContentEndBy('>');
                    if (id == null || id.length() == 0) {
                        throw new MifParseException(Messages.getString("mif.Mif2Xliff.statementError") + formatLineNumber());
                    }
                    Frame fm = mpbf.getFrame(id);
                    if (fm == null) {
                        throw new MifParseException(Messages.getString("mif.Mif2Xliff.noFrameFind") + formatLineNumber());
                    }
                    // save extract text
                    if (extraValBf.length() != 0) {
                        outputSegmenet(extraValBf.toString(), strsos, streos, strCounter);
                        strsos = 0;
                        streos = 0;
                        extraValBf.delete(0, extraValBf.length());
                        tagsos = 0;
                        tageos = 0;
                        strCounter = 0;
                    }
                    List<TextRect> trs = fm.getTextRects();
                    readTextRect(trs);
                }
                if (name.equals("atbl")) {
                    String id = getContentEndBy('>');
                    if (id == null || id.length() == 0) {
                        throw new MifParseException(Messages.getString("mif.Mif2Xliff.statementError") + formatLineNumber());
                    }
                    Table tbl = mpbf.getTable(id);
                    if (tbl == null) {
                        throw new MifParseException(Messages.getString("mif.Mif2Xliff.noTableFind") + formatLineNumber());
                    }
                    // save extract text
                    if (extraValBf.length() != 0) {
                        outputSegmenet(extraValBf.toString(), strsos, streos, strCounter);
                        strsos = 0;
                        streos = 0;
                        extraValBf.delete(0, extraValBf.length());
                        tagsos = 0;
                        tageos = 0;
                        strCounter = 0;
                    }
                    int tempsos = sos;
                    int tempeos = eos;
                    readTable(tbl);
                    sos = tempsos;
                    eos = tempeos;
                }
                break;
            case '>':
                if (doc[sos - 2] == '\\') {
                    break;
                }
                if (nameStack.isEmpty()) {
                    throw new MifParseException(Messages.getString("mif.Mif2Xliff.mismatchStartOrEndTag") + formatLineNumber());
                }
                name = nameStack.pop();
                if (name.equals("string")) {
                    // end of string statement
                    streos = sos;
                    tagsos = sos;
                }
                if (name.equals("paraline")) {
                    tageos = sos - 1;
                    plNum--;
                    if (tagsos != 0 && tageos != 0 && tagsos != tageos && plNum != 0) {
                        // when plNum == 0 is the last ParaLine
                        String tag = new String(doc, tagsos, tageos - tagsos);
                        if (tag.trim().length() != 0) {
                            extraValBf.append("<ph id=\"" + tagIdex++ + "\">");
                            extraValBf.append(rUtil.cleanTag(tag));
                            extraValBf.append("</ph>");
                        }
                        tagsos = 0;
                        tageos = 0;
                    }
                }
            default:
                break;
        }
        if (sos == eos) {
            if (extraValBf.length() != 0) {
                outputSegmenet(extraValBf.toString(), strsos, streos, strCounter);
                strsos = 0;
                streos = 0;
                extraValBf.delete(0, extraValBf.length());
                tagsos = 0;
                tageos = 0;
                strCounter = 0;
            }
            return;
        }
        ch = r.getChar();
    }
}
Also used : Frame(net.heartsome.cat.converter.mif.bean.Frame) Table(net.heartsome.cat.converter.mif.bean.Table) MifParseException(net.heartsome.cat.converter.mif.common.MifParseException) TextRect(net.heartsome.cat.converter.mif.bean.TextRect)

Aggregations

Table (net.heartsome.cat.converter.mif.bean.Table)3 MifParseException (net.heartsome.cat.converter.mif.common.MifParseException)3 Frame (net.heartsome.cat.converter.mif.bean.Frame)1 Marker (net.heartsome.cat.converter.mif.bean.Marker)1 Page (net.heartsome.cat.converter.mif.bean.Page)1 TextFlow (net.heartsome.cat.converter.mif.bean.TextFlow)1 TextRect (net.heartsome.cat.converter.mif.bean.TextRect)1