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: Backup Record <P>
024: * Description: Boolean specifying whether
025: * the GUI should store a backup of the file.<P>
026: * REFERENCE: PG 287 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P>
027: * @author Andrew C. Oliver (acoliver at apache dot org)
028: * @version 2.0-pre
029: */
030:
031: public class BackupRecord extends Record {
032: public final static short sid = 0x40;
033: private short field_1_backup; // = 0;
034:
035: public BackupRecord() {
036: }
037:
038: /**
039: * Constructs a BackupRecord and sets its fields appropriately
040: * @param in the RecordInputstream to read the record from
041: */
042:
043: public BackupRecord(RecordInputStream in) {
044: super (in);
045: }
046:
047: protected void validateSid(short id) {
048: if (id != sid) {
049: throw new RecordFormatException("NOT A BACKUP RECORD");
050: }
051: }
052:
053: protected void fillFields(RecordInputStream in) {
054: field_1_backup = in.readShort();
055: }
056:
057: /**
058: * set the backup flag (0,1)
059: *
060: * @param backup backup flag
061: */
062:
063: public void setBackup(short backup) {
064: field_1_backup = backup;
065: }
066:
067: /**
068: * get the backup flag
069: *
070: * @return short 0/1 (off/on)
071: */
072:
073: public short getBackup() {
074: return field_1_backup;
075: }
076:
077: public String toString() {
078: StringBuffer buffer = new StringBuffer();
079:
080: buffer.append("[BACKUP]\n");
081: buffer.append(" .backup = ").append(
082: Integer.toHexString(getBackup())).append("\n");
083: buffer.append("[/BACKUP]\n");
084: return buffer.toString();
085: }
086:
087: public int serialize(int offset, byte[] data) {
088: LittleEndian.putShort(data, 0 + offset, sid);
089: LittleEndian.putShort(data, 2 + offset, ((short) 0x02)); // 2 bytes (6 total)
090: LittleEndian.putShort(data, 4 + offset, getBackup());
091: return getRecordSize();
092: }
093:
094: public int getRecordSize() {
095: return 6;
096: }
097:
098: public short getSid() {
099: return sid;
100: }
101: }
|