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           = 2;
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  LinkedDataFormulaField 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      /**
111       * Constructs a LinkedData record and sets its fields appropriately.
112       *
113       * @param id    id must be 0x1051 or an exception
114       *              will be throw upon validation
115       * @param size  size the size of the data area of the record
116       * @param data  data of the record (should not contain sid/len)
117       * @param offset of the record's data
118       */
119  
120      public LinkedDataRecord(short id, short size, byte [] data, int offset)
121      {
122          super(id, size, data, offset);
123      
124      }
125  
126      /**
127       * Checks the sid matches the expected side for this record
128       *
129       * @param id   the expected sid.
130       */
131      protected void validateSid(short id)
132      {
133          if (id != sid)
134          {
135              throw new RecordFormatException("Not a LinkedData record");
136          }
137      }
138  
139      protected void fillFields(byte [] data, short size, int offset)
140      {
141  
142          int pos = 0;
143          field_1_linkType               = data[ pos + 0x0 + offset ];
144          field_2_referenceType          = data[ pos + 0x1 + offset ];
145          field_3_options                = LittleEndian.getShort(data, pos + 0x2 + offset);
146          field_4_indexNumberFmtRecord   = LittleEndian.getShort(data, pos + 0x4 + offset);
147          field_5_formulaOfLink = new org.apache.poi.hssf.record.LinkedDataFormulaField();
148          pos += field_5_formulaOfLink.fillField(data,size,pos + offset + 6);
149  
150      }
151  
152      public String toString()
153      {
154          StringBuffer buffer = new StringBuffer();
155  
156          buffer.append("[AI]\n");
157          buffer.append("    .linkType             = ")
158              .append("0x").append(HexDump.toHex(  getLinkType ()))
159              .append(" (").append( getLinkType() ).append(" )");
160          buffer.append(System.getProperty("line.separator")); 
161          buffer.append("    .referenceType        = ")
162              .append("0x").append(HexDump.toHex(  getReferenceType ()))
163              .append(" (").append( getReferenceType() ).append(" )");
164          buffer.append(System.getProperty("line.separator")); 
165          buffer.append("    .options              = ")
166              .append("0x").append(HexDump.toHex(  getOptions ()))
167              .append(" (").append( getOptions() ).append(" )");
168          buffer.append(System.getProperty("line.separator")); 
169          buffer.append("         .customNumberFormat       = ").append(isCustomNumberFormat()).append('\n'); 
170          buffer.append("    .indexNumberFmtRecord = ")
171              .append("0x").append(HexDump.toHex(  getIndexNumberFmtRecord ()))
172              .append(" (").append( getIndexNumberFmtRecord() ).append(" )");
173          buffer.append(System.getProperty("line.separator")); 
174          buffer.append("    .formulaOfLink        = ")
175              .append(" (").append( getFormulaOfLink() ).append(" )");
176          buffer.append(System.getProperty("line.separator")); 
177  
178          buffer.append("[/AI]\n");
179          return buffer.toString();
180      }
181  
182      public int serialize(int offset, byte[] data)
183      {
184          int pos = 0;
185  
186          LittleEndian.putShort(data, 0 + offset, sid);
187          LittleEndian.putShort(data, 2 + offset, (short)(getRecordSize() - 4));
188  
189          data[ 4 + offset + pos ] = field_1_linkType;
190          data[ 5 + offset + pos ] = field_2_referenceType;
191          LittleEndian.putShort(data, 6 + offset + pos, field_3_options);
192          LittleEndian.putShort(data, 8 + offset + pos, field_4_indexNumberFmtRecord);
193          pos += field_5_formulaOfLink.serializeField( pos + 10 + offset, data );
194  
195          return getRecordSize();
196      }
197  
198      /**
199       * Size of record (exluding 4 byte header)
200       */
201      public int getRecordSize()
202      {
203          return 4  + 1 + 1 + 2 + 2 + field_5_formulaOfLink.getSize();
204      }
205  
206      public short getSid()
207      {
208          return this.sid;
209      }
210  
211      public Object clone() {
212          LinkedDataRecord rec = new LinkedDataRecord();
213      
214          rec.field_1_linkType = field_1_linkType;
215          rec.field_2_referenceType = field_2_referenceType;
216          rec.field_3_options = field_3_options;
217          rec.field_4_indexNumberFmtRecord = field_4_indexNumberFmtRecord;
218          rec.field_5_formulaOfLink = ((org.apache.poi.hssf.record.LinkedDataFormulaField)field_5_formulaOfLink.clone());;
219          return rec;
220      }
221  
222  
223  
224  
225      /**
226       * Get the link type field for the LinkedData record.
227       *
228       * @return  One of 
229       *        LINK_TYPE_TITLE_OR_TEXT
230       *        LINK_TYPE_VALUES
231       *        LINK_TYPE_CATEGORIES
232       */
233      public byte getLinkType()
234      {
235          return field_1_linkType;
236      }
237  
238      /**
239       * Set the link type field for the LinkedData record.
240       *
241       * @param field_1_linkType
242       *        One of 
243       *        LINK_TYPE_TITLE_OR_TEXT
244       *        LINK_TYPE_VALUES
245       *        LINK_TYPE_CATEGORIES
246       */
247      public void setLinkType(byte field_1_linkType)
248      {
249          this.field_1_linkType = field_1_linkType;
250      }
251  
252      /**
253       * Get the reference type field for the LinkedData record.
254       *
255       * @return  One of 
256       *        REFERENCE_TYPE_DEFAULT_CATEGORIES
257       *        REFERENCE_TYPE_DIRECT
258       *        REFERENCE_TYPE_WORKSHEET
259       *        REFERENCE_TYPE_NOT_USED
260       *        REFERENCE_TYPE_ERROR_REPORTED
261       */
262      public byte getReferenceType()
263      {
264          return field_2_referenceType;
265      }
266  
267      /**
268       * Set the reference type field for the LinkedData record.
269       *
270       * @param field_2_referenceType
271       *        One of 
272       *        REFERENCE_TYPE_DEFAULT_CATEGORIES
273       *        REFERENCE_TYPE_DIRECT
274       *        REFERENCE_TYPE_WORKSHEET
275       *        REFERENCE_TYPE_NOT_USED
276       *        REFERENCE_TYPE_ERROR_REPORTED
277       */
278      public void setReferenceType(byte field_2_referenceType)
279      {
280          this.field_2_referenceType = field_2_referenceType;
281      }
282  
283      /**
284       * Get the options field for the LinkedData record.
285       */
286      public short getOptions()
287      {
288          return field_3_options;
289      }
290  
291      /**
292       * Set the options field for the LinkedData record.
293       */
294      public void setOptions(short field_3_options)
295      {
296          this.field_3_options = field_3_options;
297      }
298  
299      /**
300       * Get the index number fmt record field for the LinkedData record.
301       */
302      public short getIndexNumberFmtRecord()
303      {
304          return field_4_indexNumberFmtRecord;
305      }
306  
307      /**
308       * Set the index number fmt record field for the LinkedData record.
309       */
310      public void setIndexNumberFmtRecord(short field_4_indexNumberFmtRecord)
311      {
312          this.field_4_indexNumberFmtRecord = field_4_indexNumberFmtRecord;
313      }
314  
315      /**
316       * Get the formula of link field for the LinkedData record.
317       */
318      public LinkedDataFormulaField getFormulaOfLink()
319      {
320          return field_5_formulaOfLink;
321      }
322  
323      /**
324       * Set the formula of link field for the LinkedData record.
325       */
326      public void setFormulaOfLink(LinkedDataFormulaField field_5_formulaOfLink)
327      {
328          this.field_5_formulaOfLink = field_5_formulaOfLink;
329      }
330  
331      /**
332       * Sets the custom number format field value.
333       * true if this object has a custom number format
334       */
335      public void setCustomNumberFormat(boolean value)
336      {
337          field_3_options = customNumberFormat.setShortBoolean(field_3_options, value);
338      }
339  
340      /**
341       * true if this object has a custom number format
342       * @return  the custom number format field value.
343       */
344      public boolean isCustomNumberFormat()
345      {
346          return customNumberFormat.isSet(field_3_options);
347      }
348  
349  
350  }  // END OF CLASS
351  
352  
353  
354  
355