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 package org.apache.poi.hssf.record; 58 59 60 61 import org.apache.poi.util.*; 62 63 /** 64 * Describes a linked data record. This record referes to the series data or text. 65 * NOTE: This source is automatically generated please do not modify this file. Either subclass or 66 * remove the record in src/records/definitions. 67 68 * @author Glen Stampoultzis (glens at apache.org) 69 */ 70 public class LinkedDataRecord 71 extends Record 72 { 73 public final static short sid = 0x1051; 74 private byte field_1_linkType; 75 public final static byte LINK_TYPE_TITLE_OR_TEXT = 0; 76 public final static byte LINK_TYPE_VALUES = 1; 77 public final static byte LINK_TYPE_CATEGORIES = 1; 78 private byte field_2_referenceType; 79 public final static byte REFERENCE_TYPE_DEFAULT_CATEGORIES = 0; 80 public final static byte REFERENCE_TYPE_DIRECT = 1; 81 public final static byte REFERENCE_TYPE_WORKSHEET = 2; 82 public final static byte REFERENCE_TYPE_NOT_USED = 3; 83 public final static byte REFERENCE_TYPE_ERROR_REPORTED = 4; 84 private short field_3_options; 85 private BitField customNumberFormat = new BitField(0x1); 86 private short field_4_indexNumberFmtRecord; 87 private short field_5_formulaOfLink; 88 89 90 public LinkedDataRecord() 91 { 92 93 } 94 95 /** 96 * Constructs a LinkedData record and sets its fields appropriately. 97 * 98 * @param id id must be 0x1051 or an exception 99 * will be throw upon validation 100 * @param size size the size of the data area of the record 101 * @param data data of the record (should not contain sid/len) 102 */ 103 104 public LinkedDataRecord(short id, short size, byte [] data) 105 { 106 super(id, size, data); 107 } 108 109 /** 110 * Constructs a LinkedData record and sets its fields appropriately. 111 * 112 * @param id id must be 0x1051 or an exception 113 * will be throw upon validation 114 * @param size size the size of the data area of the record 115 * @param data data of the record (should not contain sid/len) 116 * @param offset of the record's data 117 */ 118 119 public LinkedDataRecord(short id, short size, byte [] data, int offset) 120 { 121 super(id, size, data, offset); 122 } 123 124 /** 125 * Checks the sid matches the expected side for this record 126 * 127 * @param id the expected sid. 128 */ 129 protected void validateSid(short id) 130 { 131 if (id != sid) 132 { 133 throw new RecordFormatException("Not a LinkedData record"); 134 } 135 } 136 137 protected void fillFields(byte [] data, short size, int offset) 138 { 139 field_1_linkType = data[ 0x0 + offset ]; 140 field_2_referenceType = data[ 0x1 + offset ]; 141 field_3_options = LittleEndian.getShort(data, 0x2 + offset); 142 field_4_indexNumberFmtRecord = LittleEndian.getShort(data, 0x4 + offset); 143 field_5_formulaOfLink = LittleEndian.getShort(data, 0x6 + offset); 144 145 } 146 147 public String toString() 148 { 149 StringBuffer buffer = new StringBuffer(); 150 151 buffer.append("[LinkedData]\n"); 152 153 buffer.append(" .linkType = ") 154 .append("0x") 155 .append(HexDump.toHex((byte)getLinkType())) 156 .append(" (").append(getLinkType()).append(" )\n"); 157 158 buffer.append(" .referenceType = ") 159 .append("0x") 160 .append(HexDump.toHex((byte)getReferenceType())) 161 .append(" (").append(getReferenceType()).append(" )\n"); 162 163 buffer.append(" .options = ") 164 .append("0x") 165 .append(HexDump.toHex((short)getOptions())) 166 .append(" (").append(getOptions()).append(" )\n"); 167 buffer.append(" .customNumberFormat = ").append(isCustomNumberFormat ()).append('\n'); 168 169 buffer.append(" .indexNumberFmtRecord = ") 170 .append("0x") 171 .append(HexDump.toHex((short)getIndexNumberFmtRecord())) 172 .append(" (").append(getIndexNumberFmtRecord()).append(" )\n"); 173 174 buffer.append(" .formulaOfLink = ") 175 .append("0x") 176 .append(HexDump.toHex((short)getFormulaOfLink())) 177 .append(" (").append(getFormulaOfLink()).append(" )\n"); 178 179 buffer.append("[/LinkedData]\n"); 180 return buffer.toString(); 181 } 182 183 public int serialize(int offset, byte[] data) 184 { 185 LittleEndian.putShort(data, 0 + offset, sid); 186 LittleEndian.putShort(data, 2 + offset, (short)(getRecordSize() - 4)); 187 188 data[ 4 + offset ] = field_1_linkType; 189 data[ 5 + offset ] = field_2_referenceType; 190 LittleEndian.putShort(data, 6 + offset, field_3_options); 191 LittleEndian.putShort(data, 8 + offset, field_4_indexNumberFmtRecord); 192 LittleEndian.putShort(data, 10 + offset, field_5_formulaOfLink); 193 194 return getRecordSize(); 195 } 196 197 /** 198 * Size of record (exluding 4 byte header) 199 */ 200 public int getRecordSize() 201 { 202 return 4 + 1 + 1 + 2 + 2 + 2; 203 } 204 205 public short getSid() 206 { 207 return this.sid; 208 } 209 210 public Object clone() { 211 LinkedDataRecord rec = new LinkedDataRecord(); 212 213 rec.field_1_linkType = field_1_linkType; 214 rec.field_2_referenceType = field_2_referenceType; 215 rec.field_3_options = field_3_options; 216 rec.field_4_indexNumberFmtRecord = field_4_indexNumberFmtRecord; 217 rec.field_5_formulaOfLink = field_5_formulaOfLink; 218 219 return rec; 220 } 221 222 223 /** 224 * Get the link type field for the LinkedData record. 225 * 226 * @return One of 227 * LINK_TYPE_TITLE_OR_TEXT 228 * LINK_TYPE_VALUES 229 * LINK_TYPE_CATEGORIES 230 */ 231 public byte getLinkType() 232 { 233 return field_1_linkType; 234 } 235 236 /** 237 * Set the link type field for the LinkedData record. 238 * 239 * @param field_1_linkType 240 * One of 241 * LINK_TYPE_TITLE_OR_TEXT 242 * LINK_TYPE_VALUES 243 * LINK_TYPE_CATEGORIES 244 */ 245 public void setLinkType(byte field_1_linkType) 246 { 247 this.field_1_linkType = field_1_linkType; 248 } 249 250 /** 251 * Get the reference type field for the LinkedData record. 252 * 253 * @return One of 254 * REFERENCE_TYPE_DEFAULT_CATEGORIES 255 * REFERENCE_TYPE_DIRECT 256 * REFERENCE_TYPE_WORKSHEET 257 * REFERENCE_TYPE_NOT_USED 258 * REFERENCE_TYPE_ERROR_REPORTED 259 */ 260 public byte getReferenceType() 261 { 262 return field_2_referenceType; 263 } 264 265 /** 266 * Set the reference type field for the LinkedData record. 267 * 268 * @param field_2_referenceType 269 * One of 270 * REFERENCE_TYPE_DEFAULT_CATEGORIES 271 * REFERENCE_TYPE_DIRECT 272 * REFERENCE_TYPE_WORKSHEET 273 * REFERENCE_TYPE_NOT_USED 274 * REFERENCE_TYPE_ERROR_REPORTED 275 */ 276 public void setReferenceType(byte field_2_referenceType) 277 { 278 this.field_2_referenceType = field_2_referenceType; 279 } 280 281 /** 282 * Get the options field for the LinkedData record. 283 */ 284 public short getOptions() 285 { 286 return field_3_options; 287 } 288 289 /** 290 * Set the options field for the LinkedData record. 291 */ 292 public void setOptions(short field_3_options) 293 { 294 this.field_3_options = field_3_options; 295 } 296 297 /** 298 * Get the index number fmt record field for the LinkedData record. 299 */ 300 public short getIndexNumberFmtRecord() 301 { 302 return field_4_indexNumberFmtRecord; 303 } 304 305 /** 306 * Set the index number fmt record field for the LinkedData record. 307 */ 308 public void setIndexNumberFmtRecord(short field_4_indexNumberFmtRecord) 309 { 310 this.field_4_indexNumberFmtRecord = field_4_indexNumberFmtRecord; 311 } 312 313 /** 314 * Get the formula of link field for the LinkedData record. 315 */ 316 public short getFormulaOfLink() 317 { 318 return field_5_formulaOfLink; 319 } 320 321 /** 322 * Set the formula of link field for the LinkedData record. 323 */ 324 public void setFormulaOfLink(short field_5_formulaOfLink) 325 { 326 this.field_5_formulaOfLink = field_5_formulaOfLink; 327 } 328 329 /** 330 * Sets the custom number format field value. 331 * true if this object has a custom number format 332 */ 333 public void setCustomNumberFormat(boolean value) 334 { 335 field_3_options = customNumberFormat.setShortBoolean(field_3_options, value); 336 } 337 338 /** 339 * true if this object has a custom number format 340 * @return the custom number format field value. 341 */ 342 public boolean isCustomNumberFormat() 343 { 344 return customNumberFormat.isSet(field_3_options); 345 } 346 347 348 } // END OF CLASS 349 350 351 352 353