KickJava   Java API By Example, From Geeks To Geeks.

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


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: Codepage Record<P>
25  * Description: the default characterset. for the workbook<P>
26  * REFERENCE: PG 293 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P>
27  * @author Andrew C. Oliver (acoliver at apache dot org)
28  * @version 2.0-pre
29  */

30
31 public class CodepageRecord
32     extends Record
33 {
34     public final static short sid = 0x42;
35     private short field_1_codepage; // = 0;
36

37     /**
38      * the likely correct value for CODEPAGE (at least for US versions). We could use
39      * some help with international versions (which we do not have access to documentation
40      * for)
41      */

42
43     public final static short CODEPAGE = ( short ) 0x4b0;
44
45     public CodepageRecord()
46     {
47     }
48
49     /**
50      * Constructs a CodepageRecord and sets its fields appropriately
51      *
52      * @param id id must be 0x42 or an exception will be throw upon validation
53      * @param size the size of the data area of the record
54      * @param data data of the record (should not contain sid/len)
55      */

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

70
71     public CodepageRecord(short id, short size, byte [] data, int offset)
72     {
73         super(id, size, data, offset);
74     }
75
76     protected void validateSid(short id)
77     {
78         if (id != sid)
79         {
80             throw new RecordFormatException("NOT A CODEPAGE RECORD");
81         }
82     }
83
84     protected void fillFields(byte [] data, short size, int offset)
85     {
86         field_1_codepage = LittleEndian.getShort(data, 0 + offset);
87     }
88
89     /**
90      * set the codepage for this workbook
91      *
92      * @see #CODEPAGE
93      * @param cp the codepage to set
94      */

95
96     public void setCodepage(short cp)
97     {
98         field_1_codepage = cp;
99     }
100
101     /**
102      * get the codepage for this workbook
103      *
104      * @see #CODEPAGE
105      * @return codepage - the codepage to set
106      */

107
108     public short getCodepage()
109     {
110         return field_1_codepage;
111     }
112
113     public String JavaDoc toString()
114     {
115         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
116
117         buffer.append("[CODEPAGE]\n");
118         buffer.append(" .codepage = ")
119             .append(Integer.toHexString(getCodepage())).append("\n");
120         buffer.append("[/CODEPAGE]\n");
121         return buffer.toString();
122     }
123
124     public int serialize(int offset, byte [] data)
125     {
126         LittleEndian.putShort(data, 0 + offset, sid);
127         LittleEndian.putShort(data, 2 + offset,
128                               (( short ) 0x02)); // 2 bytes (6 total)
129
LittleEndian.putShort(data, 4 + offset, getCodepage());
130         return getRecordSize();
131     }
132
133     public int getRecordSize()
134     {
135         return 6;
136     }
137
138     public short getSid()
139     {
140         return this.sid;
141     }
142 }
143
Popular Tags