1 2 17 18 19 package org.apache.poi.hssf.record; 20 21 import org.apache.poi.util.LittleEndian; 22 23 33 34 public class BOFRecord 35 extends Record 36 { 37 38 41 42 public final static short sid = 0x809; 43 private short field_1_version; 44 private short field_2_type; 45 private short field_3_build; 46 private short field_4_year; 47 private int field_5_history; 48 private int field_6_rversion; 49 50 53 54 public final static short VERSION = 0x06; 55 56 59 60 public final static short BUILD = 0x10d3; 61 62 65 66 public final static short BUILD_YEAR = 0x07CC; 68 71 72 public final static short HISTORY_MASK = 0x41; 73 public final static short TYPE_WORKBOOK = 0x05; 74 public final static short TYPE_VB_MODULE = 0x06; 75 public final static short TYPE_WORKSHEET = 0x10; 76 public final static short TYPE_CHART = 0x20; 77 public final static short TYPE_EXCEL_4_MACRO = 0x40; 78 public final static short TYPE_WORKSPACE_FILE = 0x100; 79 80 83 84 public BOFRecord() 85 { 86 } 87 88 95 96 public BOFRecord(short id, short size, byte [] data) 97 { 98 super(id, size, data); 99 100 } 102 103 111 112 public BOFRecord(short id, short size, byte [] data, int offset) 113 { 114 super(id, size, data, offset); 115 116 } 118 119 protected void validateSid(short id) 120 { 121 if (id != sid) 122 { 123 throw new RecordFormatException("NOT A BOF RECORD"); 124 } 125 } 126 127 protected void fillFields(byte [] data, short size, int offset) 128 { 129 field_1_version = LittleEndian.getShort(data, 0 + offset); 130 field_2_type = LittleEndian.getShort(data, 2 + offset); 131 field_3_build = LittleEndian.getShort(data, 4 + offset); 132 field_4_year = LittleEndian.getShort(data, 6 + offset); 133 field_5_history = LittleEndian.getInt(data, 8 + offset); 134 field_6_rversion = LittleEndian.getInt(data, 12 + offset); 135 } 136 137 142 143 public void setVersion(short version) 144 { 145 field_1_version = version; 146 } 147 148 158 159 public void setType(short type) 160 { 161 field_2_type = type; 162 } 163 164 169 170 public void setBuild(short build) 171 { 172 field_3_build = build; 173 } 174 175 180 181 public void setBuildYear(short year) 182 { 183 field_4_year = year; 184 } 185 186 191 192 public void setHistoryBitMask(int bitmask) 193 { 194 field_5_history = bitmask; 195 } 196 197 203 204 public void setRequiredVersion(int version) 205 { 206 field_6_rversion = version; 207 } 208 209 214 215 public short getVersion() 216 { 217 return field_1_version; 218 } 219 220 230 231 public short getType() 232 { 233 return field_2_type; 234 } 235 236 241 242 public short getBuild() 243 { 244 return field_3_build; 245 } 246 247 252 253 public short getBuildYear() 254 { 255 return field_4_year; 256 } 257 258 263 264 public int getHistoryBitMask() 265 { 266 return field_5_history; 267 } 268 269 275 276 public int getRequiredVersion() 277 { 278 return field_6_rversion; 279 } 280 281 public String toString() 282 { 283 StringBuffer buffer = new StringBuffer (); 284 285 buffer.append("[BOF RECORD]\n"); 286 buffer.append(" .version = ") 287 .append(Integer.toHexString(getVersion())).append("\n"); 288 buffer.append(" .type = ") 289 .append(Integer.toHexString(getType())).append("\n"); 290 buffer.append(" .build = ") 291 .append(Integer.toHexString(getBuild())).append("\n"); 292 buffer.append(" .buildyear = ").append(getBuildYear()) 293 .append("\n"); 294 buffer.append(" .history = ") 295 .append(Integer.toHexString(getHistoryBitMask())).append("\n"); 296 buffer.append(" .requiredversion = ") 297 .append(Integer.toHexString(getRequiredVersion())).append("\n"); 298 buffer.append("[/BOF RECORD]\n"); 299 return buffer.toString(); 300 } 301 302 public int serialize(int offset, byte [] data) 303 { 304 LittleEndian.putShort(data, 0 + offset, sid); 305 LittleEndian.putShort(data, 2 + offset, 306 (( short ) 0x10)); LittleEndian.putShort(data, 4 + offset, getVersion()); 308 LittleEndian.putShort(data, 6 + offset, getType()); 309 LittleEndian.putShort(data, 8 + offset, getBuild()); 310 LittleEndian.putShort(data, 10 + offset, getBuildYear()); 311 LittleEndian.putInt(data, 12 + offset, getHistoryBitMask()); 312 LittleEndian.putInt(data, 16 + offset, getRequiredVersion()); 313 return getRecordSize(); 314 } 315 316 public int getRecordSize() 317 { 318 return 20; 319 } 320 321 public short getSid() 322 { 323 return this.sid; 324 } 325 326 public Object clone() { 327 BOFRecord rec = new BOFRecord(); 328 rec.field_1_version = field_1_version; 329 rec.field_2_type = field_2_type; 330 rec.field_3_build = field_3_build; 331 rec.field_4_year = field_4_year; 332 rec.field_5_history = field_5_history; 333 rec.field_6_rversion = field_6_rversion; 334 return rec; 335 } 336 } 337 | Popular Tags |