Search in sources :

Example 1 with TextRect

use of net.heartsome.cat.converter.mif.bean.TextRect 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)

Example 2 with TextRect

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

the class MifParser method parseFrame.

private Frame parseFrame() throws EOFException, MifParseException {
    Frame fm = new Frame();
    // the top level frame start sos
    int tempsos = sos;
    fm.setOffset(sos);
    fm.setEndOffset(eos);
    int start = 0;
    int framestart = 0;
    ch = r.getCharAfterIgnore();
    while (true) {
        switch(ch) {
            case '<':
                tos = sos - 1;
                String name = getStatmentName();
                nameStack.push(name);
                if (name.equals("textrect")) {
                    start = tos;
                }
                if (name.equals("frame") && tos != tempsos) {
                    framestart = tos;
                }
                if (name.equals("id") && nameStack.get(nameStack.size() - 2).equals("frame")) {
                    String content = getContentEndBy('>');
                    // clear space
                    content = content.trim();
                    fm.setId(content);
                }
                if (name.equals("importobject")) {
                    // the ImportObject statement individual parse
                    // the ImportObject statement contained specification of object data
                    parseImportObejct();
                }
                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();
                if (name.equals("textrect")) {
                    // System.out.println(new String(doc, start, sos - start));
                    int tempEos = eos;
                    eos = sos;
                    sos = start;
                    TextRect tr = parseTextRect();
                    if (tr.validate()) {
                        fm.appendTextRect(tr);
                    }
                    eos = tempEos;
                } else if (name.equals("frame") && framestart != 0) {
                    System.out.println(new String(doc, framestart, sos - framestart));
                    int tempEos = eos;
                    eos = sos;
                    sos = framestart;
                    Frame fm1 = parseFrame();
                    mpbf.appendFrame(fm1);
                    eos = tempEos;
                    // reset for next time use
                    framestart = 0;
                }
                break;
            default:
                break;
        }
        if (sos == eos) {
            return fm;
        }
        ch = r.getChar();
    }
}
Also used : Frame(net.heartsome.cat.converter.mif.bean.Frame) MifParseException(net.heartsome.cat.converter.mif.common.MifParseException) TextRect(net.heartsome.cat.converter.mif.bean.TextRect)

Example 3 with TextRect

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

the class MifParser method parseTextRect.

private TextRect parseTextRect() throws EOFException, MifParseException {
    TextRect tr = new TextRect();
    ch = r.getCharAfterIgnore();
    while (true) {
        switch(ch) {
            case '<':
                String name = getStatmentName();
                nameStack.push(name);
                if (name.equals("id")) {
                    String content = getContentEndBy('>');
                    // clear the space
                    content = content.trim();
                    tr.setId(content);
                }
                if (name.equals("shaperect")) {
                    tos = sos;
                    String content = getContentEndBy('>');
                    char[] c = content.toCharArray();
                    String[] r = new String[4];
                    StringBuffer bf = new StringBuffer();
                    int j = 0;
                    for (int i = 0; i < c.length; i++) {
                        char m = c[i];
                        if ((m >= '0' && m <= '9') || m == '.') {
                            bf.append(m);
                        }
                        if (m == ' ' && bf.length() != 0) {
                            r[j++] = bf.toString();
                            bf.delete(0, bf.length());
                        }
                    }
                    if (r.length != 4) {
                        throw new MifParseException(Messages.getString("mif.Mif2Xliff.statementError") + formatLineNumber(tos));
                    }
                    String vp = r[1];
                    char e = vp.charAt(vp.length() - 1);
                    if (e < '0' && e > '9') {
                        vp = vp.substring(0, vp.length() - 1);
                    }
                    tr.setvPosition(vp);
                }
                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 tr;
        }
        ch = r.getChar();
    }
}
Also used : TextRect(net.heartsome.cat.converter.mif.bean.TextRect) MifParseException(net.heartsome.cat.converter.mif.common.MifParseException)

Example 4 with TextRect

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

the class MifParser method parsePage.

private Page parsePage() throws EOFException, MifParseException {
    Page page = new Page();
    page.setOffset(sos);
    page.setEndOffset(eos);
    int start = 0;
    ch = r.getCharAfterIgnore();
    while (true) {
        switch(ch) {
            case '<':
                tos = sos - 1;
                String name = getStatmentName();
                nameStack.push(name);
                if (name.equals("pagetype")) {
                    String content = getContentEndBy('>');
                    content = content.trim();
                    page.setPageType(content);
                }
                if (name.equals("pagetag")) {
                    ch = r.getCharAfterIgnore();
                    String pageTag = getValue();
                    pageTag = pageTag.trim();
                    page.setPageTag(pageTag);
                }
                if (name.equals("textrect")) {
                    start = tos;
                }
                if (name.equals("importobject")) {
                    // the ImportObject statement individual parse
                    // the ImportObject statement contained specification of object data
                    parseImportObejct();
                }
                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();
                if (name.equals("textrect")) {
                    // System.out.println(new String(doc,start,sos - start));
                    int tempEos = eos;
                    eos = sos;
                    sos = start;
                    TextRect tr = parseTextRect();
                    if (tr.validate()) {
                        page.appendTextRect(tr);
                    }
                    eos = tempEos;
                    start = 0;
                }
                break;
            default:
                break;
        }
        if (sos == eos) {
            return page;
        }
        ch = r.getChar();
    }
}
Also used : MifParseException(net.heartsome.cat.converter.mif.common.MifParseException) TextRect(net.heartsome.cat.converter.mif.bean.TextRect) Page(net.heartsome.cat.converter.mif.bean.Page)

Example 5 with TextRect

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

TextRect (net.heartsome.cat.converter.mif.bean.TextRect)5 MifParseException (net.heartsome.cat.converter.mif.common.MifParseException)4 Frame (net.heartsome.cat.converter.mif.bean.Frame)2 Page (net.heartsome.cat.converter.mif.bean.Page)1 Table (net.heartsome.cat.converter.mif.bean.Table)1 TextFlow (net.heartsome.cat.converter.mif.bean.TextFlow)1