001: /* ====================================================================
002: Licensed to the Apache Software Foundation (ASF) under one or more
003: contributor license agreements. See the NOTICE file distributed with
004: this work for additional information regarding copyright ownership.
005: The ASF licenses this file to You under the Apache License, Version 2.0
006: (the "License"); you may not use this file except in compliance with
007: the License. You may obtain a copy of the License at
008:
009: http://www.apache.org/licenses/LICENSE-2.0
010:
011: Unless required by applicable law or agreed to in writing, software
012: distributed under the License is distributed on an "AS IS" BASIS,
013: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: See the License for the specific language governing permissions and
015: limitations under the License.
016: ==================================================================== */
017:
018: package org.apache.poi.hssf.record;
019:
020: import org.apache.poi.util.LittleEndian;
021:
022: /**
023: * Title: Codepage Record<P>
024: * Description: the default characterset. for the workbook<P>
025: * REFERENCE: PG 293 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P>
026: * @author Andrew C. Oliver (acoliver at apache dot org)
027: * @version 2.0-pre
028: */
029:
030: public class CodepageRecord extends Record {
031: public final static short sid = 0x42;
032: private short field_1_codepage; // = 0;
033:
034: /**
035: * the likely correct value for CODEPAGE (at least for US versions). We could use
036: * some help with international versions (which we do not have access to documentation
037: * for)
038: */
039:
040: public final static short CODEPAGE = (short) 0x4b0;
041:
042: public CodepageRecord() {
043: }
044:
045: /**
046: * Constructs a CodepageRecord and sets its fields appropriately
047: * @param in the RecordInputstream to read the record from
048: */
049:
050: public CodepageRecord(RecordInputStream in) {
051: super (in);
052: }
053:
054: protected void validateSid(short id) {
055: if (id != sid) {
056: throw new RecordFormatException("NOT A CODEPAGE RECORD");
057: }
058: }
059:
060: protected void fillFields(RecordInputStream in) {
061: field_1_codepage = in.readShort();
062: }
063:
064: /**
065: * set the codepage for this workbook
066: *
067: * @see #CODEPAGE
068: * @param cp the codepage to set
069: */
070:
071: public void setCodepage(short cp) {
072: field_1_codepage = cp;
073: }
074:
075: /**
076: * get the codepage for this workbook
077: *
078: * @see #CODEPAGE
079: * @return codepage - the codepage to set
080: */
081:
082: public short getCodepage() {
083: return field_1_codepage;
084: }
085:
086: public String toString() {
087: StringBuffer buffer = new StringBuffer();
088:
089: buffer.append("[CODEPAGE]\n");
090: buffer.append(" .codepage = ").append(
091: Integer.toHexString(getCodepage())).append("\n");
092: buffer.append("[/CODEPAGE]\n");
093: return buffer.toString();
094: }
095:
096: public int serialize(int offset, byte[] data) {
097: LittleEndian.putShort(data, 0 + offset, sid);
098: LittleEndian.putShort(data, 2 + offset, ((short) 0x02)); // 2 bytes (6 total)
099: LittleEndian.putShort(data, 4 + offset, getCodepage());
100: return getRecordSize();
101: }
102:
103: public int getRecordSize() {
104: return 6;
105: }
106:
107: public short getSid() {
108: return sid;
109: }
110: }
|