1 2 17 18 package org.apache.poi.ddf; 19 20 import org.apache.poi.util.HexDump; 21 import org.apache.poi.util.LittleEndian; 22 import org.apache.poi.hssf.record.RecordFormatException; 23 24 import java.util.Iterator ; 25 import java.util.List ; 26 import java.util.ArrayList ; 27 28 33 public class EscherTextboxRecord extends EscherRecord 34 { 35 public static final short RECORD_ID = (short)0xF00D; 36 public static final String RECORD_DESCRIPTION = "msofbtClientTextbox"; 37 38 private static final byte[] NO_BYTES = new byte[0]; 39 40 41 private byte[] thedata = NO_BYTES; 42 43 public EscherTextboxRecord() 44 { 45 } 46 47 55 public int fillFields( byte[] data, int offset, EscherRecordFactory recordFactory ) 56 { 57 int bytesRemaining = readHeader( data, offset ); 58 if ( isContainerRecord() ) 59 { 60 int bytesWritten = 0; 61 thedata = new byte[0]; 62 offset += 8; 63 bytesWritten += 8; 64 while ( bytesRemaining > 0 ) 65 { 66 EscherRecord child = recordFactory.createRecord( data, offset ); 67 int childBytesWritten = child.fillFields( data, offset, recordFactory ); 68 bytesWritten += childBytesWritten; 69 offset += childBytesWritten; 70 bytesRemaining -= childBytesWritten; 71 getChildRecords().add( child ); 72 } 73 return bytesWritten; 74 } 75 else 76 { 77 thedata = new byte[bytesRemaining]; 78 System.arraycopy( data, offset + 8, thedata, 0, bytesRemaining ); 79 return bytesRemaining + 8; 80 } 81 } 82 83 89 public int serialize( int offset, byte[] data, EscherSerializationListener listener ) 90 { 91 listener.beforeRecordSerialize( offset, getRecordId(), this ); 92 93 LittleEndian.putShort(data, offset, getOptions()); 94 LittleEndian.putShort(data, offset+2, getRecordId()); 95 int remainingBytes = thedata.length; 96 for ( Iterator iterator = getChildRecords().iterator(); iterator.hasNext(); ) 97 { 98 EscherRecord r = (EscherRecord) iterator.next(); 99 remainingBytes += r.getRecordSize(); 100 } 101 LittleEndian.putInt(data, offset+4, remainingBytes); 102 System.arraycopy(thedata, 0, data, offset+8, thedata.length); 103 int pos = offset+8+thedata.length; 104 for ( Iterator iterator = getChildRecords().iterator(); iterator.hasNext(); ) 105 { 106 EscherRecord r = (EscherRecord) iterator.next(); 107 pos += r.serialize(pos, data, listener ); 108 } 109 110 listener.afterRecordSerialize( pos, getRecordId(), pos - offset, this ); 111 int size = pos - offset; 112 if (size != getRecordSize()) 113 throw new RecordFormatException(size + " bytes written but getRecordSize() reports " + getRecordSize()); 114 return size; 115 } 116 117 121 public byte[] getData() 122 { 123 return thedata; 124 } 125 126 131 public int getRecordSize() 132 { 133 return 8 + thedata.length; 134 } 135 136 public Object clone() 137 { 138 return super.clone(); 140 } 141 142 145 public String getRecordName() 146 { 147 return "ClientTextbox"; 148 } 149 150 public String toString() 151 { 152 String nl = System.getProperty( "line.separator" ); 153 154 String theDumpHex = ""; 155 try 156 { 157 if (thedata.length != 0) 158 { 159 theDumpHex = " Extra Data:" + nl; 160 theDumpHex += HexDump.dump(thedata, 0, 0); 161 } 162 } 163 catch ( Exception e ) 164 { 165 theDumpHex = "Error!!"; 166 } 167 168 return getClass().getName() + ":" + nl + 169 " isContainer: " + isContainerRecord() + nl + 170 " options: 0x" + HexDump.toHex( getOptions() ) + nl + 171 " recordId: 0x" + HexDump.toHex( getRecordId() ) + nl + 172 " numchildren: " + getChildRecords().size() + nl + 173 theDumpHex; 174 } 175 176 } 177 178 179 180 | Popular Tags |