1    
2    
3    /* ====================================================================
4    
5     * The Apache Software License, Version 1.1
6    
7     *
8    
9     * Copyright (c) 2002 The Apache Software Foundation.  All rights
10   
11    * reserved.
12   
13    *
14   
15    * Redistribution and use in source and binary forms, with or without
16   
17    * modification, are permitted provided that the following conditions
18   
19    * are met:
20   
21    *
22   
23    * 1. Redistributions of source code must retain the above copyright
24   
25    *    notice, this list of conditions and the following disclaimer.
26   
27    *
28   
29    * 2. Redistributions in binary form must reproduce the above copyright
30   
31    *    notice, this list of conditions and the following disclaimer in
32   
33    *    the documentation and/or other materials provided with the
34   
35    *    distribution.
36   
37    *
38   
39    * 3. The end-user documentation included with the redistribution,
40   
41    *    if any, must include the following acknowledgment:
42   
43    *       "This product includes software developed by the
44   
45    *        Apache Software Foundation (http://www.apache.org/)."
46   
47    *    Alternately, this acknowledgment may appear in the software itself,
48   
49    *    if and wherever such third-party acknowledgments normally appear.
50   
51    *
52   
53    * 4. The names "Apache" and "Apache Software Foundation" and
54   
55    *    "Apache POI" must not be used to endorse or promote products
56   
57    *    derived from this software without prior written permission. For
58   
59    *    written permission, please contact apache@apache.org.
60   
61    *
62   
63    * 5. Products derived from this software may not be called "Apache",
64   
65    *    "Apache POI", nor may "Apache" appear in their name, without
66   
67    *    prior written permission of the Apache Software Foundation.
68   
69    *
70   
71    * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
72   
73    * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
74   
75    * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
76   
77    * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
78   
79    * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
80   
81    * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
82   
83    * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
84   
85    * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
86   
87    * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
88   
89    * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
90   
91    * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
92   
93    * SUCH DAMAGE.
94   
95    * ====================================================================
96   
97    *
98   
99    * This software consists of voluntary contributions made by many
100  
101   * individuals on behalf of the Apache Software Foundation.  For more
102  
103   * information on the Apache Software Foundation, please see
104  
105   * <http://www.apache.org/>.
106  
107   */
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          StringBuffer buffer = new StringBuffer();
278  
279          buffer.append("[SUPBOOK]\n");
280  
281          buffer.append("numberosheets = ").append(getNumberOfSheets()).append('\n');
282  
283          buffer.append("flag          = ").append(getFlag()).append('\n');
284  
285          buffer.append("[/SUPBOOK]\n");
286  
287          return buffer.toString();
288  
289      }
290  
291  
292  
293      /**
294  
295       * called by the class that is responsible for writing this sucker.
296  
297       * Subclasses should implement this so that their data is passed back in a
298  
299       * byte array.
300  
301       *
302  
303       * @param offset to begin writing at
304  
305       * @param data byte array containing instance data
306  
307       * @return number of bytes written
308  
309       */
310  
311      public int serialize(int offset, byte [] data)
312  
313      {
314  
315          LittleEndian.putShort(data, 0 + offset, sid);
316  
317          LittleEndian.putShort(data, 2 + offset, (short) 4);
318  
319          LittleEndian.putShort(data, 4 + offset, field_1_number_of_sheets);
320  
321          LittleEndian.putShort(data, 6 + offset, field_2_flag);
322  
323          
324  
325  
326  
327          return getRecordSize();
328  
329      }
330  
331      
332  
333      public void setNumberOfSheets(short number){
334  
335          field_1_number_of_sheets = number;
336  
337      }
338  
339      
340  
341      public short getNumberOfSheets(){
342  
343          return field_1_number_of_sheets;
344  
345      }    
346  
347      
348  
349      public void setFlag(short flag){        
350  
351          field_2_flag = flag;
352  
353      }
354  
355      
356  
357      public short getFlag() {
358  
359          return field_2_flag;
360  
361      }
362  
363  
364  
365      public int getRecordSize()
366  
367      {
368  
369          return 4 + 4; 
370  
371      }
372  
373  
374  
375      public short getSid()
376  
377      {
378  
379          return this.sid;
380  
381      }
382  
383  }
384  
385  ????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????SupBookRecord????????????????????????????????????Record???????????????????????????????sid???????????????????????????????field_1_number_of_sheets???????????????????????????????field_2_flag????????????SupBookRecord???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????SupBookRecord???????????????id???????????????????size?????????????????????????data???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????SupBookRecord???????????????id???????????????????size?????????????????????????data???????????????????????????????offset????????????????????validateSid?????????????id???????????????????sid???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????fillFields??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????field_1_number_of_sheets????????????????????????????????????LittleEndian?????????????????????????????????????????????????getShort??????????????????????????????????????????????????????????data???????????????????????????????????????????????????????????????offset?????????field_2_flag????????????????????????LittleEndian?????????????????????????????????????getShort??????????????????????????????????????????????data???????????????????????????????????????????????????offset???????????????????toString?????????buffer?????????buffer??????????????????????????????????????????????????getNumberOfSheets?????????buffer??????????????????????????????????????????????????getFlag?????????buffer????????????????buffer????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????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