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