use of net.heartsome.cat.converter.mif.bean.Marker 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();
}
}
use of net.heartsome.cat.converter.mif.bean.Marker in project translationstudio8 by heartsome.
the class XliffReader method readXliffFile.
/**
* After parse file, this method read the xliff file from the parse info
* @param xlfOs
* the xliff file out put stream
* @param iniFile
* the configure file of mif,witch define the ESC
* @param isReadMasterPage
* xliff contain the masterpage or not
* @param monitor
* the progress monitor
* @throws MifParseException
* @throws IOException
* ;
* @throws UnSuportedFileExcetption
*/
public void readXliffFile(BufferedWriter xlfOs, String iniFile, boolean isReadMasterPage, IProgressMonitor monitor) throws MifParseException, IOException, UnSuportedFileExcetption {
if (monitor == null) {
monitor = new NullProgressMonitor();
}
rUtil = new ReaderUtil(iniFile);
File xf = File.createTempFile("xliftemp", ".temp");
// first read the index
List<Marker> markers = mpbf.getMarkers();
if (markers.size() > 0) {
File f = File.createTempFile("miftemp", ".tmp");
BufferedWriter tmpWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(f), mifEncoding));
try {
this.xlfOs = new BufferedWriter(new FileWriter(xf));
// generate the xliff content to temporary file xf
for (Marker m : markers) {
outputSegmenet(rUtil.cleanString(m.getContent()), m.getOffset(), m.getEndOffset(), 1);
}
// generate temporary file ,the file had extracted index content and contains '%%%index%%%'
readSkeletonFile(tmpWriter, null);
} finally {
if (tmpWriter != null) {
tmpWriter.close();
}
if (this.xlfOs != null) {
this.xlfOs.close();
}
}
// reload the temporary file
loadFile(f.getAbsolutePath(), mifEncoding);
// after reload delete the temporary file
f.delete();
}
// second read the content
this.xlfOs = xlfOs;
List<Page> pages = mpbf.getPages();
monitor.setTaskName(Messages.getString("mif.Mif2Xliff.task3"));
if (pages.size() == 0) {
// no pages specified ,direct read the Para statement
monitor.beginTask(Messages.getString("mif.Mif2Xliff.task3"), 1);
monitor.worked(1);
readPara();
} else {
monitor.beginTask(Messages.getString("mif.Mif2Xliff.task3"), pages.size());
for (Page page : pages) {
String pageType = page.getPageType().toLowerCase();
if (pageType.equals("bodypage")) {
readPage(page);
} else if (pageType.indexOf("masterpage") != -1 && isReadMasterPage) {
readPage(page);
}
monitor.worked(1);
}
}
BufferedReader r = null;
try {
r = new BufferedReader(new FileReader(xf));
String line = r.readLine();
while (line != null) {
this.xlfOs.write(line + "\n");
line = r.readLine();
}
} finally {
if (r != null) {
r.close();
}
xf.delete();
}
monitor.done();
}
Aggregations