KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > poi > hssf > record > MMSRecord


1
2 /* ====================================================================
3    Copyright 2002-2004 Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16 ==================================================================== */

17         
18
19 package org.apache.poi.hssf.record;
20
21 import org.apache.poi.util.LittleEndian;
22
23 /**
24  * Title: MMS Record<P>
25  * Description: defines how many add menu and del menu options are stored
26  * in the file. Should always be set to 0 for HSSF workbooks<P>
27  * REFERENCE: PG 328 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P>
28  * @author Andrew C. Oliver (acoliver at apache dot org)
29  * @version 2.0-pre
30  */

31
32 public class MMSRecord
33     extends Record
34 {
35     public final static short sid = 0xC1;
36     private byte field_1_addMenuCount; // = 0;
37
private byte field_2_delMenuCount; // = 0;
38

39     public MMSRecord()
40     {
41     }
42
43     /**
44      * Constructs a MMS record and sets its fields appropriately.
45      *
46      * @param id id must be 0xc1 or an exception will be throw upon validation
47      * @param size the size of the data area of the record
48      * @param data data of the record (should not contain sid/len)
49      */

50
51     public MMSRecord(short id, short size, byte [] data)
52     {
53         super(id, size, data);
54     }
55
56     /**
57      * Constructs a MMS record and sets its fields appropriately.
58      *
59      * @param id id must be 0xc1 or an exception will be throw upon validation
60      * @param size the size of the data area of the record
61      * @param data data of the record (should not contain sid/len)
62      * @param offset of the data
63      */

64
65     public MMSRecord(short id, short size, byte [] data, int offset)
66     {
67         super(id, size, data, offset);
68     }
69
70     protected void validateSid(short id)
71     {
72         if (id != sid)
73         {
74             throw new RecordFormatException("NOT A MMS RECORD");
75         }
76     }
77
78     protected void fillFields(byte [] data, short size, int offset)
79     {
80         field_1_addMenuCount = data[ 0 + offset ];
81         field_2_delMenuCount = data[ 1 + offset ];
82     }
83
84     /**
85      * set number of add menu options (set to 0)
86      * @param am number of add menu options
87      */

88
89     public void setAddMenuCount(byte am)
90     {
91         field_1_addMenuCount = am;
92     }
93
94     /**
95      * set number of del menu options (set to 0)
96      * @param dm number of del menu options
97      */

98
99     public void setDelMenuCount(byte dm)
100     {
101         field_2_delMenuCount = dm;
102     }
103
104     /**
105      * get number of add menu options (should be 0)
106      * @return number of add menu options
107      */

108
109     public byte getAddMenuCount()
110     {
111         return field_1_addMenuCount;
112     }
113
114     /**
115      * get number of add del options (should be 0)
116      * @return number of add menu options
117      */

118
119     public byte getDelMenuCount()
120     {
121         return field_2_delMenuCount;
122     }
123
124     public String JavaDoc toString()
125     {
126         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
127
128         buffer.append("[MMS]\n");
129         buffer.append(" .addMenu = ")
130             .append(Integer.toHexString(getAddMenuCount())).append("\n");
131         buffer.append(" .delMenu = ")
132             .append(Integer.toHexString(getDelMenuCount())).append("\n");
133         buffer.append("[/MMS]\n");
134         return buffer.toString();
135     }
136
137     public int serialize(int offset, byte [] data)
138     {
139         LittleEndian.putShort(data, 0 + offset, sid);
140         LittleEndian.putShort(data, 2 + offset,
141                               (( short ) 0x02)); // 2 bytes (6 total)
142
data[ 4 + offset ] = getAddMenuCount();
143         data[ 5 + offset ] = getDelMenuCount();
144         return getRecordSize();
145     }
146
147     public int getRecordSize()
148     {
149         return 6;
150     }
151
152     public short getSid()
153     {
154         return this.sid;
155     }
156 }
157
Popular Tags