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: Interface Header Record<P>
024: * Description: Defines the beginning of Interface records (MMS)<P>
025: * REFERENCE: PG 324 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 InterfaceHdrRecord extends Record {
031: public final static short sid = 0xe1;
032: private short field_1_codepage; // = 0;
033:
034: /**
035: * suggested (and probably correct) default
036: */
037:
038: public final static short CODEPAGE = (short) 0x4b0;
039:
040: public InterfaceHdrRecord() {
041: }
042:
043: /**
044: * Constructs an Codepage record and sets its fields appropriately.
045: * @param in the RecordInputstream to read the record from
046: */
047:
048: public InterfaceHdrRecord(RecordInputStream in) {
049: super (in);
050: }
051:
052: protected void validateSid(short id) {
053: if (id != sid) {
054: throw new RecordFormatException("NOT A INTERFACEHDR RECORD");
055: }
056: }
057:
058: protected void fillFields(RecordInputStream in) {
059: field_1_codepage = in.readShort();
060: }
061:
062: /**
063: * set the codepage for the file
064: *
065: * @param cp - the codepage
066: * @see #CODEPAGE
067: */
068:
069: public void setCodepage(short cp) {
070: field_1_codepage = cp;
071: }
072:
073: /**
074: * get the codepage for the file
075: *
076: * @return the codepage
077: * @see #CODEPAGE
078: */
079:
080: public short getCodepage() {
081: return field_1_codepage;
082: }
083:
084: public String toString() {
085: StringBuffer buffer = new StringBuffer();
086:
087: buffer.append("[INTERFACEHDR]\n");
088: buffer.append(" .codepage = ").append(
089: Integer.toHexString(getCodepage())).append("\n");
090: buffer.append("[/INTERFACEHDR]\n");
091: return buffer.toString();
092: }
093:
094: public int serialize(int offset, byte[] data) {
095: LittleEndian.putShort(data, 0 + offset, sid);
096: LittleEndian.putShort(data, 2 + offset, ((short) 0x02)); // 2 bytes (6 total)
097: LittleEndian.putShort(data, 4 + offset, getCodepage());
098: return getRecordSize();
099: }
100:
101: public int getRecordSize() {
102: return 6;
103: }
104:
105: public short getSid() {
106: return sid;
107: }
108: }
|