1 2 /* ==================================================================== 3 * The Apache Software License, Version 1.1 4 * 5 * Copyright (c) 2002 The Apache Software Foundation. All rights 6 * reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in 17 * the documentation and/or other materials provided with the 18 * distribution. 19 * 20 * 3. The end-user documentation included with the redistribution, 21 * if any, must include the following acknowledgment: 22 * "This product includes software developed by the 23 * Apache Software Foundation (http://www.apache.org/)." 24 * Alternately, this acknowledgment may appear in the software itself, 25 * if and wherever such third-party acknowledgments normally appear. 26 * 27 * 4. The names "Apache" and "Apache Software Foundation" and 28 * "Apache POI" must not be used to endorse or promote products 29 * derived from this software without prior written permission. For 30 * written permission, please contact apache@apache.org. 31 * 32 * 5. Products derived from this software may not be called "Apache", 33 * "Apache POI", nor may "Apache" appear in their name, without 34 * prior written permission of the Apache Software Foundation. 35 * 36 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED 37 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 38 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 39 * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR 40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 42 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 43 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 44 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 45 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 46 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 47 * SUCH DAMAGE. 48 * ==================================================================== 49 * 50 * This software consists of voluntary contributions made by many 51 * individuals on behalf of the Apache Software Foundation. For more 52 * information on the Apache Software Foundation, please see 53 * <http://www.apache.org/>. 54 */ 55 56 /* 57 * BlankRecord.java 58 * 59 * Created on December 10, 2001, 12:07 PM 60 */ 61 package org.apache.poi.hssf.record; 62 63 import org.apache.poi.util.LittleEndian; 64 65 /** 66 * Title: Blank cell record <P> 67 * Description: Represents a column in a row with no value but with styling.<P> 68 * REFERENCE: PG 287 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P> 69 * @author Andrew C. Oliver (acoliver at apache dot org) 70 * @version 2.0-pre 71 */ 72 73 public class BlankRecord 74 extends Record 75 implements CellValueRecordInterface, Comparable 76 { 77 public final static short sid = 0x201; 78 //private short field_1_row; 79 private int field_1_row; 80 private short field_2_col; 81 private short field_3_xf; 82 83 /** Creates a new instance of BlankRecord */ 84 85 public BlankRecord() 86 { 87 } 88 89 /** 90 * Constructs a BlankRecord and sets its fields appropriately 91 * 92 * @param id id must be 0x201 or an exception will be throw upon validation 93 * @param size the size of the data area of the record 94 * @param data data of the record (should not contain sid/len) 95 */ 96 97 public BlankRecord(short id, short size, byte [] data) 98 { 99 super(id, size, data); 100 } 101 102 /** 103 * Constructs a BlankRecord and sets its fields appropriately 104 * 105 * @param id id must be 0x201 or an exception will be throw upon validation 106 * @param size the size of the data area of the record 107 * @param data data of the record (should not contain sid/len) 108 * @param offset of the record's data 109 */ 110 111 public BlankRecord(short id, short size, byte [] data, int offset) 112 { 113 super(id, size, data, offset); 114 } 115 116 protected void fillFields(byte [] data, short size, int offset) 117 { 118 //field_1_row = LittleEndian.getShort(data, 0 + offset); 119 field_1_row = LittleEndian.getUShort(data, 0 + offset); 120 field_2_col = LittleEndian.getShort(data, 2 + offset); 121 field_3_xf = LittleEndian.getShort(data, 4 + offset); 122 } 123 124 /** 125 * called by constructor, should throw runtime exception in the event of a 126 * record passed with a differing ID. 127 * 128 * @param id alleged id for this record 129 */ 130 131 protected void validateSid(short id) 132 { 133 if (id != sid) 134 { 135 throw new RecordFormatException("NOT A BLANKRECORD!"); 136 } 137 } 138 139 /** 140 * set the row this cell occurs on 141 * @param row the row this cell occurs within 142 */ 143 144 //public void setRow(short row) 145 public void setRow(int row) 146 { 147 field_1_row = row; 148 } 149 150 /** 151 * get the row this cell occurs on 152 * 153 * @return the row 154 */ 155 156 //public short getRow() 157 public int getRow() 158 { 159 return field_1_row; 160 } 161 162 /** 163 * get the column this cell defines within the row 164 * 165 * @return the column 166 */ 167 168 public short getColumn() 169 { 170 return field_2_col; 171 } 172 173 /** 174 * set the index of the extended format record to style this cell with 175 * 176 * @param xf - the 0-based index of the extended format 177 * @see org.apache.poi.hssf.record.ExtendedFormatRecord 178 */ 179 180 public void setXFIndex(short xf) 181 { 182 field_3_xf = xf; 183 } 184 185 /** 186 * get the index of the extended format record to style this cell with 187 * 188 * @return extended format index 189 */ 190 191 public short getXFIndex() 192 { 193 return field_3_xf; 194 } 195 196 /** 197 * set the column this cell defines within the row 198 * 199 * @param col the column this cell defines 200 */ 201 202 public void setColumn(short col) 203 { 204 field_2_col = col; 205 } 206 207 public boolean isBefore(CellValueRecordInterface i) 208 { 209 if (this.getRow() > i.getRow()) 210 { 211 return false; 212 } 213 if ((this.getRow() == i.getRow()) 214 && (this.getColumn() > i.getColumn())) 215 { 216 return false; 217 } 218 if ((this.getRow() == i.getRow()) 219 && (this.getColumn() == i.getColumn())) 220 { 221 return false; 222 } 223 return true; 224 } 225 226 public boolean isAfter(CellValueRecordInterface i) 227 { 228 if (this.getRow() < i.getRow()) 229 { 230 return false; 231 } 232 if ((this.getRow() == i.getRow()) 233 && (this.getColumn() < i.getColumn())) 234 { 235 return false; 236 } 237 if ((this.getRow() == i.getRow()) 238 && (this.getColumn() == i.getColumn())) 239 { 240 return false; 241 } 242 return true; 243 } 244 245 public boolean isEqual(CellValueRecordInterface i) 246 { 247 return ((this.getRow() == i.getRow()) 248 && (this.getColumn() == i.getColumn())); 249 } 250 251 public boolean isInValueSection() 252 { 253 return true; 254 } 255 256 public boolean isValue() 257 { 258 return true; 259 } 260 261 /** 262 * return the non static version of the id for this record. 263 */ 264 265 public short getSid() 266 { 267 return BlankRecord.sid; 268 } 269 270 public String toString() 271 { 272 StringBuffer buffer = new StringBuffer(); 273 274 buffer.append("[BLANK]\n"); 275 buffer.append("row = ").append(Integer.toHexString(getRow())) 276 .append("\n"); 277 buffer.append("col = ").append(Integer.toHexString(getColumn())) 278 .append("\n"); 279 buffer.append("xf = ") 280 .append(Integer.toHexString(getXFIndex())).append("\n"); 281 buffer.append("[/BLANK]\n"); 282 return buffer.toString(); 283 } 284 285 /** 286 * called by the class that is responsible for writing this sucker. 287 * Subclasses should implement this so that their data is passed back in a 288 * byte array. 289 * 290 * @return byte array containing instance data 291 */ 292 293 public int serialize(int offset, byte [] data) 294 { 295 LittleEndian.putShort(data, 0 + offset, sid); 296 LittleEndian.putShort(data, 2 + offset, ( short ) 6); 297 //LittleEndian.putShort(data, 4 + offset, getRow()); 298 LittleEndian.putShort(data, 4 + offset, ( short ) getRow()); 299 LittleEndian.putShort(data, 6 + offset, getColumn()); 300 LittleEndian.putShort(data, 8 + offset, getXFIndex()); 301 return getRecordSize(); 302 } 303 304 public int getRecordSize() 305 { 306 return 10; 307 } 308 309 public int compareTo(Object obj) 310 { 311 CellValueRecordInterface loc = ( CellValueRecordInterface ) obj; 312 313 if ((this.getRow() == loc.getRow()) 314 && (this.getColumn() == loc.getColumn())) 315 { 316 return 0; 317 } 318 if (this.getRow() < loc.getRow()) 319 { 320 return -1; 321 } 322 if (this.getRow() > loc.getRow()) 323 { 324 return 1; 325 } 326 if (this.getColumn() < loc.getColumn()) 327 { 328 return -1; 329 } 330 if (this.getColumn() > loc.getColumn()) 331 { 332 return 1; 333 } 334 return -1; 335 } 336 337 public boolean equals(Object obj) 338 { 339 if (!(obj instanceof CellValueRecordInterface)) 340 { 341 return false; 342 } 343 CellValueRecordInterface loc = ( CellValueRecordInterface ) obj; 344 345 if ((this.getRow() == loc.getRow()) 346 && (this.getColumn() == loc.getColumn())) 347 { 348 return true; 349 } 350 return false; 351 } 352 } 353