KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > poi > hssf > record > CountryRecord


1
2 /* ====================================================================
3    Copyright 2002-2004 Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16 ==================================================================== */

17         
18
19 package org.apache.poi.hssf.record;
20
21 import org.apache.poi.util.LittleEndian;
22
23 /**
24  * Title: Country Record (aka WIN.INI country)<P>
25  * Description: used for localization. Currently HSSF always sets this to 1
26  * and it seems to work fine even in Germany. (es geht's auch fuer Deutschland)<P>
27  *
28  * REFERENCE: PG 298 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P>
29  * @author Andrew C. Oliver (acoliver at apache dot org)
30  * @version 2.0-pre
31  */

32
33 public class CountryRecord
34     extends Record
35 {
36     public final static short sid = 0x8c;
37
38     // 1 for US
39
private short field_1_default_country;
40     private short field_2_current_country;
41
42     public CountryRecord()
43     {
44     }
45
46     /**
47      * Constructs a CountryRecord and sets its fields appropriately
48      *
49      * @param id id must be 0x8c or an exception will be throw upon validation
50      * @param size the size of the data area of the record
51      * @param data data of the record (should not contain sid/len)
52      */

53
54     public CountryRecord(short id, short size, byte [] data)
55     {
56         super(id, size, data);
57     }
58
59     /**
60      * Constructs a CountryRecord and sets its fields appropriately
61      *
62      * @param id id must be 0x8c or an exception will be throw upon validation
63      * @param size the size of the data area of the record
64      * @param data data of the record (should not contain sid/len)
65      * @param offset of the record's data
66      */

67
68     public CountryRecord(short id, short size, byte [] data, int offset)
69     {
70         super(id, size, data, offset);
71     }
72
73     protected void validateSid(short id)
74     {
75         if (id != sid)
76         {
77             throw new RecordFormatException("NOT A Country RECORD");
78         }
79     }
80
81     protected void fillFields(byte [] data, short size, int offset)
82     {
83         field_1_default_country = LittleEndian.getShort(data, 0 + offset);
84         field_2_current_country = LittleEndian.getShort(data, 2 + offset);
85     }
86
87     /**
88      * sets the default country
89      *
90      * @param country ID to set (1 = US)
91      */

92
93     public void setDefaultCountry(short country)
94     {
95         field_1_default_country = country;
96     }
97
98     /**
99      * sets the current country
100      *
101      * @param country ID to set (1 = US)
102      */

103
104     public void setCurrentCountry(short country)
105     {
106         field_2_current_country = country;
107     }
108
109     /**
110      * gets the default country
111      *
112      * @return country ID (1 = US)
113      */

114
115     public short getDefaultCountry()
116     {
117         return field_1_default_country;
118     }
119
120     /**
121      * gets the current country
122      *
123      * @return country ID (1 = US)
124      */

125
126     public short getCurrentCountry()
127     {
128         return field_2_current_country;
129     }
130
131     public String JavaDoc toString()
132     {
133         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
134
135         buffer.append("[COUNTRY]\n");
136         buffer.append(" .defaultcountry = ")
137             .append(Integer.toHexString(getDefaultCountry())).append("\n");
138         buffer.append(" .currentcountry = ")
139             .append(Integer.toHexString(getCurrentCountry())).append("\n");
140         buffer.append("[/COUNTRY]\n");
141         return buffer.toString();
142     }
143
144     public int serialize(int offset, byte [] data)
145     {
146         LittleEndian.putShort(data, 0 + offset, sid);
147         LittleEndian.putShort(data, 2 + offset,
148                               (( short ) 0x04)); // 4 bytes (8 total)
149
LittleEndian.putShort(data, 4 + offset, getDefaultCountry());
150         LittleEndian.putShort(data, 6 + offset, getCurrentCountry());
151         return getRecordSize();
152     }
153
154     public int getRecordSize()
155     {
156         return 8;
157     }
158
159     public short getSid()
160     {
161         return this.sid;
162     }
163 }
164
Popular Tags