1 2 17 18 19 package org.apache.poi.hssf.record; 20 21 import org.apache.poi.util.LittleEndian; 22 23 31 32 public class DBCellRecord 33 extends Record 34 { 35 public final static int BLOCK_SIZE = 32; 36 public final static short sid = 0xd7; 37 private int field_1_row_offset; 38 private short[] field_2_cell_offsets; 39 40 public DBCellRecord() 41 { 42 } 43 44 51 52 public DBCellRecord(short id, short size, byte [] data) 53 { 54 super(id, size, data); 55 } 56 57 65 66 public DBCellRecord(short id, short size, byte [] data, int offset) 67 { 68 super(id, size, data, offset); 69 } 70 71 protected void validateSid(short id) 72 { 73 if (id != sid) 74 { 75 throw new RecordFormatException("NOT A valid DBCell RECORD"); 76 } 77 } 78 79 protected void fillFields(byte [] data, short size, int offset) 80 { 81 field_1_row_offset = LittleEndian.getUShort(data, 0 + offset); 82 field_2_cell_offsets = new short[ (size - 4) / 2 ]; 83 int element = 0; 84 85 for (int k = 4; k < data.length; k += 2) 86 { 87 field_2_cell_offsets[ element++ ] = LittleEndian.getShort(data, 88 k + offset); 89 } 90 } 91 92 98 99 public void setRowOffset(int offset) 100 { 101 field_1_row_offset = offset; 102 } 103 104 public void addCellOffset(short offset) 106 { 107 if (field_2_cell_offsets == null) 108 { 109 field_2_cell_offsets = new short[ 1 ]; 110 } 111 else 112 { 113 short[] temp = new short[ field_2_cell_offsets.length + 1 ]; 114 115 System.arraycopy(field_2_cell_offsets, 0, temp, 0, 116 field_2_cell_offsets.length); 117 field_2_cell_offsets = temp; 118 } 119 field_2_cell_offsets[ field_2_cell_offsets.length - 1 ] = offset; 120 } 121 122 128 129 public int getRowOffset() 130 { 131 return field_1_row_offset; 132 } 133 134 140 141 public short getCellOffsetAt(int index) 142 { 143 return field_2_cell_offsets[ index ]; 144 } 145 146 151 152 public int getNumCellOffsets() 153 { 154 return field_2_cell_offsets.length; 155 } 156 157 public String toString() 158 { 159 StringBuffer buffer = new StringBuffer (); 160 161 buffer.append("[DBCELL]\n"); 162 buffer.append(" .rowoffset = ") 163 .append(Integer.toHexString(getRowOffset())).append("\n"); 164 for (int k = 0; k < getNumCellOffsets(); k++) 165 { 166 buffer.append(" .cell_" + k + " = ") 167 .append(Integer.toHexString(getCellOffsetAt(k))).append("\n"); 168 } 169 buffer.append("[/DBCELL]\n"); 170 return buffer.toString(); 171 } 172 173 public int serialize(int offset, byte [] data) 174 { 175 if (field_2_cell_offsets == null) 176 { 177 field_2_cell_offsets = new short[ 0 ]; 178 } 179 LittleEndian.putShort(data, 0 + offset, sid); 180 LittleEndian.putShort(data, 2 + offset, 181 (( short ) (4 + (getNumCellOffsets() * 2)))); 182 LittleEndian.putInt(data, 4 + offset, getRowOffset()); 183 for (int k = 0; k < getNumCellOffsets(); k++) 184 { 185 LittleEndian.putShort(data, 8 + 2*k + offset, getCellOffsetAt(k)); 186 } 187 return getRecordSize(); 188 } 189 190 public int getRecordSize() 191 { 192 return 8 + (getNumCellOffsets() * 2); 193 } 194 195 196 public static int getRecordSizeForRows(int rows) { 197 return 8 + (rows * 2); 198 } 199 200 public short getSid() 201 { 202 return this.sid; 203 } 204 205 public boolean isInValueSection() 206 { 207 return true; 208 } 209 } 210 | Popular Tags |