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 * MulBlankRecord.java 58 * 59 * Created on December 10, 2001, 12:49 PM 60 */ 61 package org.apache.poi.hssf.record; 62 63 import org.apache.poi.util.LittleEndian; 64 65 /** 66 * Title: Mulitple Blank cell record <P> 67 * Description: Represents a set of columns in a row with no value but with styling. 68 * In this release we have read-only support for this record type. 69 * The RecordFactory converts this to a set of BlankRecord objects.<P> 70 * REFERENCE: PG 329 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P> 71 * @author Andrew C. Oliver (acoliver at apache dot org) 72 * @version 2.0-pre 73 * @see org.apache.poi.hssf.record.RecordFactory 74 * @see org.apache.poi.hssf.record.BlankRecord 75 */ 76 77 public class MulBlankRecord 78 extends Record 79 { 80 public final static short sid = 0xbe; 81 //private short field_1_row; 82 private int field_1_row; 83 private short field_2_first_col; 84 private short[] field_3_xfs; 85 private short field_4_last_col; 86 87 /** Creates new MulBlankRecord */ 88 89 public MulBlankRecord() 90 { 91 } 92 93 /** 94 * Constructs a MulBlank record and sets its fields appropriately. 95 * 96 * @param id id must be 0xbe or an exception will be throw upon validation 97 * @param size the size of the data area of the record 98 * @param data data of the record (should not contain sid/len) 99 */ 100 101 public MulBlankRecord(short id, short size, byte [] data) 102 { 103 super(id, size, data); 104 } 105 106 /** 107 * Constructs a MulBlank record and sets its fields appropriately. 108 * 109 * @param id id must be 0xbe or an exception will be throw upon validation 110 * @param size the size of the data area of the record 111 * @param data data of the record (should not contain sid/len) 112 * @param offset of the record's data 113 */ 114 115 public MulBlankRecord(short id, short size, byte [] data, int offset) 116 { 117 super(id, size, data, offset); 118 } 119 120 /** 121 * get the row number of the cells this represents 122 * 123 * @return row number 124 */ 125 126 //public short getRow() 127 public int getRow() 128 { 129 return field_1_row; 130 } 131 132 /** 133 * starting column (first cell this holds in the row) 134 * @return first column number 135 */ 136 137 public short getFirstColumn() 138 { 139 return field_2_first_col; 140 } 141 142 /** 143 * ending column (last cell this holds in the row) 144 * @return first column number 145 */ 146 147 public short getLastColumn() 148 { 149 return field_4_last_col; 150 } 151 152 /** 153 * get the number of columns this contains (last-first +1) 154 * @return number of columns (last - first +1) 155 */ 156 157 public int getNumColumns() 158 { 159 return field_4_last_col - field_2_first_col + 1; 160 } 161 162 /** 163 * returns the xf index for column (coffset = column - field_2_first_col) 164 * @param the column (coffset = column - field_2_first_col) 165 * @return the XF index for the column 166 */ 167 168 public short getXFAt(int coffset) 169 { 170 return field_3_xfs[ coffset ]; 171 } 172 173 /** 174 * called by the constructor, should set class level fields. Should throw 175 * runtime exception for bad/icomplete data. 176 * 177 * @param data raw data 178 * @param size size of data 179 */ 180 181 protected void fillFields(byte [] data, short size, int offset) 182 { 183 //field_1_row = LittleEndian.getShort(data, 0 + offset); 184 field_1_row = LittleEndian.getUShort(data, 0 + offset); 185 field_2_first_col = LittleEndian.getShort(data, 2 + offset); 186 field_3_xfs = parseXFs(data, 4, offset, size); 187 field_4_last_col = LittleEndian.getShort(data, 188 (field_3_xfs.length * 2) 189 + 4 + offset); 190 } 191 192 private short [] parseXFs(byte [] data, int offset, int recoffset, 193 short size) 194 { 195 short[] retval = new short[ ((size - offset) - 2) / 2 ]; 196 int idx = 0; 197 198 for (; offset < size - 2; ) 199 { 200 short xf = 0; 201 202 xf = LittleEndian.getShort(data, offset + recoffset); 203 offset += 2; 204 retval[ idx ] = xf; 205 idx++; 206 } 207 return retval; 208 } 209 210 public String toString() 211 { 212 StringBuffer buffer = new StringBuffer(); 213 214 buffer.append("[MULBLANK]\n"); 215 buffer.append("firstcol = ") 216 .append(Integer.toHexString(getFirstColumn())).append("\n"); 217 buffer.append(" lastcol = ") 218 .append(Integer.toHexString(getLastColumn())).append("\n"); 219 for (int k = 0; k < getNumColumns(); k++) 220 { 221 buffer.append("xf").append(k).append(" = ") 222 .append(Integer.toHexString(getXFAt(k))).append("\n"); 223 } 224 buffer.append("[/MULBLANK]\n"); 225 return buffer.toString(); 226 } 227 228 /** 229 * called by constructor, should throw runtime exception in the event of a 230 * record passed with a differing ID. 231 * 232 * @param id alleged id for this record 233 */ 234 235 protected void validateSid(short id) 236 { 237 if (id != sid) 238 { 239 throw new RecordFormatException("Not a MulBlankRecord!"); 240 } 241 } 242 243 public short getSid() 244 { 245 return this.sid; 246 } 247 248 public int serialize(int offset, byte [] data) 249 { 250 throw new RecordFormatException( 251 "Sorry, you can't serialize a MulBlank in this release"); 252 } 253 } 254