1 2 17 18 19 24 package org.apache.poi.hssf.record; 25 26 import org.apache.poi.util.LittleEndian; 27 import org.apache.poi.util.StringUtil; 28 29 38 39 public class LabelRecord 40 extends Record 41 implements CellValueRecordInterface 42 { 43 public final static short sid = 0x204; 44 private int field_1_row; 46 private short field_2_column; 47 private short field_3_xf_index; 48 private short field_4_string_len; 49 private byte field_5_unicode_flag; 50 private String field_6_value; 51 52 53 54 public LabelRecord() 55 { 56 } 57 58 65 66 public LabelRecord(short id, short size, byte [] data) 67 { 68 super(id, size, data); 69 } 70 71 79 80 public LabelRecord(short id, short size, byte [] data, int offset) 81 { 82 super(id, size, data, offset); 83 } 84 85 91 92 protected void validateSid(short id) 93 { 94 if (id != this.sid) 95 { 96 throw new RecordFormatException("Not a valid LabelRecord"); 97 } 98 } 99 100 107 108 protected void fillFields(byte [] data, short size, int offset) 109 { 110 field_1_row = LittleEndian.getUShort(data, 0 + offset); 112 field_2_column = LittleEndian.getShort(data, 2 + offset); 113 field_3_xf_index = LittleEndian.getShort(data, 4 + offset); 114 field_4_string_len = LittleEndian.getShort(data, 6 + offset); 115 field_5_unicode_flag = data[ 8 + offset ]; 116 if (field_4_string_len > 0) { 117 if (isUnCompressedUnicode()) { 118 field_6_value = StringUtil.getFromUnicodeLE(data, 9 + offset, 119 field_4_string_len); 120 } 121 else { 122 field_6_value = StringUtil.getFromCompressedUnicode(data, 9 + offset, 123 getStringLength()); 124 } 125 } else field_6_value = null; 126 } 127 128 141 public int getRow() 143 { 144 return field_1_row; 145 } 146 147 public short getColumn() 148 { 149 return field_2_column; 150 } 151 152 public short getXFIndex() 153 { 154 return field_3_xf_index; 155 } 156 157 161 162 public short getStringLength() 163 { 164 return field_4_string_len; 165 } 166 167 171 172 public boolean isUnCompressedUnicode() 173 { 174 return (field_5_unicode_flag == 1); 175 } 176 177 183 184 public String getValue() 185 { 186 return field_6_value; 187 } 188 189 192 193 public int serialize(int offset, byte [] data) 194 { 195 throw new RecordFormatException( 196 "Label Records are supported READ ONLY...convert to LabelSST"); 197 } 198 199 public short getSid() 200 { 201 return this.sid; 202 } 203 204 public String toString() 205 { 206 StringBuffer buffer = new StringBuffer (); 207 buffer.append("[LABEL]\n"); 208 buffer.append(" .row = ") 209 .append(Integer.toHexString(getRow())).append("\n"); 210 buffer.append(" .column = ") 211 .append(Integer.toHexString(getColumn())).append("\n"); 212 buffer.append(" .xfindex = ") 213 .append(Integer.toHexString(getXFIndex())).append("\n"); 214 buffer.append(" .string_len = ") 215 .append(Integer.toHexString(field_4_string_len)).append("\n"); 216 buffer.append(" .unicode_flag = ") 217 .append(Integer.toHexString(field_5_unicode_flag)).append("\n"); 218 buffer.append(" .value = ") 219 .append(getValue()).append("\n"); 220 buffer.append("[/LABEL]\n"); 221 return buffer.toString(); 222 } 223 224 225 public boolean isBefore(CellValueRecordInterface i) 226 { 227 if (this.getRow() > i.getRow()) 228 { 229 return false; 230 } 231 if ((this.getRow() == i.getRow()) 232 && (this.getColumn() > i.getColumn())) 233 { 234 return false; 235 } 236 if ((this.getRow() == i.getRow()) 237 && (this.getColumn() == i.getColumn())) 238 { 239 return false; 240 } 241 return true; 242 } 243 244 public boolean isAfter(CellValueRecordInterface i) 245 { 246 if (this.getRow() < i.getRow()) 247 { 248 return false; 249 } 250 if ((this.getRow() == i.getRow()) 251 && (this.getColumn() < i.getColumn())) 252 { 253 return false; 254 } 255 if ((this.getRow() == i.getRow()) 256 && (this.getColumn() == i.getColumn())) 257 { 258 return false; 259 } 260 return true; 261 } 262 263 public boolean isEqual(CellValueRecordInterface i) 264 { 265 return ((this.getRow() == i.getRow()) 266 && (this.getColumn() == i.getColumn())); 267 } 268 269 public boolean isInValueSection() 270 { 271 return true; 272 } 273 274 public boolean isValue() 275 { 276 return true; 277 } 278 279 282 283 public void setColumn(short col) 284 { 285 } 286 287 290 291 public void setRow(int row) 293 { 294 } 295 296 299 300 public void setXFIndex(short xf) 301 { 302 } 303 304 public Object clone() { 305 LabelRecord rec = new LabelRecord(); 306 rec.field_1_row = field_1_row; 307 rec.field_2_column = field_2_column; 308 rec.field_3_xf_index = field_3_xf_index; 309 rec.field_4_string_len = field_4_string_len; 310 rec.field_5_unicode_flag = field_5_unicode_flag; 311 rec.field_6_value = field_6_value; 312 return rec; 313 } 314 } 315 | Popular Tags |