use of net.heartsome.cat.converter.mif.bean.Frame in project translationstudio8 by heartsome.
the class MifParser method parseAframes.
private void parseAframes() throws EOFException, MifParseException {
ch = r.getCharAfterIgnore();
int start = 0;
while (true) {
switch(ch) {
case '<':
tos = sos - 1;
String name = getStatmentName();
nameStack.push(name);
if (name.equals("frame") && !nameStack.get(nameStack.size() - 2).equals("frame")) {
start = tos;
} else 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("frame")) {
// System.out.println(new String(doc,start,sos - start));
int temp = nameStack.size() - 1;
if (temp < 0 || !nameStack.get(temp).equals("frame")) {
int tempEos = eos;
eos = sos;
sos = start;
Frame fm = parseFrame();
mpbf.appendFrame(fm);
eos = tempEos;
}
}
break;
default:
break;
}
if (sos == eos) {
return;
}
ch = r.getChar();
}
}
use of net.heartsome.cat.converter.mif.bean.Frame 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();
}
}
use of net.heartsome.cat.converter.mif.bean.Frame 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();
}
}
Aggregations