KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > poi > hssf > record > NameRecord


1
2 /* ====================================================================
3    Copyright 2002-2004 Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16 ==================================================================== */

17         
18
19 package org.apache.poi.hssf.record;
20
21 import java.util.List JavaDoc;
22 import java.util.Stack JavaDoc;
23
24 import org.apache.poi.hssf.model.Workbook;
25 import org.apache.poi.hssf.record.formula.Area3DPtg;
26 import org.apache.poi.hssf.record.formula.Ptg;
27 import org.apache.poi.hssf.record.formula.Ref3DPtg;
28 import org.apache.poi.hssf.util.RangeAddress;
29 import org.apache.poi.util.HexDump;
30 import org.apache.poi.util.LittleEndian;
31 import org.apache.poi.util.StringUtil;
32
33 /**
34  * Title: Name Record (aka Named Range) <P>
35  * Description: Defines a named range within a workbook. <P>
36  * REFERENCE: <P>
37  * @author Libin Roman (Vista Portal LDT. Developer)
38  * @author Sergei Kozello (sergeikozello at mail.ru)
39  * @author Glen Stampoultzis (glens at apache.org)
40  * @version 1.0-pre
41  */

42
43 public class NameRecord extends Record {
44     /**
45      */

46     public final static short sid = 0x18; //Docs says that it is 0x218
47

48     /**Included for completeness sake, not implemented
49        */

50     public final static byte BUILTIN_CONSOLIDATE_AREA = (byte)1;
51     
52     /**Included for completeness sake, not implemented
53      */

54     public final static byte BUILTIN_AUTO_OPEN = (byte)2;
55
56     /**Included for completeness sake, not implemented
57      */

58     public final static byte BUILTIN_AUTO_CLOSE = (byte)3;
59
60     /**Included for completeness sake, not implemented
61      */

62     public final static byte BUILTIN_DATABASE = (byte)4;
63
64     /**Included for completeness sake, not implemented
65      */

66     public final static byte BUILTIN_CRITERIA = (byte)5;
67     
68     public final static byte BUILTIN_PRINT_AREA = (byte)6;
69     public final static byte BUILTIN_PRINT_TITLE = (byte)7;
70     
71     /**Included for completeness sake, not implemented
72      */

73     public final static byte BUILTIN_RECORDER = (byte)8;
74     
75     /**Included for completeness sake, not implemented
76      */

77     public final static byte BUILTIN_DATA_FORM = (byte)9;
78     
79     /**Included for completeness sake, not implemented
80      */

81
82     public final static byte BUILTIN_AUTO_ACTIVATE = (byte)10;
83     
84     /**Included for completeness sake, not implemented
85      */

86
87     public final static byte BUILTIN_AUTO_DEACTIVATE = (byte)11;
88     
89     /**Included for completeness sake, not implemented
90      */

91     public final static byte BUILTIN_SHEET_TITLE = (byte)12;
92     
93     public static final short OPT_HIDDEN_NAME = (short) 0x0001;
94     public static final short OPT_FUNCTION_NAME = (short) 0x0002;
95     public static final short OPT_COMMAND_NAME = (short) 0x0004;
96     public static final short OPT_MACRO = (short) 0x0008;
97     public static final short OPT_COMPLEX = (short) 0x0010;
98     public static final short OPT_BUILTIN = (short) 0x0020;
99     public static final short OPT_BINDATA = (short) 0x1000;
100
101     
102     private short field_1_option_flag;
103     private byte field_2_keyboard_shortcut;
104     private byte field_3_length_name_text;
105     private short field_4_length_name_definition;
106     private short field_5_index_to_sheet; // unused: see field_6
107
private short field_6_equals_to_index_to_sheet;
108     private byte field_7_length_custom_menu;
109     private byte field_8_length_description_text;
110     private byte field_9_length_help_topic_text;
111     private byte field_10_length_status_bar_text;
112     private byte field_11_compressed_unicode_flag; // not documented
113
private byte field_12_builtIn_name;
114     private String JavaDoc field_12_name_text;
115     private Stack JavaDoc field_13_name_definition;
116     private byte[] field_13_raw_name_definition; // raw data
117
private String JavaDoc field_14_custom_menu_text;
118     private String JavaDoc field_15_description_text;
119     private String JavaDoc field_16_help_topic_text;
120     private String JavaDoc field_17_status_bar_text;
121
122
123     /** Creates new NameRecord */
124     public NameRecord() {
125         field_13_name_definition = new Stack JavaDoc();
126
127         field_12_name_text = new String JavaDoc();
128         field_14_custom_menu_text = new String JavaDoc();
129         field_15_description_text = new String JavaDoc();
130         field_16_help_topic_text = new String JavaDoc();
131         field_17_status_bar_text = new String JavaDoc();
132     }
133
134     /**
135      * Constructs a Name record and sets its fields appropriately.
136      *
137      * @param id id must be 0x18 or an exception will be throw upon validation
138      * @param size the size of the data area of the record
139      * @param data data of the record (should not contain sid/len)
140      */

141     public NameRecord(short id, short size, byte [] data) {
142         super(id, size, data);
143     }
144
145     /**
146      * Constructs a Name record and sets its fields appropriately.
147      *
148      * @param id id must be 0x18 or an exception will be throw upon validation
149      * @param size the size of the data area of the record
150      * @param data data of the record (should not contain sid/len)
151      * @param offset of the record's data
152      */

153     public NameRecord(short id, short size, byte [] data, int offset) {
154         super(id, size, data, offset);
155     }
156
157     /**
158      * Constructor to create a built-in named region
159      * @param builtin Built-in byte representation for the name record, use the public constants
160      * @param index
161      */

162     public NameRecord(byte builtin, short index)
163     {
164         this();
165         this.field_12_builtIn_name = builtin;
166         this.setOptionFlag((short)(this.getOptionFlag() | OPT_BUILTIN));
167         this.setNameTextLength((byte)1);
168         this.setEqualsToIndexToSheet(index); //the extern sheets are set through references
169

170         //clearing these because they are not used with builtin records
171
this.setCustomMenuLength((byte)0);
172         this.setDescriptionTextLength((byte)0);
173         this.setHelpTopicLength((byte)0);
174         this.setStatusBarLength((byte)0);
175
176         
177     }
178
179     /** sets the option flag for the named range
180      * @param flag option flag
181      */

182     public void setOptionFlag(short flag){
183         field_1_option_flag = flag;
184     }
185
186
187     /** sets the keyboard shortcut
188      * @param shortcut keyboard shortcut
189      */

190     public void setKeyboardShortcut(byte shortcut){
191         field_2_keyboard_shortcut = shortcut;
192     }
193
194     /** sets the name of the named range length
195      * @param length name length
196      */

197     public void setNameTextLength(byte length){
198         field_3_length_name_text = length;
199     }
200
201     /** sets the definition (reference - formula) length
202      * @param length defenition length
203      */

204     public void setDefinitionTextLength(short length){
205         field_4_length_name_definition = length;
206     }
207
208     /** sets the index number to the extern sheet (thats is what writen in documentation
209      * but as i saw , it works differently)
210      * @param index extern sheet index
211      */

212     public void setUnused(short index){
213         field_5_index_to_sheet = index;
214
215         // field_6_equals_to_index_to_sheet is equal to field_5_index_to_sheet
216
// field_6_equals_to_index_to_sheet = index;
217
}
218
219     public short getEqualsToIndexToSheet()
220     {
221         return field_6_equals_to_index_to_sheet;
222     }
223
224     /**
225      * Convenience method to retrieve the index the name refers to.
226      * @see #getEqualsToIndexToSheet()
227      * @return short
228      */

229     public short getIndexToSheet() {
230         return getEqualsToIndexToSheet();
231     }
232
233     /**
234      * @return function group
235      * @see FnGroupCountRecord
236      */

237     public byte getFnGroup() {
238         int masked = field_1_option_flag & 0x0fc0;
239         return (byte) (masked >> 4);
240     }
241
242     public void setEqualsToIndexToSheet(short value)
243     {
244         field_6_equals_to_index_to_sheet = value;
245     }
246
247
248     /** sets the custom menu length
249      * @param length custom menu length
250      */

251     public void setCustomMenuLength(byte length){
252         field_7_length_custom_menu = length;
253     }
254
255     /** sets the length of named range description
256      * @param length description length
257      */

258     public void setDescriptionTextLength(byte length){
259         field_8_length_description_text = length;
260     }
261
262     /** sets the help topic length
263      * @param length help topic length
264      */

265     public void setHelpTopicLength(byte length){
266         field_9_length_help_topic_text = length;
267     }
268
269     /** sets the length of the status bar text
270      * @param length status bar text length
271      */

272     public void setStatusBarLength(byte length){
273         field_10_length_status_bar_text = length;
274     }
275
276     /** sets the compressed unicode flag
277      * @param flag unicode flag
278      */

279     public void setCompressedUnicodeFlag(byte flag) {
280         field_11_compressed_unicode_flag = flag;
281     }
282
283     /** sets the name of the named range
284      * @param name named range name
285      */

286     public void setNameText(String JavaDoc name){
287         field_12_name_text = name;
288     }
289
290     // public void setNameDefintion(String definition){
291
// test = definition;
292
// }
293

294     /** sets the custom menu text
295      * @param text custom menu text
296      */

297     public void setCustomMenuText(String JavaDoc text){
298         field_14_custom_menu_text = text;
299     }
300
301     /** sets the description text
302      * @param text the description text
303      */

304     public void setDescriptionText(String JavaDoc text){
305         field_15_description_text = text;
306     }
307
308     /** sets the help topic text
309      * @param text help topix text
310      */

311     public void setHelpTopicText(String JavaDoc text){
312         field_16_help_topic_text = text;
313     }
314
315     /** sets the status bar text
316      * @param text status bar text
317      */

318     public void setStatusBarText(String JavaDoc text){
319         field_17_status_bar_text = text;
320     }
321
322     /** gets the option flag
323      * @return option flag
324      */

325     public short getOptionFlag(){
326         return field_1_option_flag;
327     }
328
329     /** returns the keyboard shortcut
330      * @return keyboard shortcut
331      */

332     public byte getKeyboardShortcut(){
333         return field_2_keyboard_shortcut ;
334     }
335
336     /** gets the name length
337      * @return name length
338      */

339     public byte getNameTextLength(){
340         return field_3_length_name_text;
341     }
342
343     /** get the definition length
344      * @return definition length
345      */

346     public short getDefinitionTextLength(){
347         return field_4_length_name_definition;
348     }
349
350     /** gets the index to extern sheet
351      * @return index to extern sheet
352      */

353     public short getUnused(){
354         return field_5_index_to_sheet;
355     }
356
357     /** gets the custom menu length
358      * @return custom menu length
359      */

360     public byte getCustomMenuLength(){
361         return field_7_length_custom_menu;
362     }
363
364     /** gets the description text length
365      * @return description text length
366      */

367     public byte getDescriptionTextLength(){
368         return field_8_length_description_text;
369     }
370
371     /** gets the help topic length
372      * @return help topic length
373      */

374     public byte getHelpTopicLength(){
375         return field_9_length_help_topic_text;
376     }
377
378     /** get the status bar text length
379      * @return satus bar length
380      */

381     public byte getStatusBarLength(){
382         return field_10_length_status_bar_text;
383     }
384
385     /** gets the name compressed Unicode flag
386      * @return compressed unicode flag
387      */

388     public byte getCompressedUnicodeFlag() {
389         return field_11_compressed_unicode_flag;
390     }
391
392     /**
393      * @return true if name is hidden
394      */

395     public boolean isHiddenName() {
396         return (field_1_option_flag & OPT_HIDDEN_NAME) != 0;
397     }
398
399     /**
400      * @return true if name is a function
401      */

402     public boolean isFunctionName() {
403         return (field_1_option_flag & OPT_FUNCTION_NAME) != 0;
404     }
405
406     /**
407      * @return true if name is a command
408      */

409     public boolean isCommandName() {
410         return (field_1_option_flag & OPT_COMMAND_NAME) != 0;
411     }
412
413     /**
414      * @return true if function macro or command macro
415      */

416     public boolean isMacro() {
417         return (field_1_option_flag & OPT_MACRO) != 0;
418     }
419
420     /**
421      * @return true if array formula or user defined
422      */

423     public boolean isComplexFunction() {
424         return (field_1_option_flag & OPT_COMPLEX) != 0;
425     }
426
427
428     /**Convenience Function to determine if the name is a built-in name
429      */

430     public boolean isBuiltInName()
431     {
432         return ((this.getOptionFlag() & OPT_BUILTIN) != 0);
433     }
434
435
436     /** gets the name
437      * @return name
438      */

439     public String JavaDoc getNameText(){
440
441         return this.isBuiltInName() ? this.translateBuiltInName(this.getBuiltInName()) : field_12_name_text;
442     }
443
444     /** Gets the Built In Name
445      * @return the built in Name
446      */

447     public byte getBuiltInName()
448     {
449         return this.field_12_builtIn_name;
450     }
451
452
453     /** gets the definition, reference (Formula)
454      * @return definition -- can be null if we cant parse ptgs
455      */

456     public List JavaDoc getNameDefinition() {
457         return field_13_name_definition;
458     }
459
460     public void setNameDefinition(Stack JavaDoc nameDefinition) {
461         field_13_name_definition = nameDefinition;
462     }
463
464     /** get the custom menu text
465      * @return custom menu text
466      */

467     public String JavaDoc getCustomMenuText(){
468         return field_14_custom_menu_text;
469     }
470
471     /** gets the description text
472      * @return description text
473      */

474     public String JavaDoc getDescriptionText(){
475         return field_15_description_text;
476     }
477
478     /** get the help topic text
479      * @return gelp topic text
480      */

481     public String JavaDoc getHelpTopicText(){
482         return field_16_help_topic_text;
483     }
484
485     /** gets the status bar text
486      * @return status bar text
487      */

488     public String JavaDoc getStatusBarText(){
489         return field_17_status_bar_text;
490     }
491
492     /**
493      * called by constructor, should throw runtime exception in the event of a
494      * record passed with a differing ID.
495      *
496      * @param id alleged id for this record
497      */

498     protected void validateSid(short id) {
499         if (id != sid) {
500             throw new RecordFormatException("NOT A valid Name RECORD");
501         }
502     }
503
504     /**
505      * called by the class that is responsible for writing this sucker.
506      * Subclasses should implement this so that their data is passed back in a
507      * byte array.
508      *
509      * @param offset to begin writing at
510      * @param data byte array containing instance data
511      * @return number of bytes written
512      */

513     public int serialize( int offset, byte[] data )
514     {
515         LittleEndian.putShort( data, 0 + offset, sid );
516         // size defined below
517
LittleEndian.putShort( data, 4 + offset, getOptionFlag() );
518         data[6 + offset] = getKeyboardShortcut();
519         data[7 + offset] = getNameTextLength();
520         LittleEndian.putShort( data, 8 + offset, getDefinitionTextLength() );
521         LittleEndian.putShort( data, 10 + offset, getUnused() );
522         LittleEndian.putShort( data, 12 + offset, getEqualsToIndexToSheet() );
523         data[14 + offset] = getCustomMenuLength();
524         data[15 + offset] = getDescriptionTextLength();
525         data[16 + offset] = getHelpTopicLength();
526         data[17 + offset] = getStatusBarLength();
527         data[18 + offset] = getCompressedUnicodeFlag();
528
529         /* temp: gjs
530         if (isBuiltInName())
531         {
532             LittleEndian.putShort( data, 2 + offset, (short) ( 16 + field_13_raw_name_definition.length ) );
533
534             data[19 + offset] = field_12_builtIn_name;
535             System.arraycopy( field_13_raw_name_definition, 0, data, 20 + offset, field_13_raw_name_definition.length );
536
537             return 20 + field_13_raw_name_definition.length;
538         }
539         else
540         { */

541             LittleEndian.putShort( data, 2 + offset, (short) ( 15 + getTextsLength() ) );
542             
543             int start_of_name_definition = 19 + field_3_length_name_text;
544
545             if (this.isBuiltInName()) {
546                 //can send the builtin name directly in
547
data [19 + offset] = this.getBuiltInName();
548             } else {
549                 StringUtil.putCompressedUnicode( getNameText(), data, 19 + offset );
550                 
551             }
552
553
554             if ( this.field_13_name_definition != null )
555             {
556                 serializePtgs( data, start_of_name_definition + offset );
557             }
558             else
559             {
560                 System.arraycopy( field_13_raw_name_definition, 0, data
561                     , start_of_name_definition + offset, field_13_raw_name_definition.length );
562             }
563
564
565             int start_of_custom_menu_text = start_of_name_definition + field_4_length_name_definition;
566             StringUtil.putCompressedUnicode( getCustomMenuText(), data, start_of_custom_menu_text + offset );
567
568             int start_of_description_text = start_of_custom_menu_text + field_7_length_custom_menu;
569             StringUtil.putCompressedUnicode( getDescriptionText(), data, start_of_description_text + offset );
570
571             int start_of_help_topic_text = start_of_description_text + field_8_length_description_text;
572             StringUtil.putCompressedUnicode( getHelpTopicText(), data, start_of_help_topic_text + offset );
573
574             int start_of_status_bar_text = start_of_help_topic_text + field_9_length_help_topic_text;
575             StringUtil.putCompressedUnicode( getStatusBarText(), data, start_of_status_bar_text + offset );
576
577             return getRecordSize();
578         /* } */
579     }
580
581     private void serializePtgs(byte [] data, int offset) {
582         int pos = offset;
583
584         for (int k = 0; k < field_13_name_definition.size(); k++) {
585             Ptg ptg = ( Ptg ) field_13_name_definition.get(k);
586
587             ptg.writeBytes(data, pos);
588             pos += ptg.getSize();
589         }
590     }
591
592
593     /** gets the length of all texts
594      * @return total length
595      */

596     public int getTextsLength(){
597         int result;
598
599         result = getNameTextLength() + getDefinitionTextLength() + getDescriptionTextLength() +
600         getHelpTopicLength() + getStatusBarLength();
601
602
603         return result;
604     }
605
606     /** returns the record size
607      */

608     public int getRecordSize(){
609         int result;
610
611         result = 19 + getTextsLength();
612
613         return result;
614     }
615
616     /** gets the extern sheet number
617      * @return extern sheet index
618      */

619     public short getExternSheetNumber(){
620         if (field_13_name_definition == null) return 0;
621         Ptg ptg = (Ptg) field_13_name_definition.peek();
622         short result = 0;
623
624         if (ptg.getClass() == Area3DPtg.class){
625             result = ((Area3DPtg) ptg).getExternSheetIndex();
626
627         } else if (ptg.getClass() == Ref3DPtg.class){
628             result = ((Ref3DPtg) ptg).getExternSheetIndex();
629         }
630
631         return result;
632     }
633
634     /** sets the extern sheet number
635      * @param externSheetNumber extern sheet number
636      */

637     public void setExternSheetNumber(short externSheetNumber){
638         Ptg ptg;
639
640         if (field_13_name_definition == null || field_13_name_definition.isEmpty()){
641             field_13_name_definition = new Stack JavaDoc();
642             ptg = createNewPtg();
643         } else {
644             ptg = (Ptg) field_13_name_definition.peek();
645         }
646
647         if (ptg.getClass() == Area3DPtg.class){
648             ((Area3DPtg) ptg).setExternSheetIndex(externSheetNumber);
649
650         } else if (ptg.getClass() == Ref3DPtg.class){
651             ((Ref3DPtg) ptg).setExternSheetIndex(externSheetNumber);
652         }
653
654     }
655
656     private Ptg createNewPtg(){
657         Ptg ptg = new Area3DPtg();
658         field_13_name_definition.push(ptg);
659
660         return ptg;
661     }
662
663     /** gets the reference , the area only (range)
664      * @return area reference
665      */

666     public String JavaDoc getAreaReference(Workbook book){
667         if (field_13_name_definition == null) return "#REF!";
668         Ptg ptg = (Ptg) field_13_name_definition.peek();
669         String JavaDoc result = "";
670
671         if (ptg.getClass() == Area3DPtg.class){
672             result = ptg.toFormulaString(book);
673
674         } else if (ptg.getClass() == Ref3DPtg.class){
675             result = ptg.toFormulaString(book);
676         }
677
678         return result;
679     }
680
681     /** sets the reference , the area only (range)
682      * @param ref area reference
683      */

684     public void setAreaReference(String JavaDoc ref){
685         //Trying to find if what ptg do we need
686
RangeAddress ra = new RangeAddress(ref);
687         Ptg oldPtg;
688         Ptg ptg;
689
690         if (field_13_name_definition==null ||field_13_name_definition.isEmpty()){
691             field_13_name_definition = new Stack JavaDoc();
692             oldPtg = createNewPtg();
693         } else {
694             //Trying to find extern sheet index
695
oldPtg = (Ptg) field_13_name_definition.pop();
696         }
697
698         short externSheetIndex = 0;
699
700         if (oldPtg.getClass() == Area3DPtg.class){
701             externSheetIndex = ((Area3DPtg) oldPtg).getExternSheetIndex();
702
703         } else if (oldPtg.getClass() == Ref3DPtg.class){
704             externSheetIndex = ((Ref3DPtg) oldPtg).getExternSheetIndex();
705         }
706
707         if (ra.hasRange()) {
708             ptg = new Area3DPtg();
709             ((Area3DPtg) ptg).setExternSheetIndex(externSheetIndex);
710             ((Area3DPtg) ptg).setArea(ref);
711             this.setDefinitionTextLength((short)ptg.getSize());
712         } else {
713             ptg = new Ref3DPtg();
714             ((Ref3DPtg) ptg).setExternSheetIndex(externSheetIndex);
715             ((Ref3DPtg) ptg).setArea(ref);
716             this.setDefinitionTextLength((short)ptg.getSize());
717         }
718
719         field_13_name_definition.push(ptg);
720
721     }
722
723     /**
724      * called by the constructor, should set class level fields. Should throw
725      * runtime exception for bad/icomplete data.
726      *
727      * @param data raw data
728      * @param size size of data
729      * @param offset of the record's data (provided a big array of the file)
730      */

731     protected void fillFields(byte[] data, short size, int offset) {
732         field_1_option_flag = LittleEndian.getShort(data, 0 + offset);
733         field_2_keyboard_shortcut = data [2 + offset];
734         field_3_length_name_text = data [3 + offset];
735         field_4_length_name_definition = LittleEndian.getShort(data, 4 + offset);
736         field_5_index_to_sheet = LittleEndian.getShort(data, 6 + offset);
737         field_6_equals_to_index_to_sheet= LittleEndian.getShort(data, 8 + offset);
738         field_7_length_custom_menu = data [10 + offset];
739         field_8_length_description_text = data [11 + offset];
740         field_9_length_help_topic_text = data [12 + offset];
741         field_10_length_status_bar_text = data [13 + offset];
742         
743
744         /*
745         temp: gjs
746         if (isBuiltInName()) {
747             // DEBUG
748             // System.out.println( "Built-in name" );
749
750             field_11_compressed_unicode_flag = data[ 14 + offset ];
751             field_12_builtIn_name = data[ 15 + offset ];
752
753             if ( (field_12_builtIn_name & (short)0x07) != 0 ) {
754                 field_12_name_text = "Print_Titles";
755
756                 // DEBUG
757                 // System.out.println( field_12_name_text );
758
759                 field_13_raw_name_definition = new byte[ field_4_length_name_definition ];
760                 System.arraycopy( data, 16 + offset, field_13_raw_name_definition, 0, field_13_raw_name_definition.length );
761
762                 // DEBUG
763                 // System.out.println( HexDump.toHex( field_13_raw_name_definition ) );
764             }
765         }
766         else { */

767     
768             field_11_compressed_unicode_flag= data [14 + offset];
769             
770             
771             //store the name in byte form if it's a builtin name
772
if (this.isBuiltInName()) {
773                 field_12_builtIn_name = data[ 15 + offset ];
774             }
775             
776             field_12_name_text = StringUtil.getFromCompressedUnicode(data, 15 + offset,
777             LittleEndian.ubyteToInt(field_3_length_name_text));
778         
779             int start_of_name_definition = 15 + field_3_length_name_text;
780             field_13_name_definition = getParsedExpressionTokens(data, field_4_length_name_definition,
781             offset, start_of_name_definition);
782     
783             int start_of_custom_menu_text = start_of_name_definition + field_4_length_name_definition;
784             field_14_custom_menu_text = StringUtil.getFromCompressedUnicode(data, start_of_custom_menu_text + offset,
785             LittleEndian.ubyteToInt(field_7_length_custom_menu));
786     
787             int start_of_description_text = start_of_custom_menu_text + field_7_length_custom_menu;;
788             field_15_description_text = StringUtil.getFromCompressedUnicode(data, start_of_description_text + offset,
789             LittleEndian.ubyteToInt(field_8_length_description_text));
790     
791             int start_of_help_topic_text = start_of_description_text + field_8_length_description_text;
792             field_16_help_topic_text = StringUtil.getFromCompressedUnicode(data, start_of_help_topic_text + offset,
793             LittleEndian.ubyteToInt(field_9_length_help_topic_text));
794     
795             int start_of_status_bar_text = start_of_help_topic_text + field_9_length_help_topic_text;
796             field_17_status_bar_text = StringUtil.getFromCompressedUnicode(data, start_of_status_bar_text + offset,
797             LittleEndian.ubyteToInt(field_10_length_status_bar_text));
798         /*} */
799     }
800
801     private Stack JavaDoc getParsedExpressionTokens(byte [] data, short size,
802         int offset, int start_of_expression) {
803         Stack JavaDoc stack = new Stack JavaDoc();
804         int pos = start_of_expression + offset;
805         int sizeCounter = 0;
806         try {
807             while (sizeCounter < size) {
808                 Ptg ptg = Ptg.createPtg(data, pos);
809
810                 pos += ptg.getSize();
811                 sizeCounter += ptg.getSize();
812                 stack.push(ptg);
813                 field_13_raw_name_definition=new byte[size];
814                 System.arraycopy(data,offset,field_13_raw_name_definition,0,size);
815             }
816         } catch (java.lang.UnsupportedOperationException JavaDoc uoe) {
817             System.err.println("[WARNING] Unknown Ptg "
818                     + uoe.getMessage() );
819             field_13_raw_name_definition=new byte[size];
820             System.arraycopy(data,offset,field_13_raw_name_definition,0,size);
821             return null;
822         }
823         return stack;
824     }
825
826
827     /**
828      * return the non static version of the id for this record.
829      */

830     public short getSid() {
831         return this.sid;
832     }
833     /*
834       20 00
835       00
836       01
837       1A 00 // sz = 0x1A = 26
838       00 00
839       01 00
840       00
841       00
842       00
843       00
844       00 // unicode flag
845       07 // name
846       
847       29 17 00 3B 00 00 00 00 FF FF 00 00 02 00 3B 00 //{ 26
848       00 07 00 07 00 00 00 FF 00 10 // }
849       
850       
851       
852       20 00
853       00
854       01
855       0B 00 // sz = 0xB = 11
856       00 00
857       01 00
858       00
859       00
860       00
861       00
862       00 // unicode flag
863       07 // name
864       
865       3B 00 00 07 00 07 00 00 00 FF 00 // { 11 }
866   */

867     /*
868       18, 00,
869       1B, 00,
870       
871       20, 00,
872       00,
873       01,
874       0B, 00,
875       00,
876       00,
877       00,
878       00,
879       00,
880       07,
881       3B 00 00 07 00 07 00 00 00 FF 00 ]
882      */

883
884     /**
885      * @see Object#toString()
886      */

887     public String JavaDoc toString() {
888         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
889
890         buffer.append("[NAME]\n");
891         buffer.append(" .option flags = ").append( HexDump.toHex( field_1_option_flag ) )
892             .append("\n");
893         buffer.append(" .keyboard shortcut = ").append( HexDump.toHex( field_2_keyboard_shortcut ) )
894             .append("\n");
895         buffer.append(" .length of the name = ").append( field_3_length_name_text )
896             .append("\n");
897         buffer.append(" .size of the formula data = ").append( field_4_length_name_definition )
898             .append("\n");
899         buffer.append(" .unused = ").append( field_5_index_to_sheet )
900             .append("\n");
901         buffer.append(" .index to sheet (1-based, 0=Global) = ").append( field_6_equals_to_index_to_sheet )
902             .append("\n");
903         buffer.append(" .Length of menu text (character count) = ").append( field_7_length_custom_menu )
904             .append("\n");
905         buffer.append(" .Length of description text (character count) = ").append( field_8_length_description_text )
906             .append("\n");
907         buffer.append(" .Length of help topic text (character count) = ").append( field_9_length_help_topic_text )
908             .append("\n");
909         buffer.append(" .Length of status bar text (character count) = ").append( field_10_length_status_bar_text )
910             .append("\n");
911         buffer.append(" .Name (Unicode flag) = ").append( field_11_compressed_unicode_flag )
912             .append("\n");
913         buffer.append(" .Name (Unicode text) = ").append( getNameText() )
914             .append("\n");
915         buffer.append(" .Formula data (RPN token array without size field) = ").append( HexDump.toHex(
916                        ((field_13_raw_name_definition != null) ? field_13_raw_name_definition : new byte[0] ) ) )
917             .append("\n");
918             
919         buffer.append(" .Menu text (Unicode string without length field) = ").append( field_14_custom_menu_text )
920             .append("\n");
921         buffer.append(" .Description text (Unicode string without length field) = ").append( field_15_description_text )
922             .append("\n");
923         buffer.append(" .Help topic text (Unicode string without length field) = ").append( field_16_help_topic_text )
924             .append("\n");
925         buffer.append(" .Status bar text (Unicode string without length field) = ").append( field_17_status_bar_text )
926             .append("\n");
927         if (field_13_raw_name_definition != null)
928             buffer.append(org.apache.poi.util.HexDump.dump(this.field_13_raw_name_definition,0,0));
929         buffer.append("[/NAME]\n");
930         
931         return buffer.toString();
932     }
933
934     /**Creates a human readable name for built in types
935      * @return Unknown if the built-in name cannot be translated
936      */

937     protected String JavaDoc translateBuiltInName(byte name)
938     {
939         switch (name)
940         {
941             case NameRecord.BUILTIN_AUTO_ACTIVATE : return "Auto_Activate";
942             case NameRecord.BUILTIN_AUTO_CLOSE : return "Auto_Close";
943             case NameRecord.BUILTIN_AUTO_DEACTIVATE : return "Auto_Deactivate";
944             case NameRecord.BUILTIN_AUTO_OPEN : return "Auto_Open";
945             case NameRecord.BUILTIN_CONSOLIDATE_AREA : return "Consolidate_Area";
946             case NameRecord.BUILTIN_CRITERIA : return "Criteria";
947             case NameRecord.BUILTIN_DATABASE : return "Database";
948             case NameRecord.BUILTIN_DATA_FORM : return "Data_Form";
949             case NameRecord.BUILTIN_PRINT_AREA : return "Print_Area";
950             case NameRecord.BUILTIN_PRINT_TITLE : return "Print_Titles";
951             case NameRecord.BUILTIN_RECORDER : return "Recorder";
952             case NameRecord.BUILTIN_SHEET_TITLE : return "Sheet_Title";
953             
954         }
955         
956         return "Unknown";
957     }
958     
959
960 }
961
Popular Tags