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: MMS Record<P>
024: * Description: defines how many add menu and del menu options are stored
025: * in the file. Should always be set to 0 for HSSF workbooks<P>
026: * REFERENCE: PG 328 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 MMSRecord extends Record {
032: public final static short sid = 0xC1;
033: private byte field_1_addMenuCount; // = 0;
034: private byte field_2_delMenuCount; // = 0;
035:
036: public MMSRecord() {
037: }
038:
039: /**
040: * Constructs a MMS record and sets its fields appropriately.
041: * @param in the RecordInputstream to read the record from
042: */
043:
044: public MMSRecord(RecordInputStream in) {
045: super (in);
046: }
047:
048: protected void validateSid(short id) {
049: if (id != sid) {
050: throw new RecordFormatException("NOT A MMS RECORD");
051: }
052: }
053:
054: protected void fillFields(RecordInputStream in) {
055: field_1_addMenuCount = in.readByte();
056: field_2_delMenuCount = in.readByte();
057: }
058:
059: /**
060: * set number of add menu options (set to 0)
061: * @param am number of add menu options
062: */
063:
064: public void setAddMenuCount(byte am) {
065: field_1_addMenuCount = am;
066: }
067:
068: /**
069: * set number of del menu options (set to 0)
070: * @param dm number of del menu options
071: */
072:
073: public void setDelMenuCount(byte dm) {
074: field_2_delMenuCount = dm;
075: }
076:
077: /**
078: * get number of add menu options (should be 0)
079: * @return number of add menu options
080: */
081:
082: public byte getAddMenuCount() {
083: return field_1_addMenuCount;
084: }
085:
086: /**
087: * get number of add del options (should be 0)
088: * @return number of add menu options
089: */
090:
091: public byte getDelMenuCount() {
092: return field_2_delMenuCount;
093: }
094:
095: public String toString() {
096: StringBuffer buffer = new StringBuffer();
097:
098: buffer.append("[MMS]\n");
099: buffer.append(" .addMenu = ").append(
100: Integer.toHexString(getAddMenuCount())).append("\n");
101: buffer.append(" .delMenu = ").append(
102: Integer.toHexString(getDelMenuCount())).append("\n");
103: buffer.append("[/MMS]\n");
104: return buffer.toString();
105: }
106:
107: public int serialize(int offset, byte[] data) {
108: LittleEndian.putShort(data, 0 + offset, sid);
109: LittleEndian.putShort(data, 2 + offset, ((short) 0x02)); // 2 bytes (6 total)
110: data[4 + offset] = getAddMenuCount();
111: data[5 + offset] = getDelMenuCount();
112: return getRecordSize();
113: }
114:
115: public int getRecordSize() {
116: return 6;
117: }
118:
119: public short getSid() {
120: return sid;
121: }
122: }
|