FileDocCategorySizeDatePackage
AbstractEscherHolderRecord.javaAPI DocApache Poi 3.0.18962Mon Jan 01 12:39:40 GMT 2007org.apache.poi.hssf.record

AbstractEscherHolderRecord

public abstract class AbstractEscherHolderRecord extends Record
The escher container record is used to hold escher records. It is abstract and must be subclassed for maximum benefit.
author
Glen Stampoultzis (glens at apache.org)
author
Michael Zalewski (zalewski at optonline.net)

Fields Summary
private static final boolean
DESERIALISE
private List
escherRecords
private byte[]
rawData
Constructors Summary
public AbstractEscherHolderRecord()



     
    
        escherRecords = new ArrayList();
    
public AbstractEscherHolderRecord(RecordInputStream in)
Constructs a Bar record and sets its fields appropriately.

param
id id must be 0x1017 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 voidaddEscherRecord(int index, org.apache.poi.ddf.EscherRecord element)

        escherRecords.add( index, element );
    
public booleanaddEscherRecord(org.apache.poi.ddf.EscherRecord element)

        return escherRecords.add( element );
    
public voidclearEscherRecords()

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

        throw new IllegalStateException("Not implemented yet.");
    
private voidconvertToEscherRecords(int offset, int size, byte[] data)

        EscherRecordFactory recordFactory = new DefaultEscherRecordFactory();
        int pos = offset;
        while ( pos < offset + size )
        {
            EscherRecord r = recordFactory.createRecord(data, pos);
            int bytesRead = r.fillFields(data, pos, recordFactory );
            escherRecords.add(r);
            pos += bytesRead;
        }
    
public voiddecode()
Convert raw data to escher records.

        convertToEscherRecords(0, rawData.length, rawData );
    
protected voidfillFields(org.apache.poi.hssf.record.RecordInputStream in)

        escherRecords = new ArrayList();
        if (! DESERIALISE )
        {
            rawData = in.readRemainder();
        }
        else
        {
            byte[] data = in.readAllContinuedRemainder();
            convertToEscherRecords( 0, data.length, data );
        }
    
public org.apache.poi.ddf.EscherRecordgetEscherRecord(int index)

        return (EscherRecord) escherRecords.get(index);
    
public java.util.ListgetEscherRecords()

        return escherRecords;
    
public byte[]getRawData()

        return rawData;
    
protected abstract java.lang.StringgetRecordName()

public intgetRecordSize()
Size of record (including 4 byte header)

        if (escherRecords.size() == 0 && rawData != null)
        {
            return rawData.length + 4;
        }
        else
        {
            int size = 4;
            for ( Iterator iterator = escherRecords.iterator(); iterator.hasNext(); )
            {
                EscherRecord r = (EscherRecord) iterator.next();
                size += r.getRecordSize();
            }
            return size;
        }
    
public abstract shortgetSid()

public voidjoin(org.apache.poi.hssf.record.AbstractEscherHolderRecord record)
Big drawing group records are split but it's easier to deal with them as a whole group so we need to join them together.

        int length = this.rawData.length + record.getRawData().length;
        byte[] data = new byte[length];
        System.arraycopy( rawData, 0, data, 0, rawData.length );
        System.arraycopy( record.getRawData(), 0, data, rawData.length, record.getRawData().length );
        rawData = data;
    
public voidprocessContinueRecord(byte[] record)

        int length = this.rawData.length + record.length;
        byte[] data = new byte[length];
        System.arraycopy( rawData, 0, data, 0, rawData.length );
        System.arraycopy( record, 0, data, rawData.length, record.length );
        rawData = data;
    
public intserialize(int offset, byte[] data)

        LittleEndian.putShort( data, 0 + offset, getSid() );
        LittleEndian.putShort( data, 2 + offset, (short) ( getRecordSize() - 4 ) );
        if ( escherRecords.size() == 0 && rawData != null )
        {
            LittleEndian.putShort(data, 0 + offset, getSid());
            LittleEndian.putShort(data, 2 + offset, (short)(getRecordSize() - 4));
            System.arraycopy( rawData, 0, data, 4 + offset, rawData.length);
            return rawData.length + 4;
        }
        else
        {
            LittleEndian.putShort(data, 0 + offset, getSid());
            LittleEndian.putShort(data, 2 + offset, (short)(getRecordSize() - 4));

            int pos = offset + 4;
            for ( Iterator iterator = escherRecords.iterator(); iterator.hasNext(); )
            {
                EscherRecord r = (EscherRecord) iterator.next();
                pos += r.serialize( pos, data, new NullEscherSerializationListener() );
            }
        }
        return getRecordSize();
    
public voidsetRawData(byte[] rawData)

        this.rawData = rawData;
    
public java.lang.StringtoString()

        StringBuffer buffer = new StringBuffer();

        final String nl = System.getProperty("line.separator");
        buffer.append('[" + getRecordName() + ']" + nl);
        if (escherRecords.size() == 0)
            buffer.append("No Escher Records Decoded" + nl);
        for ( Iterator iterator = escherRecords.iterator(); iterator.hasNext(); )
        {
            EscherRecord r = (EscherRecord) iterator.next();
            buffer.append(r.toString());
        }
        buffer.append("[/" + getRecordName() + ']" + nl);

        return buffer.toString();
    
protected voidvalidateSid(short id)
Checks the sid matches the expected side for this record

param
id the expected sid.

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