1 2 17 18 19 package org.apache.poi.hssf.record; 20 21 import org.apache.poi.util.LittleEndian; 22 23 import java.util.ArrayList ; 24 25 32 33 public class ExternSheetRecord extends Record { 34 public final static short sid = 0x17; 35 private short field_1_number_of_REF_sturcutres; 36 private ArrayList field_2_REF_structures; 37 38 public ExternSheetRecord() { 39 field_2_REF_structures = new ArrayList (); 40 } 41 42 49 50 public ExternSheetRecord(short id, short size, byte[] data) { 51 super(id, size, data); 52 } 53 54 62 public ExternSheetRecord(short id, short size, byte[] data, int offset) { 63 super(id, size, data, offset); 64 } 65 66 72 protected void validateSid(short id) { 73 if (id != sid) { 74 throw new RecordFormatException("NOT An ExternSheet RECORD"); 75 } 76 } 77 78 86 protected void fillFields(byte [] data, short size, int offset) { 87 field_2_REF_structures = new ArrayList (); 88 89 field_1_number_of_REF_sturcutres = LittleEndian.getShort(data, 0 + offset); 90 91 int pos = 2 + offset; 92 for (int i = 0 ; i < field_1_number_of_REF_sturcutres ; ++i) { 93 ExternSheetSubRecord rec = new ExternSheetSubRecord((short)0, (short)6 , data , pos); 94 95 pos += 6; 96 97 field_2_REF_structures.add( rec); 98 } 99 } 100 101 105 public void setNumOfREFStructures(short numStruct) { 106 field_1_number_of_REF_sturcutres = numStruct; 107 } 108 109 113 public short getNumOfREFStructures() { 114 return field_1_number_of_REF_sturcutres; 115 } 116 117 121 public void addREFRecord(ExternSheetSubRecord rec) { 122 field_2_REF_structures.add(rec); 123 } 124 125 128 public int getNumOfREFRecords() { 129 return field_2_REF_structures.size(); 130 } 131 132 136 public ExternSheetSubRecord getREFRecordAt(int elem) { 137 ExternSheetSubRecord result = ( ExternSheetSubRecord ) field_2_REF_structures.get(elem); 138 139 return result; 140 } 141 142 public String toString() { 143 StringBuffer buffer = new StringBuffer (); 144 145 buffer.append("[EXTERNSHEET]\n"); 146 buffer.append(" numOfRefs = ").append(getNumOfREFStructures()).append("\n"); 147 for (int k=0; k < this.getNumOfREFRecords(); k++) { 148 buffer.append("refrec #").append(k).append('\n'); 149 buffer.append(getREFRecordAt(k).toString()); 150 buffer.append("----refrec #").append(k).append('\n'); 151 } 152 buffer.append("[/EXTERNSHEET]\n"); 153 154 155 return buffer.toString(); 156 } 157 158 167 public int serialize(int offset, byte [] data) { 168 LittleEndian.putShort(data, 0 + offset, sid); 169 LittleEndian.putShort(data, 2 + offset,(short)(2 + (getNumOfREFRecords() *6))); 170 171 LittleEndian.putShort(data, 4 + offset, getNumOfREFStructures()); 172 173 int pos = 6 ; 174 175 for (int k = 0; k < getNumOfREFRecords(); k++) { 176 ExternSheetSubRecord record = getREFRecordAt(k); 177 System.arraycopy(record.serialize(), 0, data, pos + offset, 6); 178 179 pos +=6; 180 } 181 return getRecordSize(); 182 } 183 184 public int getRecordSize() { 185 return 4 + 2 + getNumOfREFRecords() * 6; 186 } 187 188 191 public short getSid() { 192 return this.sid; 193 } 194 } 195 | Popular Tags |