KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jxl > read > biff > ExternalSheetRecord


1 /*********************************************************************
2 *
3 * Copyright (C) 2002 Andrew Khan
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 ***************************************************************************/

19
20 package jxl.read.biff;
21
22 import common.Logger;
23
24 import jxl.WorkbookSettings;
25 import jxl.biff.IntegerHelper;
26 import jxl.biff.RecordData;
27
28 /**
29  * An Externsheet record, containing the details of externally references
30  * workbooks
31  */

32 public class ExternalSheetRecord extends RecordData
33 {
34   /**
35    * The logger
36    */

37   private static Logger logger = Logger.getLogger(ExternalSheetRecord.class);
38
39   /**
40    * Dummy indicators for overloading the constructor
41    */

42   private static class Biff7 {};
43   public static Biff7 biff7 = new Biff7();
44
45   /**
46    * An XTI structure
47    */

48   private static class XTI
49   {
50     /**
51      * the supbook index
52      */

53     int supbookIndex;
54     /**
55      * the first tab
56      */

57     int firstTab;
58     /**
59      * the last tab
60      */

61     int lastTab;
62
63     /**
64      * Constructor
65      *
66      * @param s the supbook index
67      * @param f the first tab
68      * @param l the last tab
69      */

70     XTI(int s, int f, int l)
71     {
72       supbookIndex = s;
73       firstTab = f;
74       lastTab = l;
75     }
76   }
77
78   /**
79    * The array of XTI structures
80    */

81   private XTI[] xtiArray;
82
83   /**
84    * Constructs this object from the raw data
85    *
86    * @param t the raw data
87    * @param ws the workbook settings
88    */

89   ExternalSheetRecord(Record t, WorkbookSettings ws)
90   {
91     super(t);
92     byte[] data = getRecord().getData();
93
94     int numxtis = IntegerHelper.getInt(data[0], data[1]);
95
96     if (data.length < numxtis * 6 + 2)
97     {
98       xtiArray = new XTI[0];
99       logger.warn("Could not process external sheets. Formulas may " +
100                   "be compromised.");
101       return;
102     }
103
104     xtiArray = new XTI[numxtis];
105
106     int pos = 2;
107     for (int i = 0; i < numxtis; i++)
108     {
109       int s = IntegerHelper.getInt(data[pos], data[pos + 1]);
110       int f = IntegerHelper.getInt(data[pos + 2], data[pos + 3]);
111       int l = IntegerHelper.getInt(data[pos + 4], data[pos + 5]);
112       xtiArray[i] = new XTI(s, f, l);
113       pos += 6;
114     }
115   }
116
117   /**
118    * Constructs this object from the raw data in biff 7 format.
119    * Does nothing here
120    *
121    * @param t the raw data
122    * @param settings the workbook settings
123    * @param dummy dummy override to identify biff7 funcionality
124    */

125   ExternalSheetRecord(Record t, WorkbookSettings settings, Biff7 dummy)
126   {
127     super(t);
128
129     logger.warn("External sheet record for Biff 7 not supported");
130   }
131
132   /**
133    * Accessor for the number of external sheet records
134    * @return the number of XTI records
135    */

136   public int getNumRecords()
137   {
138     return xtiArray != null ? xtiArray.length : 0;
139   }
140   /**
141    * Gets the supbook index for the specified external sheet
142    *
143    * @param index the index of the supbook record
144    * @return the supbook index
145    */

146   public int getSupbookIndex(int index)
147   {
148     return xtiArray[index].supbookIndex;
149   }
150
151   /**
152    * Gets the first tab index for the specified external sheet
153    *
154    * @param index the index of the supbook record
155    * @return the first tab index
156    */

157   public int getFirstTabIndex(int index)
158   {
159     return xtiArray[index].firstTab;
160   }
161
162   /**
163    * Gets the last tab index for the specified external sheet
164    *
165    * @param index the index of the supbook record
166    * @return the last tab index
167    */

168   public int getLastTabIndex(int index)
169   {
170     return xtiArray[index].lastTab;
171   }
172
173   /**
174    * Used when copying a workbook to access the raw external sheet data
175    *
176    * @return the raw external sheet data
177    */

178   public byte[] getData()
179   {
180     return getRecord().getData();
181   }
182 }
183
184
185
186
187
188
189
190
191
192
Popular Tags