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: Sup Book <P>
024: * Description: A Extrenal Workbook Deciption (Sup Book)
025: * Its only a dummy record for making new ExternSheet Record <P>
026: * REFERENCE: <P>
027: * @author Libin Roman (Vista Portal LDT. Developer)
028: * @author Andrew C. Oliver (acoliver@apache.org)
029: *
030: */
031: public class SupBookRecord extends Record {
032: public final static short sid = 0x1AE;
033: private short field_1_number_of_sheets;
034: private short field_2_flag;
035:
036: public SupBookRecord() {
037: setFlag((short) 0x401);
038: }
039:
040: /**
041: * Constructs a Extern Sheet record and sets its fields appropriately.
042: *
043: * @param in the RecordInputstream to read the record from
044: */
045: public SupBookRecord(RecordInputStream in) {
046: super (in);
047: }
048:
049: protected void validateSid(short id) {
050: if (id != sid) {
051: throw new RecordFormatException("NOT An Supbook RECORD");
052: }
053: }
054:
055: /**
056: * @param in the RecordInputstream to read the record from
057: */
058: protected void fillFields(RecordInputStream in) {
059: //For now We use it only for one case
060: //When we need to add an named range when no named ranges was
061: //before it
062: field_1_number_of_sheets = in.readShort();
063: field_2_flag = in.readShort();
064: }
065:
066: public String toString() {
067: StringBuffer buffer = new StringBuffer();
068: buffer.append("[SUPBOOK]\n");
069: buffer.append("numberosheets = ").append(getNumberOfSheets())
070: .append('\n');
071: buffer.append("flag = ").append(getFlag())
072: .append('\n');
073: buffer.append("[/SUPBOOK]\n");
074: return buffer.toString();
075: }
076:
077: /**
078: * called by the class that is responsible for writing this sucker.
079: * Subclasses should implement this so that their data is passed back in a
080: * byte array.
081: *
082: * @param offset to begin writing at
083: * @param data byte array containing instance data
084: * @return number of bytes written
085: */
086: public int serialize(int offset, byte[] data) {
087: LittleEndian.putShort(data, 0 + offset, sid);
088: LittleEndian.putShort(data, 2 + offset, (short) 4);
089: LittleEndian.putShort(data, 4 + offset,
090: field_1_number_of_sheets);
091: LittleEndian.putShort(data, 6 + offset, field_2_flag);
092:
093: return getRecordSize();
094: }
095:
096: public void setNumberOfSheets(short number) {
097: field_1_number_of_sheets = number;
098: }
099:
100: public short getNumberOfSheets() {
101: return field_1_number_of_sheets;
102: }
103:
104: public void setFlag(short flag) {
105: field_2_flag = flag;
106: }
107:
108: public short getFlag() {
109: return field_2_flag;
110: }
111:
112: public int getRecordSize() {
113: return 4 + 4;
114: }
115:
116: public short getSid() {
117: return sid;
118: }
119: }
|