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: Country Record (aka WIN.INI country)<P>
024: * Description: used for localization. Currently HSSF always sets this to 1
025: * and it seems to work fine even in Germany. (es geht's auch fuer Deutschland)<P>
026: *
027: * REFERENCE: PG 298 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P>
028: * @author Andrew C. Oliver (acoliver at apache dot org)
029: * @version 2.0-pre
030: */
031:
032: public class CountryRecord extends Record {
033: public final static short sid = 0x8c;
034:
035: // 1 for US
036: private short field_1_default_country;
037: private short field_2_current_country;
038:
039: public CountryRecord() {
040: }
041:
042: /**
043: * Constructs a CountryRecord and sets its fields appropriately
044: * @param in the RecordInputstream to read the record from
045: */
046:
047: public CountryRecord(RecordInputStream in) {
048: super (in);
049: }
050:
051: protected void validateSid(short id) {
052: if (id != sid) {
053: throw new RecordFormatException("NOT A Country RECORD");
054: }
055: }
056:
057: protected void fillFields(RecordInputStream in) {
058: field_1_default_country = in.readShort();
059: field_2_current_country = in.readShort();
060: }
061:
062: /**
063: * sets the default country
064: *
065: * @param country ID to set (1 = US)
066: */
067:
068: public void setDefaultCountry(short country) {
069: field_1_default_country = country;
070: }
071:
072: /**
073: * sets the current country
074: *
075: * @param country ID to set (1 = US)
076: */
077:
078: public void setCurrentCountry(short country) {
079: field_2_current_country = country;
080: }
081:
082: /**
083: * gets the default country
084: *
085: * @return country ID (1 = US)
086: */
087:
088: public short getDefaultCountry() {
089: return field_1_default_country;
090: }
091:
092: /**
093: * gets the current country
094: *
095: * @return country ID (1 = US)
096: */
097:
098: public short getCurrentCountry() {
099: return field_2_current_country;
100: }
101:
102: public String toString() {
103: StringBuffer buffer = new StringBuffer();
104:
105: buffer.append("[COUNTRY]\n");
106: buffer.append(" .defaultcountry = ").append(
107: Integer.toHexString(getDefaultCountry())).append("\n");
108: buffer.append(" .currentcountry = ").append(
109: Integer.toHexString(getCurrentCountry())).append("\n");
110: buffer.append("[/COUNTRY]\n");
111: return buffer.toString();
112: }
113:
114: public int serialize(int offset, byte[] data) {
115: LittleEndian.putShort(data, 0 + offset, sid);
116: LittleEndian.putShort(data, 2 + offset, ((short) 0x04)); // 4 bytes (8 total)
117: LittleEndian.putShort(data, 4 + offset, getDefaultCountry());
118: LittleEndian.putShort(data, 6 + offset, getCurrentCountry());
119: return getRecordSize();
120: }
121:
122: public int getRecordSize() {
123: return 8;
124: }
125:
126: public short getSid() {
127: return sid;
128: }
129: }
|