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 211 /** 212 * Get the link type field for the LinkedData record. 213 * 214 * @return One of 215 * LINK_TYPE_TITLE_OR_TEXT 216 * LINK_TYPE_VALUES 217 * LINK_TYPE_CATEGORIES 218 */ 219 public byte getLinkType() 220 { 221 return field_1_linkType; 222 } 223 224 /** 225 * Set the link type field for the LinkedData record. 226 * 227 * @param field_1_linkType 228 * One of 229 * LINK_TYPE_TITLE_OR_TEXT 230 * LINK_TYPE_VALUES 231 * LINK_TYPE_CATEGORIES 232 */ 233 public void setLinkType(byte field_1_linkType) 234 { 235 this.field_1_linkType = field_1_linkType; 236 } 237 238 /** 239 * Get the reference type field for the LinkedData record. 240 * 241 * @return One of 242 * REFERENCE_TYPE_DEFAULT_CATEGORIES 243 * REFERENCE_TYPE_DIRECT 244 * REFERENCE_TYPE_WORKSHEET 245 * REFERENCE_TYPE_NOT_USED 246 * REFERENCE_TYPE_ERROR_REPORTED 247 */ 248 public byte getReferenceType() 249 { 250 return field_2_referenceType; 251 } 252 253 /** 254 * Set the reference type field for the LinkedData record. 255 * 256 * @param field_2_referenceType 257 * One of 258 * REFERENCE_TYPE_DEFAULT_CATEGORIES 259 * REFERENCE_TYPE_DIRECT 260 * REFERENCE_TYPE_WORKSHEET 261 * REFERENCE_TYPE_NOT_USED 262 * REFERENCE_TYPE_ERROR_REPORTED 263 */ 264 public void setReferenceType(byte field_2_referenceType) 265 { 266 this.field_2_referenceType = field_2_referenceType; 267 } 268 269 /** 270 * Get the options field for the LinkedData record. 271 */ 272 public short getOptions() 273 { 274 return field_3_options; 275 } 276 277 /** 278 * Set the options field for the LinkedData record. 279 */ 280 public void setOptions(short field_3_options) 281 { 282 this.field_3_options = field_3_options; 283 } 284 285 /** 286 * Get the index number fmt record field for the LinkedData record. 287 */ 288 public short getIndexNumberFmtRecord() 289 { 290 return field_4_indexNumberFmtRecord; 291 } 292 293 /** 294 * Set the index number fmt record field for the LinkedData record. 295 */ 296 public void setIndexNumberFmtRecord(short field_4_indexNumberFmtRecord) 297 { 298 this.field_4_indexNumberFmtRecord = field_4_indexNumberFmtRecord; 299 } 300 301 /** 302 * Get the formula of link field for the LinkedData record. 303 */ 304 public short getFormulaOfLink() 305 { 306 return field_5_formulaOfLink; 307 } 308 309 /** 310 * Set the formula of link field for the LinkedData record. 311 */ 312 public void setFormulaOfLink(short field_5_formulaOfLink) 313 { 314 this.field_5_formulaOfLink = field_5_formulaOfLink; 315 } 316 317 /** 318 * Sets the custom number format field value. 319 * true if this object has a custom number format 320 */ 321 public void setCustomNumberFormat(boolean value) 322 { 323 field_3_options = customNumberFormat.setShortBoolean(field_3_options, value); 324 } 325 326 /** 327 * true if this object has a custom number format 328 * @return the custom number format field value. 329 */ 330 public boolean isCustomNumberFormat() 331 { 332 return customNumberFormat.isSet(field_3_options); 333 } 334 335 336 } // END OF CLASS 337 338 339 340 341