KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*********************************************************************
2 *
3 * Copyright (C) 2001 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 java.io.UnsupportedEncodingException JavaDoc;
23
24 import jxl.biff.IntegerHelper;
25 import jxl.biff.RecordData;
26
27 /**
28  * A boundsheet record, which contains the worksheet name
29  */

30 class BoundsheetRecord extends RecordData
31 {
32   /**
33    * The offset into the sheet
34    */

35   private int offset;
36   /**
37    * The type of sheet this is
38    */

39   private byte typeFlag;
40   /**
41    * The visibility flag
42    */

43   private byte visibilityFlag;
44   /**
45    * The length of the worksheet name
46    */

47   private int length;
48   /**
49    * The worksheet name
50    */

51   private String JavaDoc name;
52
53   /**
54    * Dummy indicators for overloading the constructor
55    */

56   private static class Biff7 {};
57   public static Biff7 biff7 = new Biff7();
58
59   /**
60    * Constructs this object from the raw data
61    *
62    * @param t the raw data
63    */

64   public BoundsheetRecord(Record t)
65   {
66     super(t);
67     byte[] data = getRecord().getData();
68     offset = IntegerHelper.getInt(data[0], data[1], data[2], data[3]);
69     typeFlag = data[5];
70     visibilityFlag = data[4];
71     length = data[6];
72
73     if (data[7] == 0)
74     {
75       // Standard ASCII encoding
76
byte[] bytes = new byte[length];
77       System.arraycopy(data, 8, bytes, 0, length);
78       name = new String JavaDoc(bytes);
79     }
80     else
81     {
82       // little endian Unicode encoding
83
byte[] bytes = new byte[length * 2];
84       System.arraycopy(data, 8, bytes, 0, length * 2);
85       try
86       {
87         name = new String JavaDoc(bytes, "UnicodeLittle");
88       }
89       catch (UnsupportedEncodingException JavaDoc e)
90       {
91         // fail silently
92
name = "Error";
93       }
94     }
95   }
96
97
98   /**
99    * Constructs this object from the raw data
100    *
101    * @param t the raw data
102    * @param biff7 a dummy value to tell the record to interpret the
103    * data as biff7
104    */

105   public BoundsheetRecord(Record t, Biff7 biff7)
106   {
107     super(t);
108     byte[] data = getRecord().getData();
109     offset = IntegerHelper.getInt(data[0], data[1], data[2], data[3]);
110     typeFlag = data[5];
111     visibilityFlag = data[4];
112     length = data[6];
113     byte[] bytes = new byte[length];
114     System.arraycopy(data, 7, bytes, 0, length);
115     name = new String JavaDoc(bytes);
116   }
117
118   /**
119    * Accessor for the worksheet name
120    *
121    * @return the worksheet name
122    */

123   public String JavaDoc getName()
124   {
125     return name;
126   }
127
128   /**
129    * Accessor for the hidden flag
130    *
131    * @return TRUE if this is a hidden sheet, FALSE otherwise
132    */

133   public boolean isHidden()
134   {
135     return visibilityFlag != 0;
136   }
137
138   /**
139    * Accessor to determine if this is a worksheet, or some other nefarious
140    * type of object
141    *
142    * @return TRUE if this is a worksheet, FALSE otherwise
143    */

144   public boolean isSheet()
145   {
146     return typeFlag == 0;
147   }
148
149   /**
150    * Accessor to determine if this is a chart
151    *
152    * @return TRUE if this is a chart, FALSE otherwise
153    */

154   public boolean isChart()
155   {
156     return typeFlag == 2;
157   }
158
159 }
160
161
162
163
164
Popular Tags