Search in sources :

Example 6 with InternalFileException

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);
    }
}
Also used : VTDUtils(net.heartsome.xml.vtdimpl.VTDUtils) VTDException(com.ximpleware.VTDException) VTDGen(com.ximpleware.VTDGen) IOException(java.io.IOException) File(java.io.File) FileInputStream(java.io.FileInputStream) InternalFileException(net.heartsome.cat.converter.msexcel2007.common.InternalFileException) InternalFileException(net.heartsome.cat.converter.msexcel2007.common.InternalFileException) IOException(java.io.IOException) VTDException(com.ximpleware.VTDException)

Example 7 with InternalFileException

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;
}
Also used : VTDException(com.ximpleware.VTDException) AutoPilot(com.ximpleware.AutoPilot) InternalFileException(net.heartsome.cat.converter.msexcel2007.common.InternalFileException)

Example 8 with InternalFileException

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();
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) WorkBookPart(net.heartsome.cat.converter.msexcel2007.document.WorkBookPart) SheetPart(net.heartsome.cat.converter.msexcel2007.document.SheetPart) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Example 9 with InternalFileException

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();
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) SheetPart(net.heartsome.cat.converter.msexcel2007.document.SheetPart) HeaderFooter(net.heartsome.cat.converter.msexcel2007.document.HeaderFooter) DrawingsPart(net.heartsome.cat.converter.msexcel2007.document.DrawingsPart) Cell(net.heartsome.cat.converter.msexcel2007.document.Cell)

Example 10 with InternalFileException

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);
    }
}
Also used : XMLModifier(com.ximpleware.XMLModifier) VTDUtils(net.heartsome.xml.vtdimpl.VTDUtils) VTDException(com.ximpleware.VTDException) VTDGen(com.ximpleware.VTDGen) IOException(java.io.IOException) File(java.io.File) FileInputStream(java.io.FileInputStream) InternalFileException(net.heartsome.cat.converter.msexcel2007.common.InternalFileException) InternalFileException(net.heartsome.cat.converter.msexcel2007.common.InternalFileException) IOException(java.io.IOException) VTDException(com.ximpleware.VTDException)

Aggregations

VTDException (com.ximpleware.VTDException)7 InternalFileException (net.heartsome.cat.converter.msexcel2007.common.InternalFileException)7 IOException (java.io.IOException)5 AutoPilot (com.ximpleware.AutoPilot)4 SheetPart (net.heartsome.cat.converter.msexcel2007.document.SheetPart)4 Relationship (net.heartsome.cat.converter.msexcel2007.document.rels.Relationship)4 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)4 File (java.io.File)3 VTDGen (com.ximpleware.VTDGen)2 FileInputStream (java.io.FileInputStream)2 FileNotFoundException (java.io.FileNotFoundException)2 Cell (net.heartsome.cat.converter.msexcel2007.document.Cell)2 DrawingsPart (net.heartsome.cat.converter.msexcel2007.document.DrawingsPart)2 HeaderFooter (net.heartsome.cat.converter.msexcel2007.document.HeaderFooter)2 WorkBookPart (net.heartsome.cat.converter.msexcel2007.document.WorkBookPart)2 CellAnchor (net.heartsome.cat.converter.msexcel2007.document.drawing.CellAnchor)2 VTDUtils (net.heartsome.xml.vtdimpl.VTDUtils)2 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)2 XMLModifier (com.ximpleware.XMLModifier)1 FileOutputStream (java.io.FileOutputStream)1