Source Code Cross Referenced for NameRecord.java in  » Collaboration » poi-3.0.2-beta2 » org » apache » poi » hssf » record » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Collaboration » poi 3.0.2 beta2 » org.apache.poi.hssf.record 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* ====================================================================
002:           Licensed to the Apache Software Foundation (ASF) under one or more
003:           contributor license agreements.  See the NOTICE file distributed with
004:           this work for additional information regarding copyright ownership.
005:           The ASF licenses this file to You under the Apache License, Version 2.0
006:           (the "License"); you may not use this file except in compliance with
007:           the License.  You may obtain a copy of the License at
008:
009:               http://www.apache.org/licenses/LICENSE-2.0
010:
011:           Unless required by applicable law or agreed to in writing, software
012:           distributed under the License is distributed on an "AS IS" BASIS,
013:           WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:           See the License for the specific language governing permissions and
015:           limitations under the License.
016:        ==================================================================== */
017:
018:        package org.apache.poi.hssf.record;
019:
020:        import java.util.List;
021:        import java.util.Stack;
022:
023:        import org.apache.poi.hssf.model.Workbook;
024:        import org.apache.poi.hssf.record.formula.Area3DPtg;
025:        import org.apache.poi.hssf.record.formula.DeletedArea3DPtg;
026:        import org.apache.poi.hssf.record.formula.DeletedRef3DPtg;
027:        import org.apache.poi.hssf.record.formula.Ptg;
028:        import org.apache.poi.hssf.record.formula.Ref3DPtg;
029:        import org.apache.poi.hssf.util.RangeAddress;
030:        import org.apache.poi.util.HexDump;
031:        import org.apache.poi.util.LittleEndian;
032:        import org.apache.poi.util.StringUtil;
033:
034:        /**
035:         * Title:        Name Record (aka Named Range) <P>
036:         * Description:  Defines a named range within a workbook. <P>
037:         * REFERENCE:  <P>
038:         * @author Libin Roman (Vista Portal LDT. Developer)
039:         * @author  Sergei Kozello (sergeikozello at mail.ru)
040:         * @author Glen Stampoultzis (glens at apache.org)
041:         * @version 1.0-pre
042:         */
043:
044:        public class NameRecord extends Record {
045:            /**
046:             */
047:            public final static short sid = 0x18; //Docs says that it is 0x218
048:
049:            /**Included for completeness sake, not implemented
050:             */
051:            public final static byte BUILTIN_CONSOLIDATE_AREA = (byte) 1;
052:
053:            /**Included for completeness sake, not implemented
054:             */
055:            public final static byte BUILTIN_AUTO_OPEN = (byte) 2;
056:
057:            /**Included for completeness sake, not implemented
058:             */
059:            public final static byte BUILTIN_AUTO_CLOSE = (byte) 3;
060:
061:            /**Included for completeness sake, not implemented
062:             */
063:            public final static byte BUILTIN_DATABASE = (byte) 4;
064:
065:            /**Included for completeness sake, not implemented
066:             */
067:            public final static byte BUILTIN_CRITERIA = (byte) 5;
068:
069:            public final static byte BUILTIN_PRINT_AREA = (byte) 6;
070:            public final static byte BUILTIN_PRINT_TITLE = (byte) 7;
071:
072:            /**Included for completeness sake, not implemented
073:             */
074:            public final static byte BUILTIN_RECORDER = (byte) 8;
075:
076:            /**Included for completeness sake, not implemented
077:             */
078:            public final static byte BUILTIN_DATA_FORM = (byte) 9;
079:
080:            /**Included for completeness sake, not implemented
081:             */
082:
083:            public final static byte BUILTIN_AUTO_ACTIVATE = (byte) 10;
084:
085:            /**Included for completeness sake, not implemented
086:             */
087:
088:            public final static byte BUILTIN_AUTO_DEACTIVATE = (byte) 11;
089:
090:            /**Included for completeness sake, not implemented
091:             */
092:            public final static byte BUILTIN_SHEET_TITLE = (byte) 12;
093:
094:            public static final short OPT_HIDDEN_NAME = (short) 0x0001;
095:            public static final short OPT_FUNCTION_NAME = (short) 0x0002;
096:            public static final short OPT_COMMAND_NAME = (short) 0x0004;
097:            public static final short OPT_MACRO = (short) 0x0008;
098:            public static final short OPT_COMPLEX = (short) 0x0010;
099:            public static final short OPT_BUILTIN = (short) 0x0020;
100:            public static final short OPT_BINDATA = (short) 0x1000;
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 field_12_name_text;
115:            private Stack field_13_name_definition;
116:            private String field_14_custom_menu_text;
117:            private String field_15_description_text;
118:            private String field_16_help_topic_text;
119:            private String field_17_status_bar_text;
120:
121:            /** Creates new NameRecord */
122:            public NameRecord() {
123:                field_13_name_definition = new Stack();
124:
125:                field_12_name_text = new String();
126:                field_14_custom_menu_text = new String();
127:                field_15_description_text = new String();
128:                field_16_help_topic_text = new String();
129:                field_17_status_bar_text = new String();
130:            }
131:
132:            /**
133:             * Constructs a Name record and sets its fields appropriately.
134:             *
135:             * @param in the RecordInputstream to read the record from
136:             */
137:            public NameRecord(RecordInputStream in) {
138:                super (in);
139:            }
140:
141:            /**
142:             * Constructor to create a built-in named region
143:             * @param builtin Built-in byte representation for the name record, use the public constants
144:             * @param index 
145:             */
146:            public NameRecord(byte builtin, short index) {
147:                this ();
148:                this .field_12_builtIn_name = builtin;
149:                this 
150:                        .setOptionFlag((short) (this .getOptionFlag() | OPT_BUILTIN));
151:                this .setNameTextLength((byte) 1);
152:                this .setEqualsToIndexToSheet(index); //the extern sheets are set through references
153:
154:                //clearing these because they are not used with builtin records
155:                this .setCustomMenuLength((byte) 0);
156:                this .setDescriptionTextLength((byte) 0);
157:                this .setHelpTopicLength((byte) 0);
158:                this .setStatusBarLength((byte) 0);
159:
160:            }
161:
162:            /** sets the option flag for the named range
163:             * @param flag option flag
164:             */
165:            public void setOptionFlag(short flag) {
166:                field_1_option_flag = flag;
167:            }
168:
169:            /** sets the keyboard shortcut
170:             * @param shortcut keyboard shortcut
171:             */
172:            public void setKeyboardShortcut(byte shortcut) {
173:                field_2_keyboard_shortcut = shortcut;
174:            }
175:
176:            /** sets the name of the named range length
177:             * @param length name length
178:             */
179:            public void setNameTextLength(byte length) {
180:                field_3_length_name_text = length;
181:            }
182:
183:            /** sets the definition (reference - formula) length
184:             * @param length defenition length
185:             */
186:            public void setDefinitionTextLength(short length) {
187:                field_4_length_name_definition = length;
188:            }
189:
190:            /** sets the index number to the extern sheet (thats is what writen in documentation
191:             *  but as i saw , it works differently)
192:             * @param index extern sheet index
193:             */
194:            public void setUnused(short index) {
195:                field_5_index_to_sheet = index;
196:
197:                // field_6_equals_to_index_to_sheet is equal to field_5_index_to_sheet
198:                //        field_6_equals_to_index_to_sheet = index;
199:            }
200:
201:            public short getEqualsToIndexToSheet() {
202:                return field_6_equals_to_index_to_sheet;
203:            }
204:
205:            /**
206:             * Convenience method to retrieve the index the name refers to.
207:             * @see #getEqualsToIndexToSheet()
208:             * @return short
209:             */
210:            public short getIndexToSheet() {
211:                return getEqualsToIndexToSheet();
212:            }
213:
214:            /**
215:             * @return function group
216:             * @see FnGroupCountRecord
217:             */
218:            public byte getFnGroup() {
219:                int masked = field_1_option_flag & 0x0fc0;
220:                return (byte) (masked >> 4);
221:            }
222:
223:            public void setEqualsToIndexToSheet(short value) {
224:                field_6_equals_to_index_to_sheet = value;
225:            }
226:
227:            /** sets the custom menu length
228:             * @param length custom menu length
229:             */
230:            public void setCustomMenuLength(byte length) {
231:                field_7_length_custom_menu = length;
232:            }
233:
234:            /** sets the length of named range description
235:             * @param length description length
236:             */
237:            public void setDescriptionTextLength(byte length) {
238:                field_8_length_description_text = length;
239:            }
240:
241:            /** sets the help topic length
242:             * @param length help topic length
243:             */
244:            public void setHelpTopicLength(byte length) {
245:                field_9_length_help_topic_text = length;
246:            }
247:
248:            /** sets the length of the status bar text
249:             * @param length status bar text length
250:             */
251:            public void setStatusBarLength(byte length) {
252:                field_10_length_status_bar_text = length;
253:            }
254:
255:            /** sets the compressed unicode flag
256:             * @param flag unicode flag
257:             */
258:            public void setCompressedUnicodeFlag(byte flag) {
259:                field_11_compressed_unicode_flag = flag;
260:            }
261:
262:            /** sets the name of the named range
263:             * @param name named range name
264:             */
265:            public void setNameText(String name) {
266:                field_12_name_text = name;
267:            }
268:
269:            //    public void setNameDefintion(String definition){
270:            //        test = definition;
271:            //    }
272:
273:            /** sets the custom menu text
274:             * @param text custom menu text
275:             */
276:            public void setCustomMenuText(String text) {
277:                field_14_custom_menu_text = text;
278:            }
279:
280:            /** sets the description text
281:             * @param text the description text
282:             */
283:            public void setDescriptionText(String text) {
284:                field_15_description_text = text;
285:            }
286:
287:            /** sets the help topic text
288:             * @param text help topix text
289:             */
290:            public void setHelpTopicText(String text) {
291:                field_16_help_topic_text = text;
292:            }
293:
294:            /** sets the status bar text
295:             * @param text status bar text
296:             */
297:            public void setStatusBarText(String text) {
298:                field_17_status_bar_text = text;
299:            }
300:
301:            /** gets the option flag
302:             * @return option flag
303:             */
304:            public short getOptionFlag() {
305:                return field_1_option_flag;
306:            }
307:
308:            /** returns the keyboard shortcut
309:             * @return keyboard shortcut
310:             */
311:            public byte getKeyboardShortcut() {
312:                return field_2_keyboard_shortcut;
313:            }
314:
315:            /** gets the name length
316:             * @return name length
317:             */
318:            public byte getNameTextLength() {
319:                return field_3_length_name_text;
320:            }
321:
322:            /** get the definition length
323:             * @return definition length
324:             */
325:            public short getDefinitionLength() {
326:                return field_4_length_name_definition;
327:            }
328:
329:            /** gets the index to extern sheet
330:             * @return index to extern sheet
331:             */
332:            public short getUnused() {
333:                return field_5_index_to_sheet;
334:            }
335:
336:            /** gets the custom menu length
337:             * @return custom menu length
338:             */
339:            public byte getCustomMenuLength() {
340:                return field_7_length_custom_menu;
341:            }
342:
343:            /** gets the description text length
344:             * @return description text length
345:             */
346:            public byte getDescriptionTextLength() {
347:                return field_8_length_description_text;
348:            }
349:
350:            /** gets the help topic length
351:             * @return help topic length
352:             */
353:            public byte getHelpTopicLength() {
354:                return field_9_length_help_topic_text;
355:            }
356:
357:            /** get the status bar text length
358:             * @return satus bar length
359:             */
360:            public byte getStatusBarLength() {
361:                return field_10_length_status_bar_text;
362:            }
363:
364:            /** gets the name compressed Unicode flag
365:             * @return compressed unicode flag
366:             */
367:            public byte getCompressedUnicodeFlag() {
368:                return field_11_compressed_unicode_flag;
369:            }
370:
371:            /**
372:             * @return true if name is hidden
373:             */
374:            public boolean isHiddenName() {
375:                return (field_1_option_flag & OPT_HIDDEN_NAME) != 0;
376:            }
377:
378:            /**
379:             * @return true if name is a function
380:             */
381:            public boolean isFunctionName() {
382:                return (field_1_option_flag & OPT_FUNCTION_NAME) != 0;
383:            }
384:
385:            /**
386:             * @return true if name is a command
387:             */
388:            public boolean isCommandName() {
389:                return (field_1_option_flag & OPT_COMMAND_NAME) != 0;
390:            }
391:
392:            /**
393:             * @return true if function macro or command macro
394:             */
395:            public boolean isMacro() {
396:                return (field_1_option_flag & OPT_MACRO) != 0;
397:            }
398:
399:            /**
400:             * @return true if array formula or user defined
401:             */
402:            public boolean isComplexFunction() {
403:                return (field_1_option_flag & OPT_COMPLEX) != 0;
404:            }
405:
406:            /**Convenience Function to determine if the name is a built-in name
407:             */
408:            public boolean isBuiltInName() {
409:                return ((this .getOptionFlag() & OPT_BUILTIN) != 0);
410:            }
411:
412:            /** gets the name
413:             * @return name
414:             */
415:            public String getNameText() {
416:
417:                return this .isBuiltInName() ? this .translateBuiltInName(this 
418:                        .getBuiltInName()) : field_12_name_text;
419:            }
420:
421:            /** Gets the Built In Name
422:             * @return the built in Name
423:             */
424:            public byte getBuiltInName() {
425:                return this .field_12_builtIn_name;
426:            }
427:
428:            /** gets the definition, reference (Formula)
429:             * @return definition -- can be null if we cant parse ptgs
430:             */
431:            public List getNameDefinition() {
432:                return field_13_name_definition;
433:            }
434:
435:            public void setNameDefinition(Stack nameDefinition) {
436:                field_13_name_definition = nameDefinition;
437:            }
438:
439:            /** get the custom menu text
440:             * @return custom menu text
441:             */
442:            public String getCustomMenuText() {
443:                return field_14_custom_menu_text;
444:            }
445:
446:            /** gets the description text
447:             * @return description text
448:             */
449:            public String getDescriptionText() {
450:                return field_15_description_text;
451:            }
452:
453:            /** get the help topic text
454:             * @return gelp topic text
455:             */
456:            public String getHelpTopicText() {
457:                return field_16_help_topic_text;
458:            }
459:
460:            /** gets the status bar text
461:             * @return status bar text
462:             */
463:            public String getStatusBarText() {
464:                return field_17_status_bar_text;
465:            }
466:
467:            /**
468:             * called by constructor, should throw runtime exception in the event of a
469:             * record passed with a differing ID.
470:             *
471:             * @param id alleged id for this record
472:             */
473:            protected void validateSid(short id) {
474:                if (id != sid) {
475:                    throw new RecordFormatException("NOT A valid Name RECORD");
476:                }
477:            }
478:
479:            /**
480:             * called by the class that is responsible for writing this sucker.
481:             * Subclasses should implement this so that their data is passed back in a
482:             * @param offset to begin writing at
483:             * @param data byte array containing instance data
484:             * @return number of bytes written
485:             */
486:            public int serialize(int offset, byte[] data) {
487:                LittleEndian.putShort(data, 0 + offset, sid);
488:                short size = (short) (15 + getTextsLength() + getNameDefinitionSize());
489:                LittleEndian.putShort(data, 2 + offset, size);
490:                // size defined below
491:                LittleEndian.putShort(data, 4 + offset, getOptionFlag());
492:                data[6 + offset] = getKeyboardShortcut();
493:                data[7 + offset] = getNameTextLength();
494:                LittleEndian.putShort(data, 8 + offset, getDefinitionLength());
495:                LittleEndian.putShort(data, 10 + offset, getUnused());
496:                LittleEndian.putShort(data, 12 + offset,
497:                        getEqualsToIndexToSheet());
498:                data[14 + offset] = getCustomMenuLength();
499:                data[15 + offset] = getDescriptionTextLength();
500:                data[16 + offset] = getHelpTopicLength();
501:                data[17 + offset] = getStatusBarLength();
502:                data[18 + offset] = getCompressedUnicodeFlag();
503:
504:                /* temp: gjs
505:                if (isBuiltInName())
506:                {
507:                    LittleEndian.putShort( data, 2 + offset, (short) ( 16 + field_13_raw_name_definition.length ) );
508:
509:                    data[19 + offset] = field_12_builtIn_name;
510:                    System.arraycopy( field_13_raw_name_definition, 0, data, 20 + offset, field_13_raw_name_definition.length );
511:
512:                    return 20 + field_13_raw_name_definition.length;
513:                }
514:                else
515:                {     */
516:
517:                int start_of_name_definition = 19 + field_3_length_name_text;
518:
519:                if (this .isBuiltInName()) {
520:                    //can send the builtin name directly in
521:                    data[19 + offset] = this .getBuiltInName();
522:                } else {
523:                    StringUtil.putCompressedUnicode(getNameText(), data,
524:                            19 + offset);
525:
526:                }
527:
528:                Ptg.serializePtgStack(field_13_name_definition, data,
529:                        start_of_name_definition + offset);
530:
531:                int start_of_custom_menu_text = start_of_name_definition
532:                        + field_4_length_name_definition;
533:                StringUtil.putCompressedUnicode(getCustomMenuText(), data,
534:                        start_of_custom_menu_text + offset);
535:
536:                int start_of_description_text = start_of_custom_menu_text
537:                        + field_7_length_custom_menu;
538:                StringUtil.putCompressedUnicode(getDescriptionText(), data,
539:                        start_of_description_text + offset);
540:
541:                int start_of_help_topic_text = start_of_description_text
542:                        + field_8_length_description_text;
543:                StringUtil.putCompressedUnicode(getHelpTopicText(), data,
544:                        start_of_help_topic_text + offset);
545:
546:                int start_of_status_bar_text = start_of_help_topic_text
547:                        + field_9_length_help_topic_text;
548:                StringUtil.putCompressedUnicode(getStatusBarText(), data,
549:                        start_of_status_bar_text + offset);
550:
551:                return getRecordSize();
552:                /* } */
553:            }
554:
555:            /** gets the length of all texts
556:             * @return total length
557:             */
558:            public int getTextsLength() {
559:                int result;
560:
561:                result = getNameTextLength() + getDescriptionTextLength()
562:                        + getHelpTopicLength() + getStatusBarLength();
563:
564:                return result;
565:            }
566:
567:            private int getNameDefinitionSize() {
568:                int result = 0;
569:                List list = field_13_name_definition;
570:
571:                for (int k = 0; k < list.size(); k++) {
572:                    Ptg ptg = (Ptg) list.get(k);
573:
574:                    result += ptg.getSize();
575:                }
576:                return result;
577:            }
578:
579:            /** returns the record size
580:             */
581:            public int getRecordSize() {
582:                int result;
583:
584:                result = 19 + getTextsLength() + getNameDefinitionSize();
585:
586:                return result;
587:            }
588:
589:            /** gets the extern sheet number
590:             * @return extern sheet index
591:             */
592:            public short getExternSheetNumber() {
593:                if (field_13_name_definition == null
594:                        || field_13_name_definition.isEmpty())
595:                    return 0;
596:                Ptg ptg = (Ptg) field_13_name_definition.peek();
597:                short result = 0;
598:
599:                if (ptg.getClass() == Area3DPtg.class) {
600:                    result = ((Area3DPtg) ptg).getExternSheetIndex();
601:
602:                } else if (ptg.getClass() == Ref3DPtg.class) {
603:                    result = ((Ref3DPtg) ptg).getExternSheetIndex();
604:                }
605:
606:                return result;
607:            }
608:
609:            /** sets the extern sheet number
610:             * @param externSheetNumber extern sheet number
611:             */
612:            public void setExternSheetNumber(short externSheetNumber) {
613:                Ptg ptg;
614:
615:                if (field_13_name_definition == null
616:                        || field_13_name_definition.isEmpty()) {
617:                    field_13_name_definition = new Stack();
618:                    ptg = createNewPtg();
619:                } else {
620:                    ptg = (Ptg) field_13_name_definition.peek();
621:                }
622:
623:                if (ptg.getClass() == Area3DPtg.class) {
624:                    ((Area3DPtg) ptg).setExternSheetIndex(externSheetNumber);
625:
626:                } else if (ptg.getClass() == Ref3DPtg.class) {
627:                    ((Ref3DPtg) ptg).setExternSheetIndex(externSheetNumber);
628:                }
629:
630:            }
631:
632:            private Ptg createNewPtg() {
633:                Ptg ptg = new Area3DPtg();
634:                field_13_name_definition.push(ptg);
635:
636:                return ptg;
637:            }
638:
639:            /** gets the reference , the area only (range)
640:             * @return area reference
641:             */
642:            public String getAreaReference(Workbook book) {
643:                if (field_13_name_definition == null
644:                        || field_13_name_definition.isEmpty())
645:                    return "Error";
646:                Ptg ptg = (Ptg) field_13_name_definition.peek();
647:                String result = "";
648:
649:                if (ptg.getClass() == Area3DPtg.class) {
650:                    result = ptg.toFormulaString(book);
651:
652:                } else if (ptg.getClass() == Ref3DPtg.class) {
653:                    result = ptg.toFormulaString(book);
654:                } else if (ptg.getClass() == DeletedArea3DPtg.class
655:                        || ptg.getClass() == DeletedRef3DPtg.class) {
656:                    result = "#REF!";
657:                }
658:
659:                return result;
660:            }
661:
662:            /** sets the reference , the area only (range)
663:             * @param ref area reference
664:             */
665:            public void setAreaReference(String ref) {
666:                //Trying to find if what ptg do we need
667:                RangeAddress ra = new RangeAddress(ref);
668:                Ptg oldPtg;
669:                Ptg ptg;
670:
671:                if (field_13_name_definition == null
672:                        || field_13_name_definition.isEmpty()) {
673:                    field_13_name_definition = new Stack();
674:                    oldPtg = createNewPtg();
675:                } else {
676:                    //Trying to find extern sheet index
677:                    oldPtg = (Ptg) field_13_name_definition.pop();
678:                }
679:
680:                short externSheetIndex = 0;
681:
682:                if (oldPtg.getClass() == Area3DPtg.class) {
683:                    externSheetIndex = ((Area3DPtg) oldPtg)
684:                            .getExternSheetIndex();
685:
686:                } else if (oldPtg.getClass() == Ref3DPtg.class) {
687:                    externSheetIndex = ((Ref3DPtg) oldPtg)
688:                            .getExternSheetIndex();
689:                }
690:
691:                if (ra.hasRange()) {
692:                    ptg = new Area3DPtg();
693:                    ((Area3DPtg) ptg).setExternSheetIndex(externSheetIndex);
694:                    ((Area3DPtg) ptg).setArea(ref);
695:                    this .setDefinitionTextLength((short) ptg.getSize());
696:                } else {
697:                    ptg = new Ref3DPtg();
698:                    ((Ref3DPtg) ptg).setExternSheetIndex(externSheetIndex);
699:                    ((Ref3DPtg) ptg).setArea(ref);
700:                    this .setDefinitionTextLength((short) ptg.getSize());
701:                }
702:
703:                field_13_name_definition.push(ptg);
704:
705:            }
706:
707:            /**
708:             * called by the constructor, should set class level fields.  Should throw
709:             * runtime exception for bad/icomplete data.
710:             *
711:             * @param in the RecordInputstream to read the record from
712:             */
713:            protected void fillFields(RecordInputStream in) {
714:                field_1_option_flag = in.readShort();
715:                field_2_keyboard_shortcut = in.readByte();
716:                field_3_length_name_text = in.readByte();
717:                field_4_length_name_definition = in.readShort();
718:                field_5_index_to_sheet = in.readShort();
719:                field_6_equals_to_index_to_sheet = in.readShort();
720:                field_7_length_custom_menu = in.readByte();
721:                field_8_length_description_text = in.readByte();
722:                field_9_length_help_topic_text = in.readByte();
723:                field_10_length_status_bar_text = in.readByte();
724:
725:                //store the name in byte form if it's a builtin name
726:                field_11_compressed_unicode_flag = in.readByte();
727:                if (this .isBuiltInName()) {
728:                    field_12_builtIn_name = in.readByte();
729:                } else {
730:                    if (field_11_compressed_unicode_flag == 1) {
731:                        field_12_name_text = in
732:                                .readUnicodeLEString(field_3_length_name_text);
733:                    } else {
734:                        field_12_name_text = in
735:                                .readCompressedUnicode(field_3_length_name_text);
736:                    }
737:                }
738:
739:                field_13_name_definition = Ptg.createParsedExpressionTokens(
740:                        field_4_length_name_definition, in);
741:
742:                //Who says that this can only ever be compressed unicode???
743:                field_14_custom_menu_text = in
744:                        .readCompressedUnicode(LittleEndian
745:                                .ubyteToInt(field_7_length_custom_menu));
746:
747:                field_15_description_text = in
748:                        .readCompressedUnicode(LittleEndian
749:                                .ubyteToInt(field_8_length_description_text));
750:
751:                field_16_help_topic_text = in
752:                        .readCompressedUnicode(LittleEndian
753:                                .ubyteToInt(field_9_length_help_topic_text));
754:
755:                field_17_status_bar_text = in
756:                        .readCompressedUnicode(LittleEndian
757:                                .ubyteToInt(field_10_length_status_bar_text));
758:                /*} */
759:            }
760:
761:            /**
762:             * return the non static version of the id for this record.
763:             */
764:            public short getSid() {
765:                return sid;
766:            }
767:
768:            /*
769:              20 00 
770:              00 
771:              01 
772:              1A 00 // sz = 0x1A = 26
773:              00 00 
774:              01 00 
775:              00 
776:              00 
777:              00 
778:              00 
779:              00 // unicode flag
780:              07 // name
781:              
782:              29 17 00 3B 00 00 00 00 FF FF 00 00 02 00 3B 00 //{ 26
783:              00 07 00 07 00 00 00 FF 00 10                   //  }
784:              
785:              
786:              
787:              20 00 
788:              00 
789:              01 
790:              0B 00 // sz = 0xB = 11
791:              00 00 
792:              01 00 
793:              00 
794:              00 
795:              00 
796:              00 
797:              00 // unicode flag
798:              07 // name
799:              
800:              3B 00 00 07 00 07 00 00 00 FF 00   // { 11 }
801:             */
802:            /*
803:              18, 00, 
804:              1B, 00, 
805:              
806:              20, 00, 
807:              00, 
808:              01, 
809:              0B, 00, 
810:              00, 
811:              00, 
812:              00, 
813:              00, 
814:              00, 
815:              07, 
816:              3B 00 00 07 00 07 00 00 00 FF 00 ]     
817:             */
818:
819:            /**
820:             * @see Object#toString()
821:             */
822:            public String toString() {
823:                StringBuffer buffer = new StringBuffer();
824:
825:                buffer.append("[NAME]\n");
826:                buffer.append("    .option flags         = ").append(
827:                        HexDump.toHex(field_1_option_flag)).append("\n");
828:                buffer.append("    .keyboard shortcut    = ").append(
829:                        HexDump.toHex(field_2_keyboard_shortcut)).append("\n");
830:                buffer.append("    .length of the name   = ").append(
831:                        field_3_length_name_text).append("\n");
832:                buffer.append("    .size of the formula data = ").append(
833:                        field_4_length_name_definition).append("\n");
834:                buffer.append("    .unused                   = ").append(
835:                        field_5_index_to_sheet).append("\n");
836:                buffer.append(
837:                        "    .index to sheet (1-based, 0=Global)           = ")
838:                        .append(field_6_equals_to_index_to_sheet).append("\n");
839:                buffer.append(
840:                        "    .Length of menu text (character count)        = ")
841:                        .append(field_7_length_custom_menu).append("\n");
842:                buffer.append(
843:                        "    .Length of description text (character count) = ")
844:                        .append(field_8_length_description_text).append("\n");
845:                buffer.append(
846:                        "    .Length of help topic text (character count)  = ")
847:                        .append(field_9_length_help_topic_text).append("\n");
848:                buffer.append(
849:                        "    .Length of status bar text (character count)  = ")
850:                        .append(field_10_length_status_bar_text).append("\n");
851:                buffer.append("    .Name (Unicode flag)  = ").append(
852:                        field_11_compressed_unicode_flag).append("\n");
853:                buffer.append("    .Name (Unicode text)  = ").append(
854:                        getNameText()).append("\n");
855:                buffer
856:                        .append(
857:                                "    .Menu text (Unicode string without length field)        = ")
858:                        .append(field_14_custom_menu_text).append("\n");
859:                buffer
860:                        .append(
861:                                "    .Description text (Unicode string without length field) = ")
862:                        .append(field_15_description_text).append("\n");
863:                buffer
864:                        .append(
865:                                "    .Help topic text (Unicode string without length field)  = ")
866:                        .append(field_16_help_topic_text).append("\n");
867:                buffer
868:                        .append(
869:                                "    .Status bar text (Unicode string without length field)  = ")
870:                        .append(field_17_status_bar_text).append("\n");
871:                buffer.append("[/NAME]\n");
872:
873:                return buffer.toString();
874:            }
875:
876:            /**Creates a human readable name for built in types
877:             * @return Unknown if the built-in name cannot be translated
878:             */
879:            protected String translateBuiltInName(byte name) {
880:                switch (name) {
881:                case NameRecord.BUILTIN_AUTO_ACTIVATE:
882:                    return "Auto_Activate";
883:                case NameRecord.BUILTIN_AUTO_CLOSE:
884:                    return "Auto_Close";
885:                case NameRecord.BUILTIN_AUTO_DEACTIVATE:
886:                    return "Auto_Deactivate";
887:                case NameRecord.BUILTIN_AUTO_OPEN:
888:                    return "Auto_Open";
889:                case NameRecord.BUILTIN_CONSOLIDATE_AREA:
890:                    return "Consolidate_Area";
891:                case NameRecord.BUILTIN_CRITERIA:
892:                    return "Criteria";
893:                case NameRecord.BUILTIN_DATABASE:
894:                    return "Database";
895:                case NameRecord.BUILTIN_DATA_FORM:
896:                    return "Data_Form";
897:                case NameRecord.BUILTIN_PRINT_AREA:
898:                    return "Print_Area";
899:                case NameRecord.BUILTIN_PRINT_TITLE:
900:                    return "Print_Titles";
901:                case NameRecord.BUILTIN_RECORDER:
902:                    return "Recorder";
903:                case NameRecord.BUILTIN_SHEET_TITLE:
904:                    return "Sheet_Title";
905:
906:                }
907:
908:                return "Unknown";
909:            }
910:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.