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