1 */
108
109
110
111 package org.apache.poi.hssf.record;
112
113
114
115 import org.apache.poi.util.LittleEndian;
116
117
118
119 import java.util.ArrayList;
120
121
122
123 /**
124
125 * Title: Sup Book <P>
126
127 * Description: A Extrenal Workbook Deciption (Sup Book)
128
129 * Its only a dummy record for making new ExternSheet Record <P>
130
131 * REFERENCE: <P>
132
133 * @author Libin Roman (Vista Portal LDT. Developer)
134
135 * @author Andrew C. Oliver (acoliver@apache.org)
136
137 *
138
139 */
140
141
142
143 public class SupBookRecord extends Record
144
145 {
146
147 public final static short sid = 0x1AE;
148
149 private short field_1_number_of_sheets;
150
151 private short field_2_flag;
152
153
154
155
156
157 public SupBookRecord()
158
159 {
160
161 setFlag((short)0x401);
162
163 }
164
165
166
167 /**
168
169 * Constructs a Extern Sheet record and sets its fields appropriately.
170
171 *
172
173 * @param id id must be 0x16 or an exception will be throw upon validation
174
175 * @param size the size of the data area of the record
176
177 * @param data data of the record (should not contain sid/len)
178
179 */
180
181
182
183 public SupBookRecord(short id, short size, byte[] data)
184
185 {
186
187 super(id, size, data);
188
189 }
190
191
192
193 /**
194
195 * Constructs a Extern Sheet record and sets its fields appropriately.
196
197 *
198
199 * @param id id must be 0x1ae or an exception will be throw upon validation
200
201 * @param size the size of the data area of the record
202
203 * @param data data of the record (should not contain sid/len)
204
205 * @param offset of the record's data
206
207 */
208
209
210
211 public SupBookRecord(short id, short size, byte[] data, int offset)
212
213 {
214
215 super(id, size, data, offset);
216
217 }
218
219
220
221 protected void validateSid(short id)
222
223 {
224
225 if (id != sid)
226
227 {
228
229 throw new RecordFormatException("NOT An Supbook RECORD");
230
231 }
232
233 }
234
235
236
237 /**
238
239 * called by the constructor, should set class level fields. Should throw
240
241 * runtime exception for bad/icomplete data.
242
243 *
244
245 * @param data raw data
246
247 * @param size size of data
248
249 * @param offset of the record's data (provided a big array of the file)
250
251 */
252
253 protected void fillFields(byte [] data, short size, int offset)
254
255 {
256
257 //For now We use it only for one case
258
259 //When we need to add an named range when no named ranges was
260
261 //before it
262
263 field_1_number_of_sheets = LittleEndian.getShort(data,offset+0);
264
265 field_2_flag = LittleEndian.getShort(data,offset+2);
266
267 }
268
269
270
271
272
273 public String toString()
274
275 {
276
277 return "";
278
279 }
280
281
282
283 /**
284
285 * called by the class that is responsible for writing this sucker.
286
287 * Subclasses should implement this so that their data is passed back in a
288
289 * byte array.
290
291 *
292
293 * @param offset to begin writing at
294
295 * @param data byte array containing instance data
296
297 * @return number of bytes written
298
299 */
300
301 public int serialize(int offset, byte [] data)
302
303 {
304
305 LittleEndian.putShort(data, 0 + offset, sid);
306
307 LittleEndian.putShort(data, 2 + offset, (short) 4);
308
309 LittleEndian.putShort(data, 4 + offset, field_1_number_of_sheets);
310
311 LittleEndian.putShort(data, 6 + offset, field_2_flag);
312
313
314
315
316
317 return getRecordSize();
318
319 }
320
321
322
323 public void setNumberOfSheets(short number){
324
325 field_1_number_of_sheets = number;
326
327 }
328
329
330
331 public short getNumberOfSheets(){
332
333 return field_1_number_of_sheets;
334
335 }
336
337
338
339 public void setFlag(short flag){
340
341 field_2_flag = flag;
342
343 }
344
345
346
347 public short getFlag() {
348
349 return field_2_flag;
350
351 }
352
353
354
355 public int getRecordSize()
356
357 {
358
359 return 4 + 4;
360
361 }
362
363
364
365 public short getSid()
366
367 {
368
369 return this.sid;
370
371 }
372
373 }
374
375 ???????????????SupBookRecord????????????????????????????????????Record???????????????????????????????sid???????????????????????????????field_1_number_of_sheets???????????????????????????????field_2_flag????????????SupBookRecord?????????????????SupBookRecord???????????????id???????????????????size?????????????????????????data?????????????????SupBookRecord???????????????id???????????????????size?????????????????????????data???????????????????????????????offset????????????????????validateSid?????????????id???????????????????sid???????????????????????RecordFormatException?????????????????????????fillFields????????????????????????????????????field_1_number_of_sheets????????????????????????????????????LittleEndian?????????????????????????????????????????????????getShort??????????????????????????????????????????????????????????data???????????????????????????????????????????????????????????????offset?????????field_2_flag????????????????????????LittleEndian?????????????????????????????????????getShort??????????????????????????????????????????????data???????????????????????????????????????????????????offset???????????????????toString?????????????????????serialize?????????LittleEndian??????????????????????putShort???????????????????????????????data?????????????????????????????????????????offset?????????????????????????????????????????????????sid?????????LittleEndian??????????????????????putShort???????????????????????????????data?????????????????????????????????????????offset?????????LittleEndian??????????????????????putShort???????????????????????????????data?????????????????????????????????????????offset?????????????????????????????????????????????????field_1_number_of_sheets?????????LittleEndian??????????????????????putShort???????????????????????????????data?????????????????????????????????????????offset?????????????????????????????????????????????????field_2_flag????????????????getRecordSize?????????????????setNumberOfSheets????????????????????????????????????number??????????????????getNumberOfSheets????????????????field_1_number_of_sheets?????????????????setFlag?????????field_2_flag????????????????????????flag??????????????????getFlag????????????????field_2_flag????????????????getRecordSize??????????????????getSid