Search in sources :

Example 1 with Relationship

use of net.heartsome.cat.converter.msexcel2007.document.rels.Relationship in project translationstudio8 by heartsome.

the class SheetPart method loadDrawingsPart.

private void loadDrawingsPart() throws InternalFileException {
    String xpath = "/worksheet/drawing";
    AutoPilot ap = new AutoPilot(vu.getVTDNav());
    try {
        ap.selectXPath(xpath);
        if (ap.evalXPath() != -1) {
            Hashtable<String, String> attrs = vu.getCurrentElementAttributs();
            SpreadsheetUtil.assertNull(attrs);
            String rId = attrs.get("r:id");
            Relationship r = relsPart.getRelationshipById(rId);
            SpreadsheetUtil.assertNull(r);
            SpreadsheetDocument.spreadsheetPackage.markRoot();
            try {
                this.drawingsPart = new DrawingsPart(r.getTarget());
            } catch (FileNotFoundException e) {
            // no drawingsPart
            }
            SpreadsheetDocument.spreadsheetPackage.resetRoot();
        }
    } catch (VTDException e) {
        logger.error("", e);
    }
}
Also used : VTDException(com.ximpleware.VTDException) AutoPilot(com.ximpleware.AutoPilot) Relationship(net.heartsome.cat.converter.msexcel2007.document.rels.Relationship) FileNotFoundException(java.io.FileNotFoundException)

Example 2 with Relationship

use of net.heartsome.cat.converter.msexcel2007.document.rels.Relationship in project translationstudio8 by heartsome.

the class WorkBookPart method loadSytlesPart.

private void loadSytlesPart() throws InternalFileException, FileNotFoundException {
    List<Relationship> rList = relsPart.getRelationshipByType(Constants.PART_TYPE_STYLE);
    if (rList.size() != 1) {
        throw new InternalFileException(Messages.getString("msexcel.converter.exception.msg1"));
    }
    Relationship r = rList.get(0);
    stylePart = new StylesPart(r.getTarget());
}
Also used : Relationship(net.heartsome.cat.converter.msexcel2007.document.rels.Relationship) InternalFileException(net.heartsome.cat.converter.msexcel2007.common.InternalFileException)

Example 3 with Relationship

use of net.heartsome.cat.converter.msexcel2007.document.rels.Relationship in project translationstudio8 by heartsome.

the class WorkBookPart method loadWorkSheets.

private void loadWorkSheets() throws InternalFileException, FileNotFoundException {
    sheetPartList = new ArrayList<SheetPart>();
    int ssiIndex = 0;
    StringBuffer siBf = new StringBuffer();
    try {
        String xpath = "/workbook/sheets/sheet";
        AutoPilot ap = new AutoPilot(vu.getVTDNav());
        ap.selectXPath(xpath);
        while (ap.evalXPath() != -1) {
            int index = vu.getVTDNav().getAttrVal("name");
            if (index == -1) {
                throw new InternalFileException(Messages.getString("msexcel.converter.exception.msg1"));
            }
            String name = vu.getVTDNav().toRawString(index);
            index = vu.getVTDNav().getAttrVal("sheetId");
            if (index == -1) {
                throw new InternalFileException(Messages.getString("msexcel.converter.exception.msg1"));
            }
            String id = vu.getVTDNav().toRawString(index);
            index = vu.getVTDNav().getAttrVal("r:id");
            if (index == -1) {
                throw new InternalFileException(Messages.getString("msexcel.converter.exception.msg1"));
            }
            String rid = vu.getVTDNav().toRawString(index);
            Relationship r = relsPart.getRelationshipById(rid);
            SpreadsheetUtil.assertNull(r);
            String target = r.getTarget();
            SheetPart sp = new SheetPart(name, id, target);
            ssiIndex = sp.fillShareStringTable(sst, ssiIndex, siBf);
            sheetPartList.add(sp);
        }
        // fix bug Bug #2925 转换excel文件--空指针异常,转换失败 by jason
        if (sst != null && siBf.length() != 0) {
            sst.updateShareStringTable(siBf.toString());
        }
    } catch (VTDException e) {
        logger.error("", e);
    } catch (IOException e) {
    }
}
Also used : VTDException(com.ximpleware.VTDException) AutoPilot(com.ximpleware.AutoPilot) Relationship(net.heartsome.cat.converter.msexcel2007.document.rels.Relationship) IOException(java.io.IOException) InternalFileException(net.heartsome.cat.converter.msexcel2007.common.InternalFileException)

Example 4 with Relationship

use of net.heartsome.cat.converter.msexcel2007.document.rels.Relationship in project translationstudio8 by heartsome.

the class RelsPart method loadRealtionship.

public void loadRealtionship() {
    relationships = new ArrayList<Relationship>();
    String xpath = "/Relationships/Relationship";
    AutoPilot ap = new AutoPilot(vu.getVTDNav());
    try {
        ap.selectXPath(xpath);
        while (ap.evalXPath() != -1) {
            Hashtable<String, String> attrs = vu.getCurrentElementAttributs();
            if (attrs == null) {
            // TODO Error
            }
            String id = attrs.get("Id");
            String type = attrs.get("Type");
            String target = attrs.get("Target");
            Relationship rsp = new Relationship(id, type, target);
            relationships.add(rsp);
        }
    } catch (VTDException e) {
        logger.error("", e);
    }
}
Also used : VTDException(com.ximpleware.VTDException) AutoPilot(com.ximpleware.AutoPilot) Relationship(net.heartsome.cat.converter.msexcel2007.document.rels.Relationship)

Example 5 with Relationship

use of net.heartsome.cat.converter.msexcel2007.document.rels.Relationship in project translationstudio8 by heartsome.

the class WorkBookPart method loadShareStringTable.

private void loadShareStringTable() throws InternalFileException {
    List<Relationship> rList = relsPart.getRelationshipByType(Constants.PART_TYPE_SST);
    if (rList.size() != 1) {
        return;
    }
    Relationship r = rList.get(0);
    try {
        sst = new ShareStringTablePart(r.getTarget());
    } catch (FileNotFoundException e) {
    // 可能没有sharedStrings.xml
    }
}
Also used : Relationship(net.heartsome.cat.converter.msexcel2007.document.rels.Relationship) FileNotFoundException(java.io.FileNotFoundException)

Aggregations

Relationship (net.heartsome.cat.converter.msexcel2007.document.rels.Relationship)5 AutoPilot (com.ximpleware.AutoPilot)3 VTDException (com.ximpleware.VTDException)3 FileNotFoundException (java.io.FileNotFoundException)2 InternalFileException (net.heartsome.cat.converter.msexcel2007.common.InternalFileException)2 IOException (java.io.IOException)1