Class EscherAggregate

All Implemented Interfaces:
Cloneable

public final class EscherAggregate extends AbstractEscherHolderRecord
This class is used to aggregate the MSODRAWING and OBJ record combinations. This is necessary due to the bizare way in which these records are serialized. What happens is that you get a combination of MSODRAWING -> OBJ -> MSODRAWING -> OBJ records but the escher records are serialized _across_ the MSODRAWING records.

It gets even worse when you start looking at TXO records.

So what we do with this class is aggregate lazily. That is we don't aggregate the MSODRAWING -> OBJ records unless we need to modify them.

At first document contains 4 types of records which belong to drawing layer. There are can be such sequence of record:

DrawingRecord ContinueRecord ... ContinueRecord ObjRecord | TextObjectRecord ..... ContinueRecord ... ContinueRecord ObjRecord | TextObjectRecord NoteRecord ... NoteRecord

To work with shapes we have to read data from Drawing and Continue records into single array of bytes and build escher(office art) records tree from this array. Each shape in drawing layer matches corresponding ObjRecord Each textbox matches corresponding TextObjectRecord

ObjRecord contains information about shape. Thus each ObjRecord corresponds EscherContainerRecord(SPGR)

EscherAggrefate contains also NoteRecords NoteRecords must be serial

  • Field Details

  • Constructor Details

    • EscherAggregate

      public EscherAggregate(boolean createDefaultTree)
      create new EscherAggregate
      Parameters:
      createDefaultTree - if true creates base tree of the escher records, see EscherAggregate.buildBaseTree() else return empty escher aggregate
  • Method Details

    • getSid

      public short getSid()
      Description copied from class: Record
      return the non static version of the id for this record.
      Specified by:
      getSid in class AbstractEscherHolderRecord
      Returns:
      Returns the current sid.
    • toString

      public String toString()
      Calculates the string representation of this record. This is simply a dump of all the records.
      Overrides:
      toString in class AbstractEscherHolderRecord
    • toXml

      public String toXml(String tab)
      Calculates the xml representation of this record. This is simply a dump of all the records.
      Parameters:
      tab - - string which must be added before each line (used by default '\t')
      Returns:
      xml representation of the all aggregated records
    • createAggregate

      public static EscherAggregate createAggregate(List<RecordBase> records, int locFirstDrawingRecord)
      Collapses the drawing records into an aggregate. read Drawing, Obj, TxtObj, Note and Continue records into single byte array, create Escher tree from byte array, create map <EscherRecord, Record>
      Parameters:
      records - - list of all records inside sheet
      locFirstDrawingRecord - - location of the first DrawingRecord inside sheet
      Returns:
      new EscherAggregate create from all aggregated records which belong to drawing layer
    • serialize

      public int serialize(int offset, byte[] data)
      Serializes this aggregate to a byte array. Since this is an aggregate record it will effectively serialize the aggregated records.
      Overrides:
      serialize in class AbstractEscherHolderRecord
      Parameters:
      offset - The offset into the start of the array.
      data - The byte array to serialize to.
      Returns:
      The number of bytes serialized.
    • getRecordSize

      public int getRecordSize()
      Description copied from class: RecordBase
      gives the current serialized size of the record. Should include the sid and reclength (4 bytes).
      Overrides:
      getRecordSize in class AbstractEscherHolderRecord
      Returns:
      record size, including header size of obj, text, note, drawing, continue records
    • associateShapeToObjRecord

      public void associateShapeToObjRecord(EscherRecord r, Record objRecord)
      Associates an escher record to an OBJ record or a TXO record.
      Parameters:
      r - - ClientData or Textbox record
      objRecord - - Obj or TextObj record
    • removeShapeToObjRecord

      public void removeShapeToObjRecord(EscherRecord rec)
      Remove echerRecord and associated to it Obj or TextObj record
      Parameters:
      rec - - clientData or textbox record to be removed
    • getRecordName

      protected String getRecordName()
      Specified by:
      getRecordName in class AbstractEscherHolderRecord
      Returns:
      "ESCHERAGGREGATE"
    • setDgId

      public void setDgId(short dgId)
      EscherDgContainer -EscherSpgrContainer -EscherDgRecord - set id for this record set id for DgRecord of DgContainer
      Parameters:
      dgId - - id which must be set
    • setMainSpRecordId

      public void setMainSpRecordId(int shapeId)
      EscherDgContainer -EscherSpgrContainer --EscherSpContainer ---EscherSpRecord -set id for this record ---*** --*** -EscherDgRecord set id for the sp record of the first spContainer in main spgrConatiner
      Parameters:
      shapeId - - id which must be set
    • getShapeToObjMapping

      public Map<EscherRecord,Record> getShapeToObjMapping()
      Returns:
      unmodifiable copy of the mapping of EscherClientDataRecord and EscherTextboxRecord to their TextObjectRecord or ObjRecord .

      We need to access it outside of EscherAggregate when building shapes

    • getTailRecords

      public Map<Integer,NoteRecord> getTailRecords()
      Returns:
      unmodifiable copy of tail records. We need to access them when building shapes. Every HSSFComment shape has a link to a NoteRecord from the tailRec collection.
    • getNoteRecordByObj

      public NoteRecord getNoteRecordByObj(ObjRecord obj)
      Parameters:
      obj - - ObjRecord with id == NoteRecord.id
      Returns:
      null if note record is not found else returns note record with id == obj.id
    • addTailRecord

      public void addTailRecord(NoteRecord note)
      Add tail record to existing map
      Parameters:
      note - to be added
    • removeTailRecord

      public void removeTailRecord(NoteRecord note)
      Remove tail record from the existing map
      Parameters:
      note - to be removed