use of net.heartsome.cat.converter.msexcel2007.common.InternalFileException in project translationstudio8 by heartsome.
the class XliffReader method loadFile.
private void loadFile(String file) throws InternalFileException {
File f = new File(file);
VTDGen vg = new VTDGen();
FileInputStream fis = null;
byte[] b = new byte[(int) f.length()];
try {
fis = new FileInputStream(f);
fis.read(b);
} catch (IOException e) {
throw new InternalFileException(Messages.getString("msexcel.converter.exception.msg1"));
} finally {
if (fis != null) {
try {
fis.close();
} catch (Exception e) {
logger.error("", e);
}
}
}
vg.setDoc(b);
try {
vg.parse(true);
vu = new VTDUtils(vg.getNav());
} catch (VTDException e) {
String message = Messages.getString("msexcel.converter.exception.msg1");
message += "\nFile:" + f.getName() + "\n" + e.getMessage();
throw new InternalFileException(message);
}
}
use of net.heartsome.cat.converter.msexcel2007.common.InternalFileException in project translationstudio8 by heartsome.
the class XliffReader method getTargetById.
private String getTargetById(String id) throws InternalFileException {
String result = null;
String xpath = "/xliff/file/body/trans-unit[@id='" + id + "']";
AutoPilot ap = new AutoPilot(vu.getVTDNav());
try {
ap.selectXPath(xpath);
if (ap.evalXPath() != -1) {
String text = vu.getChildContent("./target");
if (text == null) {
text = vu.getChildContent("./target");
vu.pilot("./source");
} else {
vu.pilot("./target");
}
Map<Integer, String[]> anaysisRs = anaysisTarget();
result = converterAnaysisResult(anaysisRs);
}
} catch (VTDException e) {
logger.error("", e);
}
if (result == null) {
throw new InternalFileException(MessageFormat.format(Messages.getString("msexcel.xliff2mse.msg1"), id));
}
return result;
}
use of net.heartsome.cat.converter.msexcel2007.common.InternalFileException in project translationstudio8 by heartsome.
the class SpreadsheetReader method read2XliffFile.
/**
* 将内容读入到XLIFF文件
* @param xlfOs
* XLIFF文件BufferWriter
* @param filterRedCell
* 是否需要过滤标记为红色的单元格
* @param monitor
* @throws InternalFileException
* @throws IOException
* ;
*/
public void read2XliffFile(String inputFile, BufferedWriter xlfOs, String sklFilePath, boolean filterRedCell, IProgressMonitor monitor) throws InternalFileException, IOException {
this.xlfOs = xlfOs;
if (monitor == null) {
monitor = new NullProgressMonitor();
}
monitor.beginTask("", 5);
try {
monitor.setTaskName(Messages.getString("msexcel.mse2xliff.task2"));
// open source file
SpreadsheetDocument.open(inputFile);
monitor.worked(1);
monitor.setTaskName(Messages.getString("msexcel.mse2xliff.task3"));
// load current workbook
WorkBookPart wb = SpreadsheetDocument.workBookPart;
if (filterRedCell) {
this.filterStyleIndex = wb.getStylesPart().getFilterCellStyle();
}
// read worksheet
List<SheetPart> sheetList = wb.getSheetParts();
readSheets(sheetList, new SubProgressMonitor(monitor, 2));
// save current document
wb.save();
monitor.worked(1);
monitor.setTaskName(Messages.getString("msexcel.mse2xliff.task4"));
// generate skl file
saveSklFile(sklFilePath);
monitor.worked(1);
} finally {
SpreadsheetDocument.close();
}
monitor.done();
}
use of net.heartsome.cat.converter.msexcel2007.common.InternalFileException in project translationstudio8 by heartsome.
the class SpreadsheetReader method readSheets.
private void readSheets(List<SheetPart> sheetList, IProgressMonitor monitor) throws InternalFileException, IOException {
if (monitor == null) {
monitor = new NullProgressMonitor();
}
monitor.beginTask("", sheetList.size() * 5);
for (SheetPart sp : sheetList) {
// process sheet name
String name = sp.getName();
writeXliffFile(xliffIdex, name);
sp.setSheetName("%%%" + xliffIdex + "%%%");
xliffIdex++;
monitor.worked(1);
// read headers
List<HeaderFooter> headers = sp.getHeader();
readHeaderFooters(headers);
// update the file
sp.setHeaderFooter(headers);
monitor.worked(1);
// read drawing part
DrawingsPart drawingp = sp.getDrawingsPart();
if (drawingp != null) {
readDrawings(drawingp);
drawingp.updateDrawingObject();
}
monitor.worked(1);
List<Cell> cellList = sp.getCells("s");
for (Cell c : cellList) {
if (filterStyleIndex.contains(c.getStyleIndex())) {
// skip this cell
continue;
}
String cellText = c.getValue();
if (cellText == null || cellText.trim().length() == 0) {
// ignore the cell
continue;
}
List<Object[]> cellStyle = c.getCellCharacterStyles();
String[] segs = segmenter.segment(cellText);
StringBuffer bf = new StringBuffer();
for (String seg : segs) {
List<Object[]> s = ReaderUtil.getSegStyle(cellStyle, seg, cellText);
if (s.size() != 0) {
seg = ReaderUtil.appendSegStyle(seg, s);
}
bf.append("%%%").append(xliffIdex++).append("%%%");
// System.out.println(xliffIdex + ":" + seg);
writeXliffFile(xliffIdex - 1, seg);
}
c.setValue(bf.toString());
}
monitor.worked(1);
// read headers
List<HeaderFooter> footers = sp.getFoolter();
readHeaderFooters(footers);
// update the file
sp.setHeaderFooter(footers);
monitor.worked(1);
}
monitor.done();
}
use of net.heartsome.cat.converter.msexcel2007.common.InternalFileException in project translationstudio8 by heartsome.
the class AbstractPart method loadFile.
protected void loadFile() throws InternalFileException {
File f = new File(this.partXmlPath);
VTDGen vg = new VTDGen();
FileInputStream fis = null;
byte[] b = new byte[(int) f.length()];
try {
fis = new FileInputStream(f);
fis.read(b);
} catch (IOException e) {
throw new InternalFileException(Messages.getString("msexcel.converter.exception.msg1"));
} finally {
if (fis != null) {
try {
fis.close();
} catch (Exception e) {
logger.error("", e);
}
}
}
vg.setDoc(b);
try {
vg.parse(true);
vu = new VTDUtils(vg.getNav());
xm = new XMLModifier(vu.getVTDNav());
} catch (VTDException e) {
String message = Messages.getString("msexcel.converter.exception.msg1");
message += "\nFile:" + f.getName() + "\n" + e.getMessage();
throw new InternalFileException(message);
}
}
Aggregations