FileDocCategorySizeDatePackage
ObjRecord.javaAPI DocApache Poi 3.0.15909Sun Mar 11 12:59:08 GMT 2007org.apache.poi.hssf.record

ObjRecord

public class ObjRecord extends Record
The obj record is used to hold various graphic objects and controls.
author
Glen Stampoultzis (glens at apache.org)

Fields Summary
public static final short
sid
private List
subrecords
Constructors Summary
public ObjRecord()


    //00000000 15 00 12 00 01 00 01 00 11 60 00 00 00 00 00 0D .........`......
    //00000010 26 01 00 00 00 00 00 00 00 00                   &.........


     
    
        subrecords = new ArrayList(2);
    
public ObjRecord(RecordInputStream in)
Constructs a OBJ record and sets its fields appropriately.

param
id id must be 0x5D or an exception will be throw upon validation
param
size size the size of the data area of the record
param
data data of the record (should not contain sid/len)

        super(in);
    
Methods Summary
public voidaddSubRecord(int index, java.lang.Object element)

        subrecords.add( index, element );
    
public booleanaddSubRecord(java.lang.Object o)

        return subrecords.add( o );
    
public voidclearSubRecords()

        subrecords.clear();
    
public java.lang.Objectclone()

        ObjRecord rec = new ObjRecord();

        for ( Iterator iterator = subrecords.iterator(); iterator.hasNext(); )
            rec.addSubRecord(( (Record) iterator.next() ).clone());

        return rec;
    
protected voidfillFields(org.apache.poi.hssf.record.RecordInputStream in)

        subrecords = new ArrayList();
        //Check if this can be continued, if so then the
        //following wont work properly
        int subSize = 0;
        byte[] subRecordData = in.readRemainder();
        RecordInputStream subRecStream = new RecordInputStream(new ByteArrayInputStream(subRecordData));
        while(subRecStream.hasNextRecord()) {
          subRecStream.nextRecord();
          Record subRecord = SubRecord.createSubRecord(subRecStream);
          subSize += subRecord.getRecordSize();
          subrecords.add(subRecord);
        }

        /**
         * Check if the RecordInputStream skipped EndSubRecord,
         * if it did then append it explicitly.
         * See Bug 41242 for details.
         */
        if (subRecordData.length - subSize == 4){
            subrecords.add(new EndSubRecord());
        }

        /* JMH the size present/not present in the code below
           needs to be considered in the RecordInputStream??
        int pos = offset;
        while (pos - offset <= size-2) // atleast one "short" must be present
        {
            short subRecordSid = LittleEndian.getShort(data, pos);
            short subRecordSize = -1; // set default to "< 0"
            if (pos-offset <= size-4) { // see if size info is present, else default to -1
                subRecordSize = LittleEndian.getShort(data, pos + 2);
            }
            Record subRecord = SubRecord.createSubRecord(subRecordSid, subRecordSize, data, pos + 4);
            subrecords.add(subRecord);
            pos += subRecord.getRecordSize();
        }*/
    
public intgetRecordSize()
Size of record (excluding 4 byte header)

        int size = 0;
        for ( Iterator iterator = subrecords.iterator(); iterator.hasNext(); )
        {
            Record record = (Record) iterator.next();
            size += record.getRecordSize();
        }
        return 4  + size;
    
public shortgetSid()

        return sid;
    
public java.util.ListgetSubRecords()

        return subrecords;
    
public intserialize(int offset, byte[] data)

        int pos = 0;

        LittleEndian.putShort(data, 0 + offset, sid);
        LittleEndian.putShort(data, 2 + offset, (short)(getRecordSize() - 4));

        pos = offset + 4;
        for ( Iterator iterator = subrecords.iterator(); iterator.hasNext(); )
        {
            Record record = (Record) iterator.next();
            pos += record.serialize(pos, data);
        }

        return getRecordSize();
    
public java.lang.StringtoString()

        StringBuffer buffer = new StringBuffer();

        buffer.append("[OBJ]\n");
        for ( Iterator iterator = subrecords.iterator(); iterator.hasNext(); )
        {
            Record record = (Record) iterator.next();
            buffer.append("SUBRECORD: " + record.toString());
        }
        buffer.append("[/OBJ]\n");
        return buffer.toString();
    
protected voidvalidateSid(short id)
Checks the sid matches the expected side for this record

param
id the expected sid.

        if (id != sid)
        {
            throw new RecordFormatException("Not an OBJ record");
        }