Search in sources :

Example 6 with MifParseException

use of net.heartsome.cat.converter.mif.common.MifParseException 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 7 with MifParseException

use of net.heartsome.cat.converter.mif.common.MifParseException 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 8 with MifParseException

use of net.heartsome.cat.converter.mif.common.MifParseException in project translationstudio8 by heartsome.

the class MifParser method validateFile.

private void validateFile() throws MifParseException {
    try {
        ch = r.getCharAfterIgnore();
        if (ch != '<') {
            throw new MifParseException(Messages.getString("mif.Mif2Xliff.fileNotStartProperly") + formatLineNumber());
        }
        tos = sos;
        String name = getContentEndBy(' ').toLowerCase();
        if (!name.equals("miffile")) {
            throw new MifParseException(Messages.getString("mif.Mif2Xliff.fileNotStartProperly") + formatLineNumber(tos));
        }
        tos = sos;
        String version = getContentEndBy('>');
        try {
            float f = Float.parseFloat(version);
            if (f == 7.00 || f == 8.00 || f == 9.00 || f == 10.0) {
            } else {
                throw new MifParseException(MessageFormat.format(Messages.getString("mif.Mif2Xliff.unsuportVersion") + formatLineNumber(tos), f));
            }
        } catch (NumberFormatException e) {
            throw new MifParseException(Messages.getString("mif.Mif2Xliff.invalidateVersionInfo") + formatLineNumber());
        }
        if (r.getChar() != '>') {
            throw new MifParseException(Messages.getString("mif.Mif2Xliff.mismatchStartOrEndTag") + formatLineNumber());
        }
    } catch (EOFException e) {
        throw new MifParseException(Messages.getString("mif.Mif2Xliff.fileEndError"));
    }
}
Also used : MifParseException(net.heartsome.cat.converter.mif.common.MifParseException) EOFException(java.io.EOFException)

Example 9 with MifParseException

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

Aggregations

MifParseException (net.heartsome.cat.converter.mif.common.MifParseException)9 TextRect (net.heartsome.cat.converter.mif.bean.TextRect)4 Frame (net.heartsome.cat.converter.mif.bean.Frame)3 Table (net.heartsome.cat.converter.mif.bean.Table)3 Page (net.heartsome.cat.converter.mif.bean.Page)2 TextFlow (net.heartsome.cat.converter.mif.bean.TextFlow)2 EOFException (java.io.EOFException)1 Marker (net.heartsome.cat.converter.mif.bean.Marker)1