use of org.eclipse.core.runtime.NullProgressMonitor in project translationstudio8 by heartsome.
the class XliffReader method read2SpreadsheetDoc.
public void read2SpreadsheetDoc(String spreadsheetDocFile, String xliffFile, String sklFile, IProgressMonitor monitor) throws InternalFileException {
if (monitor == null) {
monitor = new NullProgressMonitor();
}
monitor.beginTask(Messages.getString("msexcel.xliff2mse.task1"), 5);
loadFile(xliffFile);
monitor.worked(1);
monitor.setTaskName(Messages.getString("msexcel.xliff2mse.task2"));
try {
SpreadsheetDocument.open(sklFile);
monitor.worked(1);
WorkBookPart wb = SpreadsheetDocument.workBookPart;
List<SheetPart> sheetList = wb.getSheetParts();
readSheet(sheetList, new SubProgressMonitor(monitor, 1));
monitor.setTaskName(Messages.getString("msexcel.xliff2mse.task3"));
wb.save();
monitor.worked(1);
try {
ZipUtil.zipFolder(spreadsheetDocFile, SpreadsheetDocument.spreadsheetPackage.getPackageSuperRoot());
} catch (IOException e) {
logger.error("", e);
}
monitor.worked(1);
} finally {
SpreadsheetDocument.close();
monitor.done();
}
}
use of org.eclipse.core.runtime.NullProgressMonitor in project translationstudio8 by heartsome.
the class XliffReader method readSheet.
private void readSheet(List<SheetPart> sheetList, IProgressMonitor monitor) throws InternalFileException {
if (monitor == null) {
monitor = new NullProgressMonitor();
}
monitor.beginTask(Messages.getString("msexcel.xliff2mse.task4"), sheetList.size() * 5);
List<String> sheetNames = new ArrayList<String>();
for (SheetPart sp : sheetList) {
monitor.worked(1);
String name = sp.getName();
name = processContent(name);
// 处理重复名称
int i = 1;
while (sheetNames.contains(name)) {
name += i;
i++;
}
sheetNames.add(name);
sp.setSheetName(name);
// read headers
monitor.worked(1);
List<HeaderFooter> headers = sp.getHeader();
for (HeaderFooter hf : headers) {
String content = hf.getContent();
content = processContent(content);
hf.setContent(content);
}
// update the file
sp.setHeaderFooter(headers);
monitor.worked(1);
DrawingsPart drawingp = sp.getDrawingsPart();
if (drawingp != null) {
List<CellAnchor> aList = drawingp.getCellAnchorList();
for (CellAnchor a : aList) {
List<ShapeTxBody> sList = a.getShapeList();
if (sList.size() == 0) {
continue;
}
for (ShapeTxBody s : sList) {
List<ShapeParagraph> pList = s.getTxBodyParagraghList();
for (ShapeParagraph p : pList) {
String content = p.getXmlContent();
content = processContent(content);
p.setXmlContent(content);
}
}
}
drawingp.updateDrawingObject();
}
monitor.worked(1);
List<Cell> cellList = sp.getCells("s");
for (Cell c : cellList) {
String content = c.getFullContent();
content = processContent(content);
c.setShareStringItemFullContent(content);
}
monitor.worked(1);
// read footer
List<HeaderFooter> footers = sp.getFoolter();
for (HeaderFooter hf : footers) {
String content = hf.getContent();
content = processContent(content);
hf.setContent(content);
}
// update the file
sp.setHeaderFooter(footers);
}
monitor.done();
}
use of org.eclipse.core.runtime.NullProgressMonitor in project translationstudio8 by heartsome.
the class ExportTbxImpl method executeExport.
/**
* (non-Javadoc)
* @see net.heartsome.cat.document.ExportAbstract#executeExport(org.eclipse.core.runtime.IProgressMonitor)
*/
@Override
public String executeExport(IProgressMonitor monitor) {
if (monitor == null) {
monitor = new NullProgressMonitor();
}
String whereResult = "";
if (this.filterBean != null) {
StringBuffer whereBf = new StringBuffer();
String connector = this.filterBean.getFilterConnector();
List<ExportFilterComponentBean> filterOptions = this.filterBean.getFilterOption();
whereBf.append(" AND ");
for (Iterator<ExportFilterComponentBean> iterator = filterOptions.iterator(); iterator.hasNext(); ) {
ExportFilterComponentBean filterBean = iterator.next();
whereBf.append("PURE ");
whereBf.append("LIKE ");
whereBf.append("'%" + filterBean.getFilterVlaue() + "%' ");
whereBf.append(connector + " ");
}
whereResult = whereBf.toString();
whereResult = whereResult.substring(0, whereResult.lastIndexOf(connector));
}
monitor.beginTask("", dbList.size());
for (Iterator<ExportDatabaseBean> iterator = dbList.iterator(); iterator.hasNext(); ) {
ExportDatabaseBean db = iterator.next();
String srcLang = db.getSrcLang();
List<String> needLang = db.getHasSelectedLangs();
DBOperator dbOp = DatabaseService.getDBOperator(db.getDbBean());
try {
dbOp.start();
output = new FileOutputStream(db.getExportFilePath());
writeHeader(srcLang);
writeString("<text>\n<body>\n");
List<Integer> tPkId = dbOp.getAfterFilterTermEntryPK(whereResult, needLang);
// Fix Bug #2361 TBX文件导出问题--语言不能正确过滤导出 by Jason
tPkId = dbOp.validateTermEntryPk(tPkId, needLang, srcLang);
IProgressMonitor subMonitor = new SubProgressMonitor(monitor, 1);
subMonitor.beginTask(Messages.getString("document.ExportTbxImpl.task1") + db.getDbBean().getDatabaseName(), tPkId.size());
subMonitor.setTaskName(Messages.getString("document.ExportTbxImpl.task1") + db.getDbBean().getDatabaseName());
for (int i = 0; i < tPkId.size(); i++) {
// long l = System.currentTimeMillis();
if (monitor.isCanceled()) {
clearResource();
return USER_CANCEL;
}
int termEntryPK = tPkId.get(i);
String termEntry = dbOp.retrieveTermEntry(termEntryPK);
if (termEntry != null && !termEntry.equals("")) {
writeString(termEntry);
}
subMonitor.worked(1);
}
writeString("</body>\n</text>\n</martif>\n");
} catch (SQLException e) {
logger.error(DBOP_ERROR, e);
e.printStackTrace();
clearResource();
return DBOP_ERROR + db.getDbBean().getDbType() + " " + db.getDbBean().getDatabaseName();
} catch (ClassNotFoundException e) {
logger.error(JDBC_ERROR, e);
e.printStackTrace();
clearResource();
return JDBC_ERROR + db.getDbBean().getDbType();
} catch (IOException e) {
logger.error(FILE_ERROR, e);
e.printStackTrace();
clearResource();
return FILE_ERROR + db.getDbBean().getDbType() + " " + db.getDbBean().getDatabaseName();
} finally {
try {
output.close();
if (dbOp != null) {
dbOp.end();
}
} catch (SQLException e) {
logger.error(RELEASE_DB_ERROR, e);
} catch (IOException e) {
logger.error(RELEASE_FILE_ERROR, e);
}
}
filterLangSet(db.getExportFilePath(), srcLang, needLang);
}
monitor.done();
return SUCCESS;
}
use of org.eclipse.core.runtime.NullProgressMonitor in project translationstudio8 by heartsome.
the class ExportTmxImpl method executeExport.
/**
* (non-Javadoc)
* @see net.heartsome.cat.document.ExportAbstract#executeExport()
*/
@Override
public String executeExport(IProgressMonitor monitor) {
String mTuFilter = "";
String textDataFilter = "";
String mNoteFilter = "";
if (monitor == null) {
monitor = new NullProgressMonitor();
}
monitor.beginTask("", dbList.size());
for (Iterator<ExportDatabaseBean> iterator = dbList.iterator(); iterator.hasNext(); ) {
ExportDatabaseBean db = iterator.next();
String srcLang = db.getSrcLang();
DBOperator dbOp = DatabaseService.getDBOperator(db.getDbBean());
// 过滤条件
if (this.filterBean != null) {
mTuFilter = dbOp.generationExportTMXFilter("MTU", this.filterBean);
textDataFilter = dbOp.generationExportTMXFilter("TEXTDATA", this.filterBean);
mNoteFilter = dbOp.generationExportTMXFilter("MNOTE", this.filterBean);
}
try {
dbOp.start();
output = new FileOutputStream(db.getExportFilePath());
if (encoding.equalsIgnoreCase("UTF-16LE")) {
output.write(0xFF);
output.write(0xFE);
} else if (encoding.equalsIgnoreCase("UTF-16BE")) {
output.write(0xFE);
output.write(0xFF);
}
List<Integer> filterTu = dbOp.getAfterFilterTuPk(mTuFilter, mNoteFilter, textDataFilter);
writeHeader(srcLang);
writeString("<body>\n");
IProgressMonitor subMonitor = new SubProgressMonitor(monitor, 1);
subMonitor.beginTask(Messages.getString("document.ExportTmxImpl.task1") + db.getDbBean().getDatabaseName(), filterTu.size());
subMonitor.setTaskName(Messages.getString("document.ExportTmxImpl.task1") + db.getDbBean().getDatabaseName());
for (int i = 0; i < filterTu.size(); i++) {
// long l = System.currentTimeMillis();
if (monitor.isCanceled()) {
clearResource();
break;
}
int tuPk = filterTu.get(i);
String tuNodeContent = dbOp.retrieveTu(tuPk, db.getHasSelectedLangs(), isToplevelTmx, isTagLevelTmx);
if (tuNodeContent != null && !tuNodeContent.equals("")) {
writeString(tuNodeContent);
}
subMonitor.worked(1);
}
//$NON-NLS-1$
writeString("</body>\n");
//$NON-NLS-1$
writeString("</tmx>\n");
subMonitor.done();
} catch (SQLException e) {
logger.error(DBOP_ERROR, e);
e.printStackTrace();
clearResource();
return DBOP_ERROR + db.getDbBean().getDbType() + " " + db.getDbBean().getDatabaseName();
} catch (ClassNotFoundException e) {
logger.error(JDBC_ERROR, e);
e.printStackTrace();
clearResource();
return JDBC_ERROR + db.getDbBean().getDbType();
} catch (IOException e) {
logger.error(FILE_ERROR, e);
e.printStackTrace();
clearResource();
return FILE_ERROR + db.getDbBean().getDbType() + " " + db.getDbBean().getDatabaseName();
} finally {
try {
output.close();
if (dbOp != null) {
dbOp.end();
}
} catch (SQLException e) {
logger.error(RELEASE_DB_ERROR, e);
} catch (IOException e) {
logger.error(RELEASE_FILE_ERROR, e);
}
}
}
if (monitor.isCanceled()) {
return USER_CANCEL;
}
monitor.done();
return SUCCESS;
}
use of org.eclipse.core.runtime.NullProgressMonitor in project translationstudio8 by heartsome.
the class TestWord2007 method docx2Xliff.
public void docx2Xliff() {
try {
// String inputFile = "/home/robert/Desktop/测试简单word文档.docx";
// String inputFile = "/home/robert/Desktop/Word2007 for test.docx";
// String xliffFile = "/home/robert/workspace/runtime-UltimateEdition.product/testDocxConverter/XLIFF/zh-CN/测试简单word文档.docx.hsxliff";
// String sourceLanguage = "en-US";
// String targetLanguage = "zh-CN";
// String srx = "/home/robert/workspace/newR8/.metadata/.plugins/org.eclipse.pde.core/UltimateEdition.product/net.heartsome.cat.converter/srx/default_rules.srx";
// String catalogue = "/home/robert/workspace/newR8/.metadata/.plugins/org.eclipse.pde.core/UltimateEdition.product/net.heartsome.cat.converter/catalogue/catalogue.xml";
String inputFile = "C:\\Users\\Administrator\\Desktop\\test word 2007 converter\\测试简单word文档.docx";
// String inputFile = "C:\\Users\\Administrator\\Desktop\\test word 2007 converter\\Word2007 for test.docx";
String xliffFile = "E:\\workspaces\\runtime-UltimateEdition.product\\testWord2007Convert\\XLIFF\\zh-CN\\测试简单word文档.docx.hsxliff";
String sourceLanguage = "en-US";
String targetLanguage = "zh-CN";
String srx = "E:\\workspaces\\newR8\\.metadata\\.plugins\\org.eclipse.pde.core\\UltimateEdition.product\\net.heartsome.cat.converter\\srx\\default_rules.srx";
String catalogue = "E:\\workspaces\\newR8\\.metadata\\.plugins\\org.eclipse.pde.core\\UltimateEdition.product\\net.heartsome.cat.converter\\catalogue\\catalogue.xml";
StringSegmenter segmenter = new StringSegmenter(srx, sourceLanguage, catalogue);
// 先解压 docx 文件
String docxFolderPath = ZipUtil.upZipFile(inputFile, null);
PathUtil pathUtil = new PathUtil(docxFolderPath);
// 定义一个 hsxliff 文件的写入方法
xlfOutput = new XliffOutputer(xliffFile, sourceLanguage, targetLanguage);
xlfOutput.writeHeader(inputFile, "skeletonFile", true, "UTF-8", "");
// 先从主文档 document 文件入手
String docPath = pathUtil.getPackageFilePath(PathConstant.DOCUMENT, false);
DocumentPart docPart = new DocumentPart(docPath, pathUtil, xlfOutput, segmenter, inputFile, new NullProgressMonitor());
docPart.converter();
System.out.println("--------------");
xlfOutput.outputEndTag();
// 开始将文件进行压缩
// String zipPath = "/home/robert/Desktop/word 2007 skeleton/" + new File(pathUtil.getSuperRoot()).getName();
String zipPath = "C:\\Users\\Administrator\\Desktop\\word 2007 skeleton\\" + new File(pathUtil.getSuperRoot()).getName();
ZipUtil.zipFolder(zipPath, pathUtil.getSuperRoot());
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
xlfOutput.close();
System.out.println("----------");
} catch (Exception e2) {
e2.printStackTrace();
}
}
}
Aggregations