001: /* ====================================================================
002: Copyright 2002-2004 Apache Software Foundation
003:
004: Licensed under the Apache License, Version 2.0 (the "License");
005: you may not use this file except in compliance with the License.
006: You may obtain a copy of the License at
007:
008: http://www.apache.org/licenses/LICENSE-2.0
009:
010: Unless required by applicable law or agreed to in writing, software
011: distributed under the License is distributed on an "AS IS" BASIS,
012: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: See the License for the specific language governing permissions and
014: limitations under the License.
015: ==================================================================== */
016:
017: package org.apache.poi.hssf.record;
018:
019: import org.apache.poi.util.LittleEndian;
020:
021: /**
022: * Title: DVAL Record<P>
023: * Description: used in data validation ;
024: * This record is the list header of all data validation records in the current sheet.
025: * @author Dragos Buleandra (dragos.buleandra@trade2b.ro)
026: * @version 2.0-pre
027: */
028:
029: public class DVALRecord extends Record {
030: public final static short sid = 0x01B2;
031:
032: //unknown field ; it's size should be 10
033: private short field_unknown = 0x0000;
034:
035: //Object ID of the drop down arrow object for list boxes ;
036: //in our case this will be always FFFF , until
037: //MSODrawingGroup and MSODrawing records are implemented
038: private int field_cbo_id = 0xFFFFFFFF;
039:
040: //Number of following DV records
041: //Default value is 1
042: private int field_3_dv_no = 0x00000000;
043:
044: public DVALRecord() {
045: }
046:
047: /**
048: * Constructs a DVAL record and sets its fields appropriately.
049: *
050: * @param in the RecordInputstream to read the record from
051: */
052:
053: public DVALRecord(RecordInputStream in) {
054: super (in);
055: }
056:
057: protected void validateSid(short id) {
058: if (id != sid) {
059: throw new RecordFormatException("NOT A valid DVAL RECORD");
060: }
061: }
062:
063: protected void fillFields(RecordInputStream in) {
064: for (int i = 0; i < 5; i++) {
065: this .field_unknown = in.readShort();
066: }
067: this .field_cbo_id = in.readInt();
068: this .field_3_dv_no = in.readInt();
069: }
070:
071: /**
072: * set the object ID of the drop down arrow object for list boxes
073: * @param cboID - Object ID
074: */
075: public void setObjectID(int cboID) {
076: this .field_cbo_id = cboID;
077: }
078:
079: /**
080: * Set the number of following DV records
081: * @param dvNo - the DV records number
082: */
083: public void setDVRecNo(int dvNo) {
084: this .field_3_dv_no = dvNo;
085: }
086:
087: /**
088: * get Object ID of the drop down arrow object for list boxes
089: */
090: public int getObjectID() {
091: return this .field_cbo_id;
092: }
093:
094: /**
095: * Get number of following DV records
096: */
097: public int getDVRecNo() {
098: return this .field_3_dv_no;
099: }
100:
101: public String toString() {
102: StringBuffer buffer = new StringBuffer();
103:
104: buffer.append("[DVAL]\n");
105: buffer.append(" .comboObjectID = ").append(
106: Integer.toHexString(this .getObjectID())).append("\n");
107: buffer.append(" .DVRecordsNumber = ").append(
108: Integer.toHexString(this .getDVRecNo())).append("\n");
109: buffer.append("[/DVAL]\n");
110: return buffer.toString();
111: }
112:
113: public int serialize(int offset, byte[] data) {
114: LittleEndian.putShort(data, 0 + offset, this .sid);
115: LittleEndian.putShort(data, 2 + offset, (short) (this
116: .getRecordSize() - 4));
117: for (int i = 0; i < 5; i++) {
118: LittleEndian.putShort(data, 4 + i * 2 + offset,
119: (short) this .field_unknown);
120: }
121: LittleEndian.putInt(data, 14 + offset, this .getObjectID());
122: LittleEndian.putInt(data, 18 + offset, this .getDVRecNo());
123: return getRecordSize();
124: }
125:
126: //with 4 bytes header
127: public int getRecordSize() {
128: return 22;
129: }
130:
131: public short getSid() {
132: return this .sid;
133: }
134:
135: public Object clone() {
136: DVALRecord rec = new DVALRecord();
137: rec.field_unknown = this.field_unknown;
138: rec.field_cbo_id = this.field_cbo_id;
139: rec.field_3_dv_no = this.field_3_dv_no;
140: return rec;
141: }
142: }
|