1 2 17 18 19 20 package org.apache.poi.hssf.record; 21 22 23 24 import org.apache.poi.util.*; 25 26 33 public class LinkedDataRecord 34 extends Record 35 { 36 public final static short sid = 0x1051; 37 private byte field_1_linkType; 38 public final static byte LINK_TYPE_TITLE_OR_TEXT = 0; 39 public final static byte LINK_TYPE_VALUES = 1; 40 public final static byte LINK_TYPE_CATEGORIES = 2; 41 private byte field_2_referenceType; 42 public final static byte REFERENCE_TYPE_DEFAULT_CATEGORIES = 0; 43 public final static byte REFERENCE_TYPE_DIRECT = 1; 44 public final static byte REFERENCE_TYPE_WORKSHEET = 2; 45 public final static byte REFERENCE_TYPE_NOT_USED = 3; 46 public final static byte REFERENCE_TYPE_ERROR_REPORTED = 4; 47 private short field_3_options; 48 private BitField customNumberFormat = new BitField(0x1); 49 private short field_4_indexNumberFmtRecord; 50 private LinkedDataFormulaField field_5_formulaOfLink; 51 52 53 public LinkedDataRecord() 54 { 55 56 } 57 58 66 67 public LinkedDataRecord(short id, short size, byte [] data) 68 { 69 super(id, size, data); 70 71 } 72 73 82 83 public LinkedDataRecord(short id, short size, byte [] data, int offset) 84 { 85 super(id, size, data, offset); 86 87 } 88 89 94 protected void validateSid(short id) 95 { 96 if (id != sid) 97 { 98 throw new RecordFormatException("Not a LinkedData record"); 99 } 100 } 101 102 protected void fillFields(byte [] data, short size, int offset) 103 { 104 105 int pos = 0; 106 field_1_linkType = data[ pos + 0x0 + offset ]; 107 field_2_referenceType = data[ pos + 0x1 + offset ]; 108 field_3_options = LittleEndian.getShort(data, pos + 0x2 + offset); 109 field_4_indexNumberFmtRecord = LittleEndian.getShort(data, pos + 0x4 + offset); 110 field_5_formulaOfLink = new org.apache.poi.hssf.record.LinkedDataFormulaField(); 111 pos += field_5_formulaOfLink.fillField(data,size,pos + offset + 6); 112 113 } 114 115 public String toString() 116 { 117 StringBuffer buffer = new StringBuffer (); 118 119 buffer.append("[AI]\n"); 120 buffer.append(" .linkType = ") 121 .append("0x").append(HexDump.toHex( getLinkType ())) 122 .append(" (").append( getLinkType() ).append(" )"); 123 buffer.append(System.getProperty("line.separator")); 124 buffer.append(" .referenceType = ") 125 .append("0x").append(HexDump.toHex( getReferenceType ())) 126 .append(" (").append( getReferenceType() ).append(" )"); 127 buffer.append(System.getProperty("line.separator")); 128 buffer.append(" .options = ") 129 .append("0x").append(HexDump.toHex( getOptions ())) 130 .append(" (").append( getOptions() ).append(" )"); 131 buffer.append(System.getProperty("line.separator")); 132 buffer.append(" .customNumberFormat = ").append(isCustomNumberFormat()).append('\n'); 133 buffer.append(" .indexNumberFmtRecord = ") 134 .append("0x").append(HexDump.toHex( getIndexNumberFmtRecord ())) 135 .append(" (").append( getIndexNumberFmtRecord() ).append(" )"); 136 buffer.append(System.getProperty("line.separator")); 137 buffer.append(" .formulaOfLink = ") 138 .append(" (").append( getFormulaOfLink() ).append(" )"); 139 buffer.append(System.getProperty("line.separator")); 140 141 buffer.append("[/AI]\n"); 142 return buffer.toString(); 143 } 144 145 public int serialize(int offset, byte[] data) 146 { 147 int pos = 0; 148 149 LittleEndian.putShort(data, 0 + offset, sid); 150 LittleEndian.putShort(data, 2 + offset, (short)(getRecordSize() - 4)); 151 152 data[ 4 + offset + pos ] = field_1_linkType; 153 data[ 5 + offset + pos ] = field_2_referenceType; 154 LittleEndian.putShort(data, 6 + offset + pos, field_3_options); 155 LittleEndian.putShort(data, 8 + offset + pos, field_4_indexNumberFmtRecord); 156 pos += field_5_formulaOfLink.serializeField( pos + 10 + offset, data ); 157 158 return getRecordSize(); 159 } 160 161 164 public int getRecordSize() 165 { 166 return 4 + 1 + 1 + 2 + 2 + field_5_formulaOfLink.getSize(); 167 } 168 169 public short getSid() 170 { 171 return this.sid; 172 } 173 174 public Object clone() { 175 LinkedDataRecord rec = new LinkedDataRecord(); 176 177 rec.field_1_linkType = field_1_linkType; 178 rec.field_2_referenceType = field_2_referenceType; 179 rec.field_3_options = field_3_options; 180 rec.field_4_indexNumberFmtRecord = field_4_indexNumberFmtRecord; 181 rec.field_5_formulaOfLink = ((org.apache.poi.hssf.record.LinkedDataFormulaField)field_5_formulaOfLink.clone());; 182 return rec; 183 } 184 185 186 187 188 196 public byte getLinkType() 197 { 198 return field_1_linkType; 199 } 200 201 210 public void setLinkType(byte field_1_linkType) 211 { 212 this.field_1_linkType = field_1_linkType; 213 } 214 215 225 public byte getReferenceType() 226 { 227 return field_2_referenceType; 228 } 229 230 241 public void setReferenceType(byte field_2_referenceType) 242 { 243 this.field_2_referenceType = field_2_referenceType; 244 } 245 246 249 public short getOptions() 250 { 251 return field_3_options; 252 } 253 254 257 public void setOptions(short field_3_options) 258 { 259 this.field_3_options = field_3_options; 260 } 261 262 265 public short getIndexNumberFmtRecord() 266 { 267 return field_4_indexNumberFmtRecord; 268 } 269 270 273 public void setIndexNumberFmtRecord(short field_4_indexNumberFmtRecord) 274 { 275 this.field_4_indexNumberFmtRecord = field_4_indexNumberFmtRecord; 276 } 277 278 281 public LinkedDataFormulaField getFormulaOfLink() 282 { 283 return field_5_formulaOfLink; 284 } 285 286 289 public void setFormulaOfLink(LinkedDataFormulaField field_5_formulaOfLink) 290 { 291 this.field_5_formulaOfLink = field_5_formulaOfLink; 292 } 293 294 298 public void setCustomNumberFormat(boolean value) 299 { 300 field_3_options = customNumberFormat.setShortBoolean(field_3_options, value); 301 } 302 303 307 public boolean isCustomNumberFormat() 308 { 309 return customNumberFormat.isSet(field_3_options); 310 } 311 312 313 } 315 316 317 318 | Popular Tags |