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: /*
019: * LabelRecord.java
020: *
021: * Created on November 11, 2001, 12:51 PM
022: */
023: package org.apache.poi.hssf.record;
024:
025: /**
026: * Label Record - read only support for strings stored directly in the cell.. Don't
027: * use this (except to read), use LabelSST instead <P>
028: * REFERENCE: PG 325 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P>
029: * @author Andrew C. Oliver (acoliver at apache dot org)
030: * @author Jason Height (jheight at chariot dot net dot au)
031: * @version 2.0-pre
032: * @see org.apache.poi.hssf.record.LabelSSTRecord
033: */
034:
035: public class LabelRecord extends Record implements
036: CellValueRecordInterface {
037: public final static short sid = 0x204;
038: //private short field_1_row;
039: private int field_1_row;
040: private short field_2_column;
041: private short field_3_xf_index;
042: private short field_4_string_len;
043: private byte field_5_unicode_flag;
044: private String field_6_value;
045:
046: /** Creates new LabelRecord */
047:
048: public LabelRecord() {
049: }
050:
051: /**
052: * Constructs an Label record and sets its fields appropriately.
053: *
054: * @param in the RecordInputstream to read the record from
055: */
056:
057: public LabelRecord(RecordInputStream in) {
058: super (in);
059: }
060:
061: /**
062: * called by constructor, should throw runtime exception in the event of a
063: * record passed with a differing ID.
064: *
065: * @param id alleged id for this record
066: */
067:
068: protected void validateSid(short id) {
069: if (id != sid) {
070: throw new RecordFormatException("Not a valid LabelRecord");
071: }
072: }
073:
074: /**
075: * @param in the RecordInputstream to read the record from
076: */
077:
078: protected void fillFields(RecordInputStream in) {
079: //field_1_row = LittleEndian.getShort(data, 0 + offset);
080: field_1_row = in.readUShort();
081: field_2_column = in.readShort();
082: field_3_xf_index = in.readShort();
083: field_4_string_len = in.readShort();
084: field_5_unicode_flag = in.readByte();
085: if (field_4_string_len > 0) {
086: if (isUnCompressedUnicode()) {
087: field_6_value = in
088: .readUnicodeLEString(field_4_string_len);
089: } else {
090: field_6_value = in
091: .readCompressedUnicode(field_4_string_len);
092: }
093: } else
094: field_6_value = null;
095: }
096:
097: /* READ ONLY ACCESS... THIS IS FOR COMPATIBILITY ONLY...USE LABELSST!
098: public void setRow(short row) {
099: field_1_row = row;
100: }
101:
102: public void setColumn(short col) {
103: field_2_column = col;
104: }
105:
106: public void setXFIndex(short index) {
107: field_3_xf_index = index;
108: }
109: */
110: //public short getRow()
111: public int getRow() {
112: return field_1_row;
113: }
114:
115: public short getColumn() {
116: return field_2_column;
117: }
118:
119: public short getXFIndex() {
120: return field_3_xf_index;
121: }
122:
123: /**
124: * get the number of characters this string contains
125: * @return number of characters
126: */
127:
128: public short getStringLength() {
129: return field_4_string_len;
130: }
131:
132: /**
133: * is this uncompressed unicode (16bit)? Or just 8-bit compressed?
134: * @return isUnicode - True for 16bit- false for 8bit
135: */
136:
137: public boolean isUnCompressedUnicode() {
138: return (field_5_unicode_flag == 1);
139: }
140:
141: /**
142: * get the value
143: *
144: * @return the text string
145: * @see #getStringLength()
146: */
147:
148: public String getValue() {
149: return field_6_value;
150: }
151:
152: /**
153: * THROWS A RUNTIME EXCEPTION.. USE LABELSSTRecords. YOU HAVE NO REASON to use LABELRecord!!
154: */
155:
156: public int serialize(int offset, byte[] data) {
157: throw new RecordFormatException(
158: "Label Records are supported READ ONLY...convert to LabelSST");
159: }
160:
161: public short getSid() {
162: return sid;
163: }
164:
165: public String toString() {
166: StringBuffer buffer = new StringBuffer();
167: buffer.append("[LABEL]\n");
168: buffer.append(" .row = ").append(
169: Integer.toHexString(getRow())).append("\n");
170: buffer.append(" .column = ").append(
171: Integer.toHexString(getColumn())).append("\n");
172: buffer.append(" .xfindex = ").append(
173: Integer.toHexString(getXFIndex())).append("\n");
174: buffer.append(" .string_len = ").append(
175: Integer.toHexString(field_4_string_len)).append("\n");
176: buffer.append(" .unicode_flag = ").append(
177: Integer.toHexString(field_5_unicode_flag)).append("\n");
178: buffer.append(" .value = ").append(getValue()).append(
179: "\n");
180: buffer.append("[/LABEL]\n");
181: return buffer.toString();
182: }
183:
184: public boolean isBefore(CellValueRecordInterface i) {
185: if (this .getRow() > i.getRow()) {
186: return false;
187: }
188: if ((this .getRow() == i.getRow())
189: && (this .getColumn() > i.getColumn())) {
190: return false;
191: }
192: if ((this .getRow() == i.getRow())
193: && (this .getColumn() == i.getColumn())) {
194: return false;
195: }
196: return true;
197: }
198:
199: public boolean isAfter(CellValueRecordInterface i) {
200: if (this .getRow() < i.getRow()) {
201: return false;
202: }
203: if ((this .getRow() == i.getRow())
204: && (this .getColumn() < i.getColumn())) {
205: return false;
206: }
207: if ((this .getRow() == i.getRow())
208: && (this .getColumn() == i.getColumn())) {
209: return false;
210: }
211: return true;
212: }
213:
214: public boolean isEqual(CellValueRecordInterface i) {
215: return ((this .getRow() == i.getRow()) && (this .getColumn() == i
216: .getColumn()));
217: }
218:
219: public boolean isInValueSection() {
220: return true;
221: }
222:
223: public boolean isValue() {
224: return true;
225: }
226:
227: /**
228: * NO-OP!
229: */
230:
231: public void setColumn(short col) {
232: }
233:
234: /**
235: * NO-OP!
236: */
237:
238: //public void setRow(short row)
239: public void setRow(int row) {
240: }
241:
242: /**
243: * no op!
244: */
245:
246: public void setXFIndex(short xf) {
247: }
248:
249: public Object clone() {
250: LabelRecord rec = new LabelRecord();
251: rec.field_1_row = field_1_row;
252: rec.field_2_column = field_2_column;
253: rec.field_3_xf_index = field_3_xf_index;
254: rec.field_4_string_len = field_4_string_len;
255: rec.field_5_unicode_flag = field_5_unicode_flag;
256: rec.field_6_value = field_6_value;
257: return rec;
258: }
259: }
|