Search in sources :

Example 1 with TextFlow

use of net.heartsome.cat.converter.mif.bean.TextFlow 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 2 with TextFlow

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

the class MifParser method parseTextFlow.

private TextFlow parseTextFlow() throws EOFException, MifParseException {
    TextFlow tf = new TextFlow();
    tf.setOffset(sos);
    tf.setEndOffset(eos);
    ch = r.getCharAfterIgnore();
    while (true) {
        switch(ch) {
            case '<':
                String name = getStatmentName();
                nameStack.push(name);
                if (name.equals("textrectid") && (tf.getTextRectId() == null || tf.getTextRectId().equals(""))) {
                    String content = getContentEndBy('>');
                    content = content.trim();
                    tf.setTextRectId(content);
                }
                break;
            case '`':
                getValue();
                break;
            case '>':
                if (doc[sos - 2] == '\\') {
                    break;
                }
                if (nameStack.isEmpty()) {
                    throw new MifParseException(Messages.getString("mif.Mif2Xliff.mismatchStartOrEndTag") + formatLineNumber());
                }
                name = nameStack.pop();
                break;
            default:
                break;
        }
        if (sos == eos) {
            return tf;
        }
        ch = r.getChar();
    }
}
Also used : MifParseException(net.heartsome.cat.converter.mif.common.MifParseException) TextFlow(net.heartsome.cat.converter.mif.bean.TextFlow)

Example 3 with TextFlow

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

the class XliffReader method readTextRect.

private void readTextRect(List<TextRect> trs) throws MifParseException, IOException {
    for (TextRect tr : trs) {
        String id = tr.getId();
        TextFlow tf = mpbf.getTextFlow(id);
        if (tf == null) {
            continue;
        }
        readTextFlow(tf);
    }
}
Also used : TextRect(net.heartsome.cat.converter.mif.bean.TextRect) TextFlow(net.heartsome.cat.converter.mif.bean.TextFlow)

Aggregations

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