Search in sources :

Example 1 with RecordFormatException

use of org.apache.poi.util.RecordFormatException in project poi by apache.

the class EscherDggRecord method fillFields.

@Override
public int fillFields(byte[] data, int offset, EscherRecordFactory recordFactory) {
    int bytesRemaining = readHeader(data, offset);
    int pos = offset + 8;
    int size = 0;
    field_1_shapeIdMax = LittleEndian.getInt(data, pos + size);
    size += 4;
    // field_2_numIdClusters = LittleEndian.getInt( data, pos + size );
    size += 4;
    field_3_numShapesSaved = LittleEndian.getInt(data, pos + size);
    size += 4;
    field_4_drawingsSaved = LittleEndian.getInt(data, pos + size);
    size += 4;
    // Can't rely on field_2_numIdClusters
    field_5_fileIdClusters = new FileIdCluster[(bytesRemaining - size) / 8];
    for (int i = 0; i < field_5_fileIdClusters.length; i++) {
        field_5_fileIdClusters[i] = new FileIdCluster(LittleEndian.getInt(data, pos + size), LittleEndian.getInt(data, pos + size + 4));
        maxDgId = Math.max(maxDgId, field_5_fileIdClusters[i].getDrawingGroupId());
        size += 8;
    }
    bytesRemaining -= size;
    if (bytesRemaining != 0)
        throw new RecordFormatException("Expecting no remaining data but got " + bytesRemaining + " byte(s).");
    return 8 + size + bytesRemaining;
}
Also used : RecordFormatException(org.apache.poi.util.RecordFormatException)

Example 2 with RecordFormatException

use of org.apache.poi.util.RecordFormatException in project poi by apache.

the class EscherSpgrRecord method fillFields.

@Override
public int fillFields(byte[] data, int offset, EscherRecordFactory recordFactory) {
    int bytesRemaining = readHeader(data, offset);
    int pos = offset + 8;
    int size = 0;
    field_1_rectX1 = LittleEndian.getInt(data, pos + size);
    size += 4;
    field_2_rectY1 = LittleEndian.getInt(data, pos + size);
    size += 4;
    field_3_rectX2 = LittleEndian.getInt(data, pos + size);
    size += 4;
    field_4_rectY2 = LittleEndian.getInt(data, pos + size);
    size += 4;
    bytesRemaining -= size;
    if (bytesRemaining != 0)
        throw new RecordFormatException("Expected no remaining bytes but got " + bytesRemaining);
    //        System.arraycopy( data, pos + size, remainingData, 0, bytesRemaining );
    return 8 + size + bytesRemaining;
}
Also used : RecordFormatException(org.apache.poi.util.RecordFormatException)

Example 3 with RecordFormatException

use of org.apache.poi.util.RecordFormatException in project poi by apache.

the class InternalWorkbook method cloneDrawings.

/**
     * Check if the cloned sheet has drawings. If yes, then allocate a new drawing group ID and
     * re-generate shape IDs
     *
     * @param sheet the cloned sheet
     */
public void cloneDrawings(InternalSheet sheet) {
    findDrawingGroup();
    if (drawingManager == null) {
        //this workbook does not have drawings
        return;
    }
    //check if the cloned sheet has drawings
    int aggLoc = sheet.aggregateDrawingRecords(drawingManager, false);
    if (aggLoc == -1) {
        return;
    }
    EscherAggregate agg = (EscherAggregate) sheet.findFirstRecordBySid(EscherAggregate.sid);
    EscherContainerRecord escherContainer = agg.getEscherContainer();
    if (escherContainer == null) {
        return;
    }
    EscherDggRecord dgg = drawingManager.getDgg();
    //register a new drawing group for the cloned sheet
    int dgId = drawingManager.findNewDrawingGroupId();
    dgg.addCluster(dgId, 0);
    dgg.setDrawingsSaved(dgg.getDrawingsSaved() + 1);
    EscherDgRecord dg = null;
    for (EscherRecord er : escherContainer) {
        if (er instanceof EscherDgRecord) {
            dg = (EscherDgRecord) er;
            //update id of the drawing in the cloned sheet
            dg.setOptions((short) (dgId << 4));
        } else if (er instanceof EscherContainerRecord) {
            // iterate over shapes and re-generate shapeId
            for (EscherRecord er2 : (EscherContainerRecord) er) {
                for (EscherRecord shapeChildRecord : (EscherContainerRecord) er2) {
                    int recordId = shapeChildRecord.getRecordId();
                    if (recordId == EscherSpRecord.RECORD_ID) {
                        if (dg == null) {
                            throw new RecordFormatException("EscherDgRecord wasn't set/processed before.");
                        }
                        EscherSpRecord sp = (EscherSpRecord) shapeChildRecord;
                        int shapeId = drawingManager.allocateShapeId((short) dgId, dg);
                        //allocateShapeId increments the number of shapes. roll back to the previous value
                        dg.setNumShapes(dg.getNumShapes() - 1);
                        sp.setShapeId(shapeId);
                    } else if (recordId == EscherOptRecord.RECORD_ID) {
                        EscherOptRecord opt = (EscherOptRecord) shapeChildRecord;
                        EscherSimpleProperty prop = (EscherSimpleProperty) opt.lookup(EscherProperties.BLIP__BLIPTODISPLAY);
                        if (prop != null) {
                            int pictureIndex = prop.getPropertyValue();
                            // increment reference count for pictures
                            EscherBSERecord bse = getBSERecord(pictureIndex);
                            bse.setRef(bse.getRef() + 1);
                        }
                    }
                }
            }
        }
    }
}
Also used : EscherAggregate(org.apache.poi.hssf.record.EscherAggregate) RecordFormatException(org.apache.poi.util.RecordFormatException) EscherSimpleProperty(org.apache.poi.ddf.EscherSimpleProperty) EscherSpRecord(org.apache.poi.ddf.EscherSpRecord) EscherContainerRecord(org.apache.poi.ddf.EscherContainerRecord) EscherDggRecord(org.apache.poi.ddf.EscherDggRecord) EscherDgRecord(org.apache.poi.ddf.EscherDgRecord) EscherRecord(org.apache.poi.ddf.EscherRecord) EscherOptRecord(org.apache.poi.ddf.EscherOptRecord) EscherBSERecord(org.apache.poi.ddf.EscherBSERecord)

Example 4 with RecordFormatException

use of org.apache.poi.util.RecordFormatException in project poi by apache.

the class InternalWorkbook method createWorkbook.

/**
     * read support  for low level
     * API.  Pass in an array of Record objects, A Workbook
     * object is constructed and passed back with all of its initialization set
     * to the passed in records and references to those records held. Unlike Sheet
     * workbook does not use an offset (its assumed to be 0) since its first in a file.
     * If you need an offset then construct a new array with a 0 offset or write your
     * own ;-p.
     *
     * @param recs an array of Record objects
     * @return Workbook object
     */
public static InternalWorkbook createWorkbook(List<Record> recs) {
    LOG.log(DEBUG, "Workbook (readfile) created with reclen=", recs.size());
    InternalWorkbook retval = new InternalWorkbook();
    List<Record> records = new ArrayList<Record>(recs.size() / 3);
    retval.records.setRecords(records);
    boolean eofPassed = false;
    for (int k = 0; k < recs.size(); k++) {
        Record rec = recs.get(k);
        String logObj;
        switch(rec.getSid()) {
            case EOFRecord.sid:
                logObj = "workbook eof";
                break;
            case BoundSheetRecord.sid:
                logObj = "boundsheet";
                retval.boundsheets.add((BoundSheetRecord) rec);
                retval.records.setBspos(k);
                break;
            case SSTRecord.sid:
                logObj = "sst";
                retval.sst = (SSTRecord) rec;
                break;
            case FontRecord.sid:
                logObj = "font";
                retval.records.setFontpos(k);
                retval.numfonts++;
                break;
            case ExtendedFormatRecord.sid:
                logObj = "XF";
                retval.records.setXfpos(k);
                retval.numxfs++;
                break;
            case TabIdRecord.sid:
                logObj = "tabid";
                retval.records.setTabpos(k);
                break;
            case ProtectRecord.sid:
                logObj = "protect";
                retval.records.setProtpos(k);
                break;
            case BackupRecord.sid:
                logObj = "backup";
                retval.records.setBackuppos(k);
                break;
            case ExternSheetRecord.sid:
                throw new RecordFormatException("Extern sheet is part of LinkTable");
            case NameRecord.sid:
            case SupBookRecord.sid:
                // LinkTable can start with either of these
                LOG.log(DEBUG, "found SupBook record at " + k);
                retval.linkTable = new LinkTable(recs, k, retval.records, retval.commentRecords);
                k += retval.linkTable.getRecordCount() - 1;
                continue;
            case FormatRecord.sid:
                logObj = "format";
                FormatRecord fr = (FormatRecord) rec;
                retval.formats.add(fr);
                retval.maxformatid = retval.maxformatid >= fr.getIndexCode() ? retval.maxformatid : fr.getIndexCode();
                break;
            case DateWindow1904Record.sid:
                logObj = "datewindow1904";
                retval.uses1904datewindowing = ((DateWindow1904Record) rec).getWindowing() == 1;
                break;
            case PaletteRecord.sid:
                logObj = "palette";
                retval.records.setPalettepos(k);
                break;
            case WindowOneRecord.sid:
                logObj = "WindowOneRecord";
                retval.windowOne = (WindowOneRecord) rec;
                break;
            case WriteAccessRecord.sid:
                logObj = "WriteAccess";
                retval.writeAccess = (WriteAccessRecord) rec;
                break;
            case WriteProtectRecord.sid:
                logObj = "WriteProtect";
                retval.writeProtect = (WriteProtectRecord) rec;
                break;
            case FileSharingRecord.sid:
                logObj = "FileSharing";
                retval.fileShare = (FileSharingRecord) rec;
                break;
            case NameCommentRecord.sid:
                logObj = "NameComment";
                final NameCommentRecord ncr = (NameCommentRecord) rec;
                retval.commentRecords.put(ncr.getNameText(), ncr);
                break;
            case HyperlinkRecord.sid:
                // Look for other interesting values that follow the EOFRecord
                logObj = "Hyperlink";
                retval.hyperlinks.add((HyperlinkRecord) rec);
                break;
            default:
                logObj = "(sid=" + rec.getSid() + ")";
                break;
        }
        if (!eofPassed) {
            records.add(rec);
        }
        LOG.log(DEBUG, "found " + logObj + " record at " + k);
        if (rec.getSid() == EOFRecord.sid) {
            eofPassed = true;
        }
    }
    if (retval.windowOne == null) {
        retval.windowOne = createWindowOne();
    }
    LOG.log(DEBUG, "exit create workbook from existing file function");
    return retval;
}
Also used : RecordFormatException(org.apache.poi.util.RecordFormatException) ArrayList(java.util.ArrayList) WindowProtectRecord(org.apache.poi.hssf.record.WindowProtectRecord) PasswordRev4Record(org.apache.poi.hssf.record.PasswordRev4Record) DateWindow1904Record(org.apache.poi.hssf.record.DateWindow1904Record) FormatRecord(org.apache.poi.hssf.record.FormatRecord) BookBoolRecord(org.apache.poi.hssf.record.BookBoolRecord) StyleRecord(org.apache.poi.hssf.record.StyleRecord) RecalcIdRecord(org.apache.poi.hssf.record.RecalcIdRecord) EscherBSERecord(org.apache.poi.ddf.EscherBSERecord) EscherOptRecord(org.apache.poi.ddf.EscherOptRecord) HideObjRecord(org.apache.poi.hssf.record.HideObjRecord) Record(org.apache.poi.hssf.record.Record) EscherContainerRecord(org.apache.poi.ddf.EscherContainerRecord) HyperlinkRecord(org.apache.poi.hssf.record.HyperlinkRecord) ProtectionRev4Record(org.apache.poi.hssf.record.ProtectionRev4Record) EOFRecord(org.apache.poi.hssf.record.EOFRecord) MMSRecord(org.apache.poi.hssf.record.MMSRecord) PrecisionRecord(org.apache.poi.hssf.record.PrecisionRecord) BoundSheetRecord(org.apache.poi.hssf.record.BoundSheetRecord) CountryRecord(org.apache.poi.hssf.record.CountryRecord) EscherSpRecord(org.apache.poi.ddf.EscherSpRecord) NameCommentRecord(org.apache.poi.hssf.record.NameCommentRecord) FnGroupCountRecord(org.apache.poi.hssf.record.FnGroupCountRecord) DrawingGroupRecord(org.apache.poi.hssf.record.DrawingGroupRecord) BackupRecord(org.apache.poi.hssf.record.BackupRecord) EscherSplitMenuColorsRecord(org.apache.poi.ddf.EscherSplitMenuColorsRecord) ExternSheetRecord(org.apache.poi.hssf.record.ExternSheetRecord) WriteAccessRecord(org.apache.poi.hssf.record.WriteAccessRecord) EscherDggRecord(org.apache.poi.ddf.EscherDggRecord) CodepageRecord(org.apache.poi.hssf.record.CodepageRecord) EscherRecord(org.apache.poi.ddf.EscherRecord) NameRecord(org.apache.poi.hssf.record.NameRecord) BOFRecord(org.apache.poi.hssf.record.BOFRecord) FilePassRecord(org.apache.poi.hssf.record.FilePassRecord) FontRecord(org.apache.poi.hssf.record.FontRecord) UseSelFSRecord(org.apache.poi.hssf.record.UseSelFSRecord) WindowOneRecord(org.apache.poi.hssf.record.WindowOneRecord) WriteProtectRecord(org.apache.poi.hssf.record.WriteProtectRecord) ProtectRecord(org.apache.poi.hssf.record.ProtectRecord) InterfaceHdrRecord(org.apache.poi.hssf.record.InterfaceHdrRecord) DSFRecord(org.apache.poi.hssf.record.DSFRecord) InterfaceEndRecord(org.apache.poi.hssf.record.InterfaceEndRecord) SupBookRecord(org.apache.poi.hssf.record.SupBookRecord) SSTRecord(org.apache.poi.hssf.record.SSTRecord) TabIdRecord(org.apache.poi.hssf.record.TabIdRecord) PasswordRecord(org.apache.poi.hssf.record.PasswordRecord) PaletteRecord(org.apache.poi.hssf.record.PaletteRecord) EscherDgRecord(org.apache.poi.ddf.EscherDgRecord) ExtSSTRecord(org.apache.poi.hssf.record.ExtSSTRecord) ExtendedFormatRecord(org.apache.poi.hssf.record.ExtendedFormatRecord) FileSharingRecord(org.apache.poi.hssf.record.FileSharingRecord) RefreshAllRecord(org.apache.poi.hssf.record.RefreshAllRecord) UnicodeString(org.apache.poi.hssf.record.common.UnicodeString) DateWindow1904Record(org.apache.poi.hssf.record.DateWindow1904Record) FormatRecord(org.apache.poi.hssf.record.FormatRecord) ExtendedFormatRecord(org.apache.poi.hssf.record.ExtendedFormatRecord) NameCommentRecord(org.apache.poi.hssf.record.NameCommentRecord)

Example 5 with RecordFormatException

use of org.apache.poi.util.RecordFormatException in project poi by apache.

the class EscherSplitMenuColorsRecord method fillFields.

@Override
public int fillFields(byte[] data, int offset, EscherRecordFactory recordFactory) {
    int bytesRemaining = readHeader(data, offset);
    int pos = offset + 8;
    int size = 0;
    field_1_color1 = LittleEndian.getInt(data, pos + size);
    size += 4;
    field_2_color2 = LittleEndian.getInt(data, pos + size);
    size += 4;
    field_3_color3 = LittleEndian.getInt(data, pos + size);
    size += 4;
    field_4_color4 = LittleEndian.getInt(data, pos + size);
    size += 4;
    bytesRemaining -= size;
    if (bytesRemaining != 0)
        throw new RecordFormatException("Expecting no remaining data but got " + bytesRemaining + " byte(s).");
    return 8 + size + bytesRemaining;
}
Also used : RecordFormatException(org.apache.poi.util.RecordFormatException)

Aggregations

RecordFormatException (org.apache.poi.util.RecordFormatException)9 EscherContainerRecord (org.apache.poi.ddf.EscherContainerRecord)3 EscherOptRecord (org.apache.poi.ddf.EscherOptRecord)3 EscherRecord (org.apache.poi.ddf.EscherRecord)3 EscherBSERecord (org.apache.poi.ddf.EscherBSERecord)2 EscherDgRecord (org.apache.poi.ddf.EscherDgRecord)2 EscherDggRecord (org.apache.poi.ddf.EscherDggRecord)2 EscherSpRecord (org.apache.poi.ddf.EscherSpRecord)2 TikaException (org.apache.tika.exception.TikaException)2 XHTMLContentHandler (org.apache.tika.sax.XHTMLContentHandler)2 Charset (java.nio.charset.Charset)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 EscherClientDataRecord (org.apache.poi.ddf.EscherClientDataRecord)1 EscherProperty (org.apache.poi.ddf.EscherProperty)1 EscherSimpleProperty (org.apache.poi.ddf.EscherSimpleProperty)1 EscherSplitMenuColorsRecord (org.apache.poi.ddf.EscherSplitMenuColorsRecord)1 HemfExtractor (org.apache.poi.hemf.extractor.HemfExtractor)1 AbstractHemfComment (org.apache.poi.hemf.record.AbstractHemfComment)1 HemfCommentPublic (org.apache.poi.hemf.record.HemfCommentPublic)1