You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ni...@apache.org on 2008/09/07 22:11:34 UTC

svn commit: r692932 [1/4] - in /poi/branches/ooxml: ./ src/documentation/content/xdocs/ src/java/org/apache/poi/ddf/ src/java/org/apache/poi/hssf/model/ src/java/org/apache/poi/hssf/record/ src/java/org/apache/poi/hssf/record/formula/ src/java/org/apac...

Author: nick
Date: Sun Sep  7 13:11:32 2008
New Revision: 692932

URL: http://svn.apache.org/viewvc?rev=692932&view=rev
Log:
Merged revisions 638786-638802,638805-638811,638813-638814,638816-639230,639233-639241,639243-639253,639255-639486,639488-639601,639603-639835,639837-639917,639919-640056,640058-640710,640712-641156,641158-641184,641186-641795,641797-641798,641800-641933,641935-641963,641965-641966,641968-641995,641997-642230,642232-642562,642564-642565,642568-642570,642572-642573,642576-642736,642739-642877,642879,642881-642890,642892-642903,642905-642945,642947-643624,643626-643653,643655-643669,643671,643673-643830,643832-643833,643835-644342,644344-644472,644474-644508,644510-645347,645349-645351,645353-645559,645561-645565,645568-645951,645953-646193,646195-646311,646313-646404,646406-646665,646667-646853,646855-646869,646871-647151,647153-647185,647187-647277,647279-647566,647568-647573,647575,647578-647711,647714-647737,647739-647823,647825-648155,648157-648202,648204-648273,648275,648277-648302,648304-648333,648335-648588,648590-648622,648625-648673,648675-649141,649144,649146-649556,
 649558-649795,649799,649801-649910,649912-649913,649915-650128,650131-650132,650134-650137,650140-650914,650916-651991,651993-652284,652286-652287,652289,652291,652293-652297,652299-652328,652330-652425,652427-652445,652447-652560,652562-652933,652935,652937-652993,652995-653116,653118-653124,653126-653483,653487-653519,653522-653550,653552-653607,653609-653667,653669-653674,653676-653814,653817-653830,653832-653891,653893-653944,653946-654055,654057-654355,654357-654365,654367-654648,654651-655215,655217-655277,655279-655281,655283-655911,655913-656212,656214,656216-656251,656253-656698,656700-656756,656758-656892,656894-657135,657137-657165,657168-657179,657181-657354,657356-657357,657359-657701,657703-657874,657876-658032,658034-658284,658286,658288-658301,658303-658307,658309-658321,658323-658335,658337-658348,658351,658353-658832,658834-658983,658985,658987-659066,659068-659402,659404-659428,659430-659451,659453-659454,659456-659461,659463-659477,659479-659524,659526-65
 9571,659574,659576-660255,660257-660262,660264-660279,660281-660343,660345-660473,660475-660827,660829-660833,660835-660888,660890-663321,663323-663435,663437-663764,663766-663854,663856-664219,664221-664489,664494-664514,664516-668013,668015-668142,668144-668152,668154,668156-668256,668258,668260-669139,669141-669455,669457-669657,669659-669808,669810-670189,670191-671321,671323-672229,672231-672549,672551-672552,672554-672561,672563-672566,672568,672571-673049,673051-673852,673854-673862,673864-673986,673988-673996,673998-674347,674349-674890,674892-674910,674912-674936,674938-674952,674954-675078,675080-675085,675087-675217,675219-675660,675662-675670,675672-675716,675718-675726,675728-675733,675735-675775,675777-675782,675784,675786-675791,675794-675852,675854-676200,676202,676204,676206-676220,676222-676309,676311-676456,676458-676994,676996-677027,677030-677040,677042-677056,677058-677375,677377-677968,677970-677971,677973,677975-677994,677996-678286,678288-678538,6785
 40-680393,680395-680469,680471-680529,680531-680852,680854-681529,681531-681571,681573-682224,682226,682228,682231-682281,682283-682335,682337-682507,682509,682512-682517,682519-682532,682534-682619,682622-682777,682779-682998,683000-683019,683021-683022,683024-683080,683082-683092,683094-683095,683097-683127,683129-683131,683133-683166,683168-683698,683700-683705,683707-683757,683759-683787,683789-683870,683872-683879,683881-683900,683902-684066,684068-684074,684076-684222,684224-684254,684257-684281,684283-684286,684288-684292,684294-684298,684300-684301,684303-684308,684310-684317,684320,684323-684335,684337-684348,684350-684354,684356-684361,684363-684369,684371-684453,684455-684883,684885-684937,684940-684958,684960-684970,684972-684985,684987-685053,685055-685063,685065-685259,685261-685262,685264-685266,685268-685282,685285-686035,686037-686045,686047-686052,686054-686206,686208-686215,686217-686277,686279-686289,686291-686620,686622-686623,686626-686627,686629-686639
 ,686641-686843,686845-686976,686978-687402,687404-687422,687424-687428,687430-687442,687444-688425,688427-688641,688643-688649,688651-688654,688656-688824,688826-688909,688911-689543,689545-689558,689560-689635,689637-689703,689705-689715,689717-689718,689720,689722-689972,689974-690090,690092-690093,690095-690111,690113-690258,690260-690261,690263-690403,690405-690410,690412-690460,690462-690516,690518-690533,690535,690537-690625,690627-690635,690637-690720,690722-690725,690727-690728,690730-690738,690740-690760,690762-690771,690773-690824,690826-690834,690838-691016,691018-691179,691181,691183-692908 via svnmerge from 
https://svn.apache.org/repos/asf/poi/trunk

........
  r691533 | yegor | 2008-09-03 09:04:07 +0100 (Wed, 03 Sep 2008) | 1 line
  
  fixed bug #45728: SlideShow.reorderSlide didn't work properly
........
  r691687 | josh | 2008-09-03 18:03:02 +0100 (Wed, 03 Sep 2008) | 1 line
  
  Fixed ArrayPtg.toString to not crash when partially initialised
........
  r691740 | josh | 2008-09-03 20:22:53 +0100 (Wed, 03 Sep 2008) | 1 line
  
  Initial work on bug 45720 - copy 'FilterDatabase' named record when cloning sheets. Some clean-up in NameRecord.
........
  r692239 | josh | 2008-09-04 21:58:37 +0100 (Thu, 04 Sep 2008) | 1 line
  
  Fixed 2 small bugs in RelationalOperationEval (added junits).  Refactored hierarchy.
........
  r692241 | josh | 2008-09-04 22:01:48 +0100 (Thu, 04 Sep 2008) | 1 line
  
  Fix unused import (correction to r692239)
........
  r692243 | josh | 2008-09-04 22:05:50 +0100 (Thu, 04 Sep 2008) | 1 line
  
  Fixed compiler warnings, linked junit test to suite
........
  r692255 | josh | 2008-09-04 22:32:17 +0100 (Thu, 04 Sep 2008) | 1 line
  
  Made HSSFFormulaEvaluator capable of handling simple named ranges
........
  r692300 | josh | 2008-09-05 00:16:15 +0100 (Fri, 05 Sep 2008) | 1 line
  
  Fix for bug 45376 - added caching to HSSFFormulaEvaluator
........
  r692506 | josh | 2008-09-05 19:22:30 +0100 (Fri, 05 Sep 2008) | 1 line
  
  Minor fixes for numeric operators - junit added.  Some refactoring.
........
  r692538 | josh | 2008-09-05 21:38:51 +0100 (Fri, 05 Sep 2008) | 1 line
  
  Modified formula evaluator to handle whole column refs
........
  r692541 | josh | 2008-09-05 21:43:37 +0100 (Fri, 05 Sep 2008) | 1 line
  
  reverted changes accidentally submitted with r692538
........
  r692612 | josh | 2008-09-06 06:30:31 +0100 (Sat, 06 Sep 2008) | 1 line
  
  Fixes for special cases of lookup functions (test cases added)
........
  r692614 | josh | 2008-09-06 07:04:01 +0100 (Sat, 06 Sep 2008) | 1 line
  
  Minor fixes to YEARFRAC(). Added ISEVEN() and ISODD(). Added test cases.
........
  r692893 | yegor | 2008-09-07 17:30:35 +0100 (Sun, 07 Sep 2008) | 1 line
  
  fixed bug #45720: cloneSheet breaks autofilters.
........

Added:
    poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/atp/ParityFunction.java
      - copied, changed from r692893, poi/trunk/src/java/org/apache/poi/hssf/record/formula/atp/ParityFunction.java
    poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/eval/TwoOperandNumericOperation.java
      - copied unchanged from r692893, poi/trunk/src/java/org/apache/poi/hssf/record/formula/eval/TwoOperandNumericOperation.java
    poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/OperationEvaluatorFactory.java   (with props)
    poi/branches/ooxml/src/java/org/apache/poi/ss/usermodel/EvaluationCache.java   (with props)
    poi/branches/ooxml/src/testcases/org/apache/poi/hssf/data/45720.xls
      - copied unchanged from r692893, poi/trunk/src/testcases/org/apache/poi/hssf/data/45720.xls
    poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/eval/TestDivideEval.java
      - copied unchanged from r692893, poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/eval/TestDivideEval.java
    poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/eval/TestEqualEval.java
      - copied unchanged from r692893, poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/eval/TestEqualEval.java
    poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFFormulaEvaluator.java
      - copied, changed from r692893, poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFFormulaEvaluator.java
Removed:
    poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/eval/NumericOperationEval.java
    poi/branches/ooxml/src/testcases/org/apache/poi/hssf/data/45376.xls
Modified:
    poi/branches/ooxml/   (props changed)
    poi/branches/ooxml/src/documentation/content/xdocs/changes.xml
    poi/branches/ooxml/src/documentation/content/xdocs/status.xml
    poi/branches/ooxml/src/java/org/apache/poi/ddf/EscherContainerRecord.java
    poi/branches/ooxml/src/java/org/apache/poi/hssf/model/DrawingManager2.java
    poi/branches/ooxml/src/java/org/apache/poi/hssf/model/Workbook.java
    poi/branches/ooxml/src/java/org/apache/poi/hssf/record/NameRecord.java
    poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/ArrayPtg.java
    poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/Ref3DPtg.java
    poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/atp/AnalysisToolPak.java
    poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/atp/YearFrac.java
    poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/eval/AddEval.java
    poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/eval/DivideEval.java
    poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/eval/EqualEval.java
    poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/eval/ExternalFunction.java
    poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/eval/GreaterEqualEval.java
    poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/eval/GreaterThanEval.java
    poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/eval/LazyAreaEval.java
    poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/eval/LazyRefEval.java
    poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/eval/LessEqualEval.java
    poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/eval/LessThanEval.java
    poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/eval/MultiplyEval.java
    poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/eval/NameEval.java
    poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/eval/NotEqualEval.java
    poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/eval/PercentEval.java
    poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/eval/PowerEval.java
    poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/eval/RelationalOperationEval.java
    poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/eval/SubtractEval.java
    poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/eval/UnaryMinusEval.java
    poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/eval/UnaryPlusEval.java
    poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/eval/ValueEvalToNumericXlator.java
    poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/functions/Hlookup.java
    poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/functions/LookupUtils.java
    poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/functions/Vlookup.java
    poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFName.java
    poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java
    poi/branches/ooxml/src/java/org/apache/poi/ss/usermodel/FormulaEvaluator.java
    poi/branches/ooxml/src/java/org/apache/poi/ss/usermodel/OperationEvaluatorFactory.java
    poi/branches/ooxml/src/java/org/apache/poi/ss/util/AreaReference.java
    poi/branches/ooxml/src/java/org/apache/poi/ss/util/CellReference.java
    poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/record/Document.java
    poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/record/RecordContainer.java
    poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/record/SlideListWithText.java
    poi/branches/ooxml/src/scratchpad/src/org/apache/poi/hslf/usermodel/SlideShow.java
    poi/branches/ooxml/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestReOrderingSlides.java
    poi/branches/ooxml/src/testcases/org/apache/poi/hssf/data/FormulaEvalTestData.xls
    poi/branches/ooxml/src/testcases/org/apache/poi/hssf/data/LookupFunctionsTestCaseData.xls
    poi/branches/ooxml/src/testcases/org/apache/poi/hssf/data/externalFunctionExample.xls
    poi/branches/ooxml/src/testcases/org/apache/poi/hssf/data/testNames.xls
    poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/TestExternalFunctionFormulas.java
    poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/atp/TestYearFracCalculator.java
    poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/eval/AllFormulaEvalTests.java
    poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/eval/TestCircularReferences.java
    poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/eval/TestPercentEval.java
    poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/eval/TestUnaryPlusEval.java
    poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/functions/AllIndividualFunctionEvaluationTests.java
    poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/formula/functions/TestDate.java
    poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/AllUserModelTests.java
    poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java
    poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestFormulaEvaluatorBugs.java
    poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java
    poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java
    poi/branches/ooxml/src/testcases/org/apache/poi/hssf/util/TestAreaReference.java

Propchange: poi/branches/ooxml/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Sun Sep  7 13:11:32 2008
@@ -1 +1 @@
-/poi/trunk:1-638784,638786-639486,639488-639601,639603-640056,640058-642562,642564-642566,642568-642574,642576-642736,642739-650914,650916-691382
+/poi/trunk:1-638784,638786-639486,639488-639601,639603-640056,640058-642562,642564-642566,642568-642574,642576-642736,642739-650914,650916-692908

Modified: poi/branches/ooxml/src/documentation/content/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/documentation/content/xdocs/changes.xml?rev=692932&r1=692931&r2=692932&view=diff
==============================================================================
--- poi/branches/ooxml/src/documentation/content/xdocs/changes.xml (original)
+++ poi/branches/ooxml/src/documentation/content/xdocs/changes.xml Sun Sep  7 13:11:32 2008
@@ -65,6 +65,8 @@
            <action dev="POI-DEVELOPERS" type="add">Created a common interface for handling Excel files, irrespective of if they are .xls or .xlsx</action>
         </release>
         <release version="3.1.1-alpha1" date="2008-??-??">
+           <action dev="POI-DEVELOPERS" type="fix">45720 Fixed HSSFWorkbook.cloneSheet to correctly clone sheets with drawings</action>
+           <action dev="POI-DEVELOPERS" type="fix">45728 Fix for SlideShow.reorderSlide in HSLF</action>
            <action dev="POI-DEVELOPERS" type="add">Initial support for embedded movies and controls in HSLF</action>
            <action dev="POI-DEVELOPERS" type="fix">45358 - signed/unsigned error when parsing 3-d area refs, performance problem evaluating area refs, and ClassCastExcecption in IF()</action>
            <action dev="POI-DEVELOPERS" type="add">Support for HPBF Publisher hyperlinks, including during text extraction</action>

Modified: poi/branches/ooxml/src/documentation/content/xdocs/status.xml
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/documentation/content/xdocs/status.xml?rev=692932&r1=692931&r2=692932&view=diff
==============================================================================
--- poi/branches/ooxml/src/documentation/content/xdocs/status.xml (original)
+++ poi/branches/ooxml/src/documentation/content/xdocs/status.xml Sun Sep  7 13:11:32 2008
@@ -62,6 +62,8 @@
            <action dev="POI-DEVELOPERS" type="add">Created a common interface for handling Excel files, irrespective of if they are .xls or .xlsx</action>
         </release>
         <release version="3.1.1-alpha1" date="2008-??-??">
+           <action dev="POI-DEVELOPERS" type="fix">45720 Fixed HSSFWorkbook.cloneSheet to correctly clone sheets with drawings</action>
+           <action dev="POI-DEVELOPERS" type="fix">45728 Fix for SlideShow.reorderSlide in HSLF</action>
            <action dev="POI-DEVELOPERS" type="add">Initial support for embedded movies and controls in HSLF</action>
            <action dev="POI-DEVELOPERS" type="fix">45358 - signed/unsigned error when parsing 3-d area refs, performance problem evaluating area refs, and ClassCastExcecption in IF()</action>
            <action dev="POI-DEVELOPERS" type="add">Support for HPBF Publisher hyperlinks, including during text extraction</action>

Modified: poi/branches/ooxml/src/java/org/apache/poi/ddf/EscherContainerRecord.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/ddf/EscherContainerRecord.java?rev=692932&r1=692931&r2=692932&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/ddf/EscherContainerRecord.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/ddf/EscherContainerRecord.java Sun Sep  7 13:11:32 2008
@@ -235,4 +235,21 @@
         return null;
     }
 
+    /**
+     * Recursively find records with the specified record ID
+     *
+     * @param out - list to store found records
+     */
+    public void getRecordsById(short recordId, List out){
+        for(Iterator it = childRecords.iterator(); it.hasNext();) {
+            Object er = it.next();
+            if(er instanceof EscherContainerRecord) {
+                EscherContainerRecord c = (EscherContainerRecord)er;
+                c.getRecordsById(recordId, out );
+            } else if (er instanceof EscherSpRecord){
+                out.add(er);
+            }
+        }
+    }
+
 }

Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/model/DrawingManager2.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/model/DrawingManager2.java?rev=692932&r1=692931&r2=692932&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/model/DrawingManager2.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/model/DrawingManager2.java Sun Sep  7 13:11:32 2008
@@ -68,6 +68,17 @@
      */
     public int allocateShapeId(short drawingGroupId)
     {
+        EscherDgRecord dg = getDrawingGroup(drawingGroupId);
+        return allocateShapeId(drawingGroupId, dg);
+    }
+
+    /**
+     * Allocates new shape id for the new drawing group id.
+     *
+     * @return a new shape id.
+     */
+    public int allocateShapeId(short drawingGroupId, EscherDgRecord dg)
+    {
         dgg.setNumShapesSaved( dgg.getNumShapesSaved() + 1 );
 
         // Add to existing cluster if space available
@@ -78,7 +89,6 @@
             {
                 int result = c.getNumShapeIdsUsed() + (1024 * (i+1));
                 c.incrementShapeId();
-                EscherDgRecord dg = getDrawingGroup(drawingGroupId);
                 dg.setNumShapes( dg.getNumShapes() + 1 );
                 dg.setLastMSOSPID( result );
                 if (result >= dgg.getShapeIdMax())
@@ -90,7 +100,6 @@
         // Create new cluster
         dgg.addCluster( drawingGroupId, 0 );
         dgg.getFileIdClusters()[dgg.getFileIdClusters().length-1].incrementShapeId();
-        EscherDgRecord dg = getDrawingGroup(drawingGroupId);
         dg.setNumShapes( dg.getNumShapes() + 1 );
         int result = (1024 * dgg.getFileIdClusters().length);
         dg.setLastMSOSPID( result );
@@ -98,7 +107,6 @@
             dgg.setShapeIdMax( result + 1 );
         return result;
     }
-
     ////////////  Non-public methods /////////////
     
     /**

Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/model/Workbook.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/model/Workbook.java?rev=692932&r1=692931&r2=692932&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/model/Workbook.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/model/Workbook.java Sun Sep  7 13:11:32 2008
@@ -22,57 +22,8 @@
 import java.util.List;
 import java.util.Locale;
 
-import org.apache.poi.ddf.EscherBSERecord;
-import org.apache.poi.ddf.EscherBoolProperty;
-import org.apache.poi.ddf.EscherContainerRecord;
-import org.apache.poi.ddf.EscherDggRecord;
-import org.apache.poi.ddf.EscherOptRecord;
-import org.apache.poi.ddf.EscherProperties;
-import org.apache.poi.ddf.EscherRGBProperty;
-import org.apache.poi.ddf.EscherRecord;
-import org.apache.poi.ddf.EscherSplitMenuColorsRecord;
-import org.apache.poi.hssf.record.BOFRecord;
-import org.apache.poi.hssf.record.BackupRecord;
-import org.apache.poi.hssf.record.BookBoolRecord;
-import org.apache.poi.hssf.record.BoundSheetRecord;
-import org.apache.poi.hssf.record.CodepageRecord;
-import org.apache.poi.hssf.record.CountryRecord;
-import org.apache.poi.hssf.record.DSFRecord;
-import org.apache.poi.hssf.record.DateWindow1904Record;
-import org.apache.poi.hssf.record.DrawingGroupRecord;
-import org.apache.poi.hssf.record.EOFRecord;
-import org.apache.poi.hssf.record.ExtSSTRecord;
-import org.apache.poi.hssf.record.ExtendedFormatRecord;
-import org.apache.poi.hssf.record.ExternSheetRecord;
-import org.apache.poi.hssf.record.FileSharingRecord;
-import org.apache.poi.hssf.record.FnGroupCountRecord;
-import org.apache.poi.hssf.record.FontRecord;
-import org.apache.poi.hssf.record.FormatRecord;
-import org.apache.poi.hssf.record.HideObjRecord;
-import org.apache.poi.hssf.record.HyperlinkRecord;
-import org.apache.poi.hssf.record.InterfaceEndRecord;
-import org.apache.poi.hssf.record.InterfaceHdrRecord;
-import org.apache.poi.hssf.record.MMSRecord;
-import org.apache.poi.hssf.record.NameRecord;
-import org.apache.poi.hssf.record.PaletteRecord;
-import org.apache.poi.hssf.record.PasswordRecord;
-import org.apache.poi.hssf.record.PasswordRev4Record;
-import org.apache.poi.hssf.record.PrecisionRecord;
-import org.apache.poi.hssf.record.ProtectRecord;
-import org.apache.poi.hssf.record.ProtectionRev4Record;
-import org.apache.poi.hssf.record.RecalcIdRecord;
-import org.apache.poi.hssf.record.Record;
-import org.apache.poi.hssf.record.RefreshAllRecord;
-import org.apache.poi.hssf.record.SSTRecord;
-import org.apache.poi.hssf.record.StyleRecord;
-import org.apache.poi.hssf.record.SupBookRecord;
-import org.apache.poi.hssf.record.TabIdRecord;
-import org.apache.poi.hssf.record.UnicodeString;
-import org.apache.poi.hssf.record.UseSelFSRecord;
-import org.apache.poi.hssf.record.WindowOneRecord;
-import org.apache.poi.hssf.record.WindowProtectRecord;
-import org.apache.poi.hssf.record.WriteAccessRecord;
-import org.apache.poi.hssf.record.WriteProtectRecord;
+import org.apache.poi.ddf.*;
+import org.apache.poi.hssf.record.*;
 import org.apache.poi.hssf.record.formula.NameXPtg;
 import org.apache.poi.hssf.util.HSSFColor;
 import org.apache.poi.hssf.util.SheetReferences;
@@ -2206,17 +2157,17 @@
         //  contains a EscherDggRecord
         for(Iterator rit = records.iterator(); rit.hasNext();) {
             Record r = (Record)rit.next();
-            
+
             if(r instanceof DrawingGroupRecord) {
                 DrawingGroupRecord dg =    (DrawingGroupRecord)r;
                 dg.processChildRecords();
-                
+
                 EscherContainerRecord cr =
                     dg.getEscherContainer();
                 if(cr == null) {
                     continue;
                 }
-                
+
                 EscherDggRecord dgg = null;
                 for(Iterator it = cr.getChildRecords().iterator(); it.hasNext();) {
                     Object er = it.next();
@@ -2224,7 +2175,7 @@
                         dgg = (EscherDggRecord)er;
                     }
                 }
-                
+
                 if(dgg != null) {
                     drawingManager = new DrawingManager2(dgg);
                     return;
@@ -2234,7 +2185,7 @@
 
         // Look for the DrawingGroup record
         int dgLoc = findFirstRecordLocBySid(DrawingGroupRecord.sid);
-        
+
         // If there is one, does it have a EscherDggRecord?
         if(dgLoc != -1) {
             DrawingGroupRecord dg =
@@ -2246,7 +2197,7 @@
                     dgg = (EscherDggRecord)er;
                 }
             }
-            
+
             if(dgg != null) {
                 drawingManager = new DrawingManager2(dgg);
             }
@@ -2455,4 +2406,54 @@
     public NameXPtg getNameXPtg(String name) {
         return getOrCreateLinkTable().getNameXPtg(name);
     }
+
+    /**
+     * Check if the cloned sheet has drawings. If yes, then allocate a new drawing group ID and
+     * re-generate shape IDs
+     *
+     * @param sheet the cloned sheet
+     */
+    public void cloneDrawings(Sheet sheet){
+
+        findDrawingGroup();
+
+        if(drawingManager == null) {
+            //this workbook does not have drawings
+            return;
+        }
+
+        //check if the cloned sheet has drawings
+        int aggLoc = sheet.aggregateDrawingRecords(drawingManager, false);
+        if(aggLoc != -1) {
+            EscherAggregate agg = (EscherAggregate) sheet.findFirstRecordBySid(EscherAggregate.sid);
+
+            EscherDggRecord dgg = drawingManager.getDgg();
+
+            //register a new drawing group for the cloned sheet
+            int dgId = drawingManager.findNewDrawingGroupId();
+            dgg.addCluster( dgId, 0 );
+            dgg.setDrawingsSaved(dgg.getDrawingsSaved() + 1);
+
+            EscherDgRecord dg = null;
+            for(Iterator it = agg.getEscherContainer().getChildRecords().iterator(); it.hasNext();) {
+                Object er = it.next();
+                if(er instanceof EscherDgRecord) {
+                    dg = (EscherDgRecord)er;
+                    //update id of the drawing in the cloned sheet
+                    dg.setOptions( (short) ( dgId << 4 ) );
+                } else if (er instanceof EscherContainerRecord){
+                    //recursively find shape records and re-generate shapeId
+                    ArrayList spRecords = new ArrayList();
+                    EscherContainerRecord cp = (EscherContainerRecord)er;
+                    cp.getRecordsById(EscherSpRecord.RECORD_ID,  spRecords);
+                    for(Iterator spIt = spRecords.iterator(); spIt.hasNext();) {
+                        EscherSpRecord sp = (EscherSpRecord)spIt.next();
+                        int shapeId = drawingManager.allocateShapeId((short)dgId, dg);
+                        sp.setShapeId(shapeId);
+                    }
+                }
+            }
+
+        }
+    }
 }

Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/record/NameRecord.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/record/NameRecord.java?rev=692932&r1=692931&r2=692932&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/record/NameRecord.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/record/NameRecord.java Sun Sep  7 13:11:32 2008
@@ -17,9 +17,8 @@
 
 package org.apache.poi.hssf.record;
 
-import java.util.Iterator;
+import java.util.ArrayList;
 import java.util.List;
-import java.util.Stack;
 
 import org.apache.poi.hssf.model.FormulaParser;
 import org.apache.poi.hssf.record.formula.Area3DPtg;
@@ -44,51 +43,33 @@
  */
 public final class NameRecord extends Record {
     public final static short sid = 0x0018;
-	/**Included for completeness sake, not implemented
-	   */
-	public final static byte  BUILTIN_CONSOLIDATE_AREA      = (byte)1;
-	
-	/**Included for completeness sake, not implemented
-	 */
-	public final static byte  BUILTIN_AUTO_OPEN             = (byte)2;
-
-	/**Included for completeness sake, not implemented
-	 */
-	public final static byte  BUILTIN_AUTO_CLOSE            = (byte)3;
-
-	/**Included for completeness sake, not implemented
-	 */
-	public final static byte  BUILTIN_DATABASE              = (byte)4;
-
-	/**Included for completeness sake, not implemented
-	 */
-	public final static byte  BUILTIN_CRITERIA              = (byte)5;
-	
-	public final static byte  BUILTIN_PRINT_AREA            = (byte)6;
-	public final static byte  BUILTIN_PRINT_TITLE           = (byte)7;
-	
-	/**Included for completeness sake, not implemented
-	 */
-	public final static byte  BUILTIN_RECORDER              = (byte)8;
-	
-	/**Included for completeness sake, not implemented
-	 */
-	public final static byte  BUILTIN_DATA_FORM             = (byte)9;
-	
-	/**Included for completeness sake, not implemented
-	 */
+	/**Included for completeness sake, not implemented */
+	public final static byte  BUILTIN_CONSOLIDATE_AREA      = 1;
+	/**Included for completeness sake, not implemented */
+	public final static byte  BUILTIN_AUTO_OPEN             = 2;
+	/**Included for completeness sake, not implemented */
+	public final static byte  BUILTIN_AUTO_CLOSE            = 3;
+	/**Included for completeness sake, not implemented */
+	public final static byte  BUILTIN_DATABASE              = 4;
+	/**Included for completeness sake, not implemented */
+	public final static byte  BUILTIN_CRITERIA              = 5;
+
+	public final static byte  BUILTIN_PRINT_AREA            = 6;
+	public final static byte  BUILTIN_PRINT_TITLE           = 7;
+
+	/**Included for completeness sake, not implemented */
+	public final static byte  BUILTIN_RECORDER              = 8;
+	/**Included for completeness sake, not implemented */
+	public final static byte  BUILTIN_DATA_FORM             = 9;
+	/**Included for completeness sake, not implemented */
+	public final static byte  BUILTIN_AUTO_ACTIVATE         = 10;
+	/**Included for completeness sake, not implemented */
+	public final static byte  BUILTIN_AUTO_DEACTIVATE       = 11;
+	/**Included for completeness sake, not implemented */
+	public final static byte  BUILTIN_SHEET_TITLE           = 12;
 
-	public final static byte  BUILTIN_AUTO_ACTIVATE         = (byte)10;
-	
-	/**Included for completeness sake, not implemented
-	 */
+	public final static byte  BUILTIN_FILTER_DB             = 13;
 
-	public final static byte  BUILTIN_AUTO_DEACTIVATE       = (byte)11;
-	
-	/**Included for completeness sake, not implemented
-	 */
-	public final static byte  BUILTIN_SHEET_TITLE           = (byte)12;
-	
 	private static final class Option {
 		public static final int OPT_HIDDEN_NAME =   0x0001;
 		public static final int OPT_FUNCTION_NAME = 0x0002;
@@ -98,22 +79,16 @@
 		public static final int OPT_BUILTIN =       0x0020;
 		public static final int OPT_BINDATA =       0x1000;
 	}
-	
+
 	private short             field_1_option_flag;
 	private byte              field_2_keyboard_shortcut;
-	private byte              field_3_length_name_text;
-	private short             field_4_length_name_definition;
 	private short             field_5_index_to_sheet;     // unused: see field_6
 	/** the one based sheet number.  Zero if this is a global name */
 	private int               field_6_sheetNumber;
-	private byte              field_7_length_custom_menu;
-	private byte              field_8_length_description_text;
-	private byte              field_9_length_help_topic_text;
-	private byte              field_10_length_status_bar_text;
-	private byte              field_11_compressed_unicode_flag;   // not documented
-	private byte              field_12_builtIn_name;
+	private boolean           field_11_nameIsMultibyte;
+	private byte              field_12_built_in_code;
 	private String            field_12_name_text;
-	private Stack             field_13_name_definition;
+	private Ptg[]             field_13_name_definition;
 	private String            field_14_custom_menu_text;
 	private String            field_15_description_text;
 	private String            field_16_help_topic_text;
@@ -122,13 +97,13 @@
 
 	/** Creates new NameRecord */
 	public NameRecord() {
-		field_13_name_definition = new Stack();
+		field_13_name_definition = Ptg.EMPTY_PTG_ARRAY;
 
-		field_12_name_text = new String();
-		field_14_custom_menu_text = new String();
-		field_15_description_text = new String();
-		field_16_help_topic_text = new String();
-		field_17_status_bar_text = new String();
+		field_12_name_text = "";
+		field_14_custom_menu_text = "";
+		field_15_description_text = "";
+		field_16_help_topic_text = "";
+		field_17_status_bar_text = "";
 	}
 
 	/**
@@ -146,19 +121,10 @@
 	 */
 	public NameRecord(byte builtin, int sheetNumber)
 	{
-		this();		
-		this.field_12_builtIn_name = builtin;
-		this.setOptionFlag((short)(this.field_1_option_flag | Option.OPT_BUILTIN));
-		this.setNameTextLength((byte)1);
+		this();
+		field_12_built_in_code = builtin;
+		setOptionFlag((short)(field_1_option_flag | Option.OPT_BUILTIN));
 		field_6_sheetNumber = sheetNumber; //the extern sheets are set through references
-		
-		//clearing these because they are not used with builtin records
-		this.setCustomMenuLength((byte)0);
-		this.setDescriptionTextLength((byte)0);
-		this.setHelpTopicLength((byte)0);
-		this.setStatusBarLength((byte)0);
-
-		
 	}
 
 	/** sets the option flag for the named range
@@ -176,34 +142,9 @@
 		field_2_keyboard_shortcut = shortcut;
 	}
 
-	/** sets the name of the named range length
-	 * @param length name length
-	 */
-	public void setNameTextLength(byte length){
-		field_3_length_name_text = length;
-	}
-
-	/** sets the definition (reference - formula) length
-	 * @param length defenition length
-	 */
-	public void setDefinitionTextLength(short length){
-		field_4_length_name_definition = length;
-	}
-
-	/** sets the index number to the extern sheet (thats is what writen in documentation
-	 *  but as i saw , it works differently)
-	 * @param index extern sheet index
-	 */
-	public void setUnused(short index){
-		field_5_index_to_sheet = index;
-
-		// field_6_equals_to_index_to_sheet is equal to field_5_index_to_sheet
-//        field_6_equals_to_index_to_sheet = index;
-	}
-
 	/**
 	 * For named ranges, and built-in names
-	 * @return the 1-based sheet number.  Zero if this is a global name 
+	 * @return the 1-based sheet number.  Zero if this is a global name
 	 */
 	public int getSheetNumber()
 	{
@@ -226,49 +167,12 @@
 	}
 
 
-	/** sets the custom menu length
-	 * @param length custom menu length
-	 */
-	public void setCustomMenuLength(byte length){
-		field_7_length_custom_menu = length;
-	}
-
-	/** sets the length of named range description
-	 * @param length description length
-	 */
-	public void setDescriptionTextLength(byte length){
-		field_8_length_description_text = length;
-	}
-
-	/** sets the help topic length
-	 * @param length help topic length
-	 */
-	public void setHelpTopicLength(byte length){
-		field_9_length_help_topic_text = length;
-	}
-
-	/** sets the length of the status bar text
-	 * @param length status bar text length
-	 */
-	public void setStatusBarLength(byte length){
-		field_10_length_status_bar_text = length;
-	}
-
-	/** sets the compressed unicode flag
-	 * @param flag unicode flag
-	 */
-	public void setCompressedUnicodeFlag(byte flag) {
-		field_11_compressed_unicode_flag = flag;
-	}
-
 	/** sets the name of the named range
 	 * @param name named range name
 	 */
 	public void setNameText(String name){
 		field_12_name_text = name;
-		setCompressedUnicodeFlag(
-			StringUtil.hasMultibyte(name) ?	(byte)1 : (byte)0
-		);
+		field_11_nameIsMultibyte = StringUtil.hasMultibyte(name);
 	}
 
 	/** sets the custom menu text
@@ -313,72 +217,15 @@
 		return field_2_keyboard_shortcut ;
 	}
 
-	/** 
+	/**
 	 * gets the name length, in characters
 	 * @return name length
 	 */
-	public byte getNameTextLength(){
-		return field_3_length_name_text;
-	}
-	
-	/** 
-	 * gets the name length, in bytes
-	 * @return raw name length
-	 */
-	public byte getRawNameTextLength(){
-		if( (field_11_compressed_unicode_flag & 0x01) == 1 ) {
-			return (byte)(2 * field_3_length_name_text);
+	private int getNameTextLength(){
+		if (isBuiltInName()) {
+			return 1;
 		}
-		return field_3_length_name_text;
-	}
-
-	/** get the definition length
-	 * @return definition length
-	 */
-	public short getDefinitionLength(){
-		return field_4_length_name_definition;
-	}
-
-	/** gets the index to extern sheet
-	 * @return index to extern sheet
-	 */
-	public short getUnused(){
-		return field_5_index_to_sheet;
-	}
-
-	/** gets the custom menu length
-	 * @return custom menu length
-	 */
-	public byte getCustomMenuLength(){
-		return field_7_length_custom_menu;
-	}
-
-	/** gets the description text length
-	 * @return description text length
-	 */
-	public byte getDescriptionTextLength(){
-		return field_8_length_description_text;
-	}
-
-	/** gets the help topic length
-	 * @return help topic length
-	 */
-	public byte getHelpTopicLength(){
-		return field_9_length_help_topic_text;
-	}
-
-	/** get the status bar text length
-	 * @return satus bar length
-	 */
-	public byte getStatusBarLength(){
-		return field_10_length_status_bar_text;
-	}
-
-	/** gets the name compressed Unicode flag
-	 * @return compressed unicode flag
-	 */
-	public byte getCompressedUnicodeFlag() {
-		return field_11_compressed_unicode_flag;
+		return field_12_name_text.length();
 	}
 
 
@@ -388,13 +235,26 @@
 	public boolean isHiddenName() {
 		return (field_1_option_flag & Option.OPT_HIDDEN_NAME) != 0;
 	}
+	public void setHidden(boolean b) {
+		if (b) {
+			field_1_option_flag |= Option.OPT_HIDDEN_NAME;
+		} else {
+			field_1_option_flag &= (~Option.OPT_HIDDEN_NAME);
+		}
+	}
 	/**
-	 * @return true if name is a function
+	 * @return <code>true</code> if name is a function
 	 */
 	public boolean isFunctionName() {
 		return (field_1_option_flag & Option.OPT_FUNCTION_NAME) != 0;
 	}
 
+	/**
+	 * @return <code>true</code> if name has a formula (named range or defined value)
+	 */
+	public boolean hasFormula() {
+		return field_1_option_flag == 0 && field_13_name_definition.length > 0;
+	}
 
 	/**
 	 * @return true if name is a command
@@ -419,7 +279,7 @@
 	 */
 	public boolean isBuiltInName()
 	{
-		return ((this.field_1_option_flag & Option.OPT_BUILTIN) != 0);
+		return ((field_1_option_flag & Option.OPT_BUILTIN) != 0);
 	}
 
 
@@ -428,7 +288,7 @@
 	 */
 	public String getNameText(){
 
-		return this.isBuiltInName() ? this.translateBuiltInName(this.getBuiltInName()) : field_12_name_text;
+		return isBuiltInName() ? translateBuiltInName(getBuiltInName()) : field_12_name_text;
 	}
 
 	/** Gets the Built In Name
@@ -436,19 +296,19 @@
 	 */
 	public byte getBuiltInName()
 	{
-		return this.field_12_builtIn_name;
+		return field_12_built_in_code;
 	}
 
 
 	/** gets the definition, reference (Formula)
-	 * @return definition -- can be null if we cant parse ptgs
+	 * @return the name formula. never <code>null</code>
 	 */
-	public List getNameDefinition() {
-		return field_13_name_definition;
+	public Ptg[] getNameDefinition() {
+		return (Ptg[]) field_13_name_definition.clone();
 	}
 
-	public void setNameDefinition(Stack nameDefinition) {
-		field_13_name_definition = nameDefinition;
+	public void setNameDefinition(Ptg[] ptgs) {
+		field_13_name_definition = (Ptg[]) ptgs.clone();
 	}
 
 	/** get the custom menu text
@@ -490,7 +350,8 @@
 			throw new RecordFormatException("NOT A valid Name RECORD");
 		}
 	}
-	
+
+
 	/**
 	 * called by the class that is responsible for writing this sucker.
 	 * Subclasses should implement this so that their data is passed back in a
@@ -498,109 +359,107 @@
 	 * @param data byte array containing instance data
 	 * @return number of bytes written
 	 */
-	public int serialize( int offset, byte[] data )
-	{
-		LittleEndian.putShort( data, 0 + offset, sid );
-		short size = (short)( 15 + getTextsLength() + getNameDefinitionSize());
-		LittleEndian.putShort( data, 2 + offset, size );
-		// size defined below
-		LittleEndian.putShort( data, 4 + offset, getOptionFlag() );
-		data[6 + offset] = getKeyboardShortcut();
-		data[7 + offset] = getNameTextLength();
-		LittleEndian.putShort( data, 8 + offset, getDefinitionLength() );
-		LittleEndian.putShort( data, 10 + offset, getUnused() );
-		LittleEndian.putUShort( data, 12 + offset, field_6_sheetNumber);
-		data[14 + offset] = getCustomMenuLength();
-		data[15 + offset] = getDescriptionTextLength();
-		data[16 + offset] = getHelpTopicLength();
-		data[17 + offset] = getStatusBarLength();
-		data[18 + offset] = getCompressedUnicodeFlag();
-
-			int start_of_name_definition = 19 + field_3_length_name_text;
-
-			if (this.isBuiltInName()) {
-				//can send the builtin name directly in
-				data [19 + offset] =  this.getBuiltInName();
-			} else if ((this.getCompressedUnicodeFlag() & 0x01) == 1) {
-				StringUtil.putUnicodeLE( getNameText(), data, 19 + offset );
-				start_of_name_definition = 19 + (2 * field_3_length_name_text);
-			} else {
-				StringUtil.putCompressedUnicode( getNameText(), data, 19 + offset );
-			}
-
-
-			Ptg.serializePtgStack(field_13_name_definition,  data, start_of_name_definition + offset );
-
-
-			int start_of_custom_menu_text = start_of_name_definition + field_4_length_name_definition;
-			StringUtil.putCompressedUnicode( getCustomMenuText(), data, start_of_custom_menu_text + offset );
-
-			int start_of_description_text = start_of_custom_menu_text + field_7_length_custom_menu;
-			StringUtil.putCompressedUnicode( getDescriptionText(), data, start_of_description_text + offset );
-
-			int start_of_help_topic_text = start_of_description_text + field_8_length_description_text;
-			StringUtil.putCompressedUnicode( getHelpTopicText(), data, start_of_help_topic_text + offset );
-
-			int start_of_status_bar_text = start_of_help_topic_text + field_9_length_help_topic_text;
-			StringUtil.putCompressedUnicode( getStatusBarText(), data, start_of_status_bar_text + offset );
-
-			return getRecordSize();
-		/* } */
-	}
-
-	/** 
-	 * Gets the length of all texts, in bytes
-	 * @return total length
-	 */
-	public int getTextsLength(){
-		int result;
+	public int serialize( int offset, byte[] data ) {
 
-		result = getRawNameTextLength() + getDescriptionTextLength() +
-			getHelpTopicLength() + getStatusBarLength();
-
-		return result;
-	}
-	
-	private int getNameDefinitionSize() {
-		int result = 0;
-		List list   = field_13_name_definition;
+		int field_7_length_custom_menu = field_14_custom_menu_text.length();
+		int field_8_length_description_text = field_15_description_text.length();
+		int field_9_length_help_topic_text = field_16_help_topic_text.length();
+		int field_10_length_status_bar_text = field_17_status_bar_text.length();
+		int rawNameSize = getNameRawSize();
 		
-		for (int k = 0; k < list.size(); k++)
-		{
-			Ptg ptg = ( Ptg ) list.get(k);
-			
-			result += ptg.getSize();
+		int formulaTotalSize = Ptg.getEncodedSize(field_13_name_definition);
+		int dataSize = 15 // 4 shorts + 7 bytes
+			+ rawNameSize
+			+ field_7_length_custom_menu
+			+ field_8_length_description_text
+			+ field_9_length_help_topic_text
+			+ field_10_length_status_bar_text
+			+ formulaTotalSize;
+		
+		LittleEndian.putShort(data, 0 + offset, sid);
+		LittleEndian.putUShort(data, 2 + offset, dataSize);
+		// size defined below
+		LittleEndian.putShort(data, 4 + offset, getOptionFlag());
+		LittleEndian.putByte(data, 6 + offset, getKeyboardShortcut());
+		LittleEndian.putByte(data, 7 + offset, getNameTextLength());
+		// Note -
+		LittleEndian.putUShort(data, 8 + offset, Ptg.getEncodedSizeWithoutArrayData(field_13_name_definition));
+		LittleEndian.putUShort(data, 10 + offset, field_5_index_to_sheet);
+		LittleEndian.putUShort(data, 12 + offset, field_6_sheetNumber);
+		LittleEndian.putByte(data, 14 + offset, field_7_length_custom_menu);
+		LittleEndian.putByte(data, 15 + offset, field_8_length_description_text);
+		LittleEndian.putByte(data, 16 + offset, field_9_length_help_topic_text);
+		LittleEndian.putByte(data, 17 + offset, field_10_length_status_bar_text);
+		LittleEndian.putByte(data, 18 + offset, field_11_nameIsMultibyte ? 1 : 0);
+		int pos = 19 + offset;
+
+		if (isBuiltInName()) {
+			//can send the builtin name directly in
+			LittleEndian.putByte(data, pos,  field_12_built_in_code);
+		} else {
+			String nameText = field_12_name_text;
+			if (field_11_nameIsMultibyte) {
+    			StringUtil.putUnicodeLE(nameText, data, pos);
+     		} else {
+    			StringUtil.putCompressedUnicode(nameText, data, pos);
+    		}
 		}
-		return result;    
+		pos += rawNameSize;
+
+		Ptg.serializePtgs(field_13_name_definition,  data, pos);
+		pos += formulaTotalSize;
+		
+		StringUtil.putCompressedUnicode( getCustomMenuText(), data, pos);
+		pos += field_7_length_custom_menu;
+		StringUtil.putCompressedUnicode( getDescriptionText(), data, pos);
+		pos += field_8_length_description_text;
+		StringUtil.putCompressedUnicode( getHelpTopicText(), data, pos);
+		pos += field_9_length_help_topic_text;
+		StringUtil.putCompressedUnicode( getStatusBarText(), data, pos);
+
+		return 4 + dataSize;
+	}
+	private int getNameRawSize() {
+		if (isBuiltInName()) {
+			return 1;
+		} 
+		int nChars = field_12_name_text.length();
+		if(field_11_nameIsMultibyte) {
+			return 2 * nChars;
+		} 
+		return nChars;
 	}
 
 	/** returns the record size
 	 */
 	public int getRecordSize(){
-		int result;
-
-		result = 19 + getTextsLength() + getNameDefinitionSize();
-		
-
-		return result;
+		return 4 // sid + size
+			+ 15 // 4 shorts + 7 bytes
+			+ getNameRawSize()
+			+ field_14_custom_menu_text.length()
+			+ field_15_description_text.length()
+			+ field_16_help_topic_text.length()
+			+ field_17_status_bar_text.length()
+			+ Ptg.getEncodedSize(field_13_name_definition);
 	}
 
 	/** gets the extern sheet number
 	 * @return extern sheet index
 	 */
 	public short getExternSheetNumber(){
-		if (field_13_name_definition == null || field_13_name_definition.isEmpty()) return 0;
-		Ptg ptg = (Ptg) field_13_name_definition.peek();
-		short result = 0;
+		if (field_13_name_definition.length < 1) {
+			return 0;
+		}
+		Ptg ptg = field_13_name_definition[0];
 
 		if (ptg.getClass() == Area3DPtg.class){
-			result = ((Area3DPtg) ptg).getExternSheetIndex();
+			return ((Area3DPtg) ptg).getExternSheetIndex();
 
-		} else if (ptg.getClass() == Ref3DPtg.class){
-			result = ((Ref3DPtg) ptg).getExternSheetIndex();
 		}
-
-		return result;
+		if (ptg.getClass() == Ref3DPtg.class){
+			return ((Ref3DPtg) ptg).getExternSheetIndex();
+		}
+		return 0;
 	}
 
 	/** sets the extern sheet number
@@ -609,11 +468,13 @@
 	public void setExternSheetNumber(short externSheetNumber){
 		Ptg ptg;
 
-		if (field_13_name_definition == null || field_13_name_definition.isEmpty()){
-			field_13_name_definition = new Stack();
+		if (field_13_name_definition.length < 1){
 			ptg = createNewPtg();
+			field_13_name_definition = new Ptg[] {
+				ptg,
+			};
 		} else {
-			ptg = (Ptg) field_13_name_definition.peek();
+			ptg = field_13_name_definition[0];
 		}
 
 		if (ptg.getClass() == Area3DPtg.class){
@@ -625,11 +486,8 @@
 
 	}
 
-	private Ptg createNewPtg(){
-		Ptg ptg = new Area3DPtg("A1", 0); // TODO - change to not be partially initialised
-		field_13_name_definition.push(ptg);
-
-		return ptg;
+	private static Ptg createNewPtg(){
+		return new Area3DPtg("A1:A1", 0); // TODO - change to not be partially initialised
 	}
 
 	/** gets the reference , the area only (range)
@@ -646,16 +504,14 @@
 		//Trying to find if what ptg do we need
 		RangeAddress ra = new RangeAddress(ref);
 		Ptg oldPtg;
-		Ptg ptg;
 
-		if (field_13_name_definition==null ||field_13_name_definition.isEmpty()){
-			field_13_name_definition = new Stack();
+		if (field_13_name_definition.length < 1){
 			oldPtg = createNewPtg();
 		} else {
 			//Trying to find extern sheet index
-			oldPtg = (Ptg) field_13_name_definition.pop();
+			oldPtg = field_13_name_definition[0];
 		}
-
+		List temp = new ArrayList();
 		short externSheetIndex = 0;
 
 		if (oldPtg.getClass() == Area3DPtg.class){
@@ -667,29 +523,27 @@
 
 		if (ra.hasRange()) {
 			// Is it contiguous or not?
-			AreaReference[] refs = 
-				AreaReference.generateContiguous(ref);
-			this.setDefinitionTextLength((short)0);
+			AreaReference[] refs = AreaReference.generateContiguous(ref);
 
-			// Add the area reference(s) 
+			// Add the area reference(s)
 			for(int i=0; i<refs.length; i++) {
-				ptg = new Area3DPtg(refs[i].formatAsString(), externSheetIndex);
-				field_13_name_definition.push(ptg);
-				this.setDefinitionTextLength( (short)(getDefinitionLength() + ptg.getSize()) );
+				Ptg ptg = new Area3DPtg(refs[i].formatAsString(), externSheetIndex);
+				temp.add(ptg);
 			}
 			// And then a union if we had more than one area
 			if(refs.length > 1) {
-				ptg = UnionPtg.instance;
-				field_13_name_definition.push(ptg);
-				this.setDefinitionTextLength( (short)(getDefinitionLength() + ptg.getSize()) );
+				Ptg ptg = UnionPtg.instance;
+				temp.add(ptg);
 			}
 		} else {
-			ptg = new Ref3DPtg();
+			Ptg ptg = new Ref3DPtg();
 			((Ref3DPtg) ptg).setExternSheetIndex(externSheetIndex);
 			((Ref3DPtg) ptg).setArea(ref);
-			field_13_name_definition.push(ptg);
-			this.setDefinitionTextLength((short)ptg.getSize());
+			temp.add(ptg);
 		}
+		Ptg[] ptgs = new Ptg[temp.size()];
+		temp.toArray(ptgs);
+		field_13_name_definition = ptgs;
 	}
 
 	/**
@@ -699,40 +553,36 @@
 	 * @param in the RecordInputstream to read the record from
 	 */
 	protected void fillFields(RecordInputStream in) {
-		field_1_option_flag             = in.readShort();
-		field_2_keyboard_shortcut       = in.readByte();
-		field_3_length_name_text        = in.readByte();
-		field_4_length_name_definition  = in.readShort();
-		field_5_index_to_sheet          = in.readShort();
-		field_6_sheetNumber = in.readUShort();
-		field_7_length_custom_menu      = in.readByte();
-		field_8_length_description_text = in.readByte();
-		field_9_length_help_topic_text  = in.readByte();
-		field_10_length_status_bar_text = in.readByte();
-			
-		//store the name in byte form if it's a builtin name
-		field_11_compressed_unicode_flag= in.readByte();        
-		if (this.isBuiltInName()) {
-		   field_12_builtIn_name = in.readByte();
-		} else {                
-		   if (field_11_compressed_unicode_flag == 1) {
-			 field_12_name_text = in.readUnicodeLEString(field_3_length_name_text);
-		   } else {
-			 field_12_name_text = in.readCompressedUnicode(field_3_length_name_text);
-		   }
-		}
-			
-		field_13_name_definition = Ptg.createParsedExpressionTokens(field_4_length_name_definition, in);
-	
+		field_1_option_flag                 = in.readShort();
+		field_2_keyboard_shortcut           = in.readByte();
+		int field_3_length_name_text        = in.readByte();
+		int field_4_length_name_definition  = in.readShort();
+		field_5_index_to_sheet              = in.readShort();
+		field_6_sheetNumber                 = in.readUShort();
+		int field_7_length_custom_menu      = in.readUByte();
+		int field_8_length_description_text = in.readUByte();
+		int field_9_length_help_topic_text  = in.readUByte();
+		int field_10_length_status_bar_text = in.readUByte();
+
+		//store the name in byte form if it's a built-in name
+		field_11_nameIsMultibyte = (in.readByte() != 0);
+		if (isBuiltInName()) {
+			field_12_built_in_code = in.readByte();
+		} else {
+			if (field_11_nameIsMultibyte) {
+				field_12_name_text = in.readUnicodeLEString(field_3_length_name_text);
+			} else {
+				field_12_name_text = in.readCompressedUnicode(field_3_length_name_text);
+			}
+		}
+
+		field_13_name_definition = Ptg.readTokens(field_4_length_name_definition, in);
+
 		//Who says that this can only ever be compressed unicode???
-		field_14_custom_menu_text       = in.readCompressedUnicode(LittleEndian.ubyteToInt(field_7_length_custom_menu));
-	
-		field_15_description_text       = in.readCompressedUnicode(LittleEndian.ubyteToInt(field_8_length_description_text));
-	
-		field_16_help_topic_text        = in.readCompressedUnicode(LittleEndian.ubyteToInt(field_9_length_help_topic_text));
-	
-		field_17_status_bar_text        = in.readCompressedUnicode(LittleEndian.ubyteToInt(field_10_length_status_bar_text));
-		/*} */
+		field_14_custom_menu_text = in.readCompressedUnicode(field_7_length_custom_menu);
+		field_15_description_text = in.readCompressedUnicode(field_8_length_description_text);
+		field_16_help_topic_text  = in.readCompressedUnicode(field_9_length_help_topic_text);
+		field_17_status_bar_text  = in.readCompressedUnicode(field_10_length_status_bar_text);
 	}
 
 	/**
@@ -742,113 +592,90 @@
 		return sid;
 	}
 	/*
-	  20 00 
-	  00 
-	  01 
+	  20 00
+	  00
+	  01
 	  1A 00 // sz = 0x1A = 26
-	  00 00 
-	  01 00 
-	  00 
-	  00 
-	  00 
-	  00 
+	  00 00
+	  01 00
+	  00
+	  00
+	  00
+	  00
 	  00 // unicode flag
 	  07 // name
-	  
+
 	  29 17 00 3B 00 00 00 00 FF FF 00 00 02 00 3B 00 //{ 26
 	  00 07 00 07 00 00 00 FF 00 10                   //  }
-	  
-	  
-	  
-	  20 00 
-	  00 
-	  01 
+
+
+
+	  20 00
+	  00
+	  01
 	  0B 00 // sz = 0xB = 11
-	  00 00 
-	  01 00 
-	  00 
-	  00 
-	  00 
-	  00 
+	  00 00
+	  01 00
+	  00
+	  00
+	  00
+	  00
 	  00 // unicode flag
 	  07 // name
-	  
+
 	  3B 00 00 07 00 07 00 00 00 FF 00   // { 11 }
   */
 	/*
-	  18, 00, 
-	  1B, 00, 
-	  
-	  20, 00, 
-	  00, 
-	  01, 
-	  0B, 00, 
-	  00, 
-	  00, 
-	  00, 
-	  00, 
-	  00, 
-	  07, 
-	  3B 00 00 07 00 07 00 00 00 FF 00 ]     
-	 */
+	  18, 00,
+	  1B, 00,
 
-	/**
-	 * @see Object#toString()
+	  20, 00,
+	  00,
+	  01,
+	  0B, 00,
+	  00,
+	  00,
+	  00,
+	  00,
+	  00,
+	  07,
+	  3B 00 00 07 00 07 00 00 00 FF 00 ]
 	 */
+
 	public String toString() {
-		StringBuffer buffer = new StringBuffer();
+		StringBuffer sb = new StringBuffer();
 
-		buffer.append("[NAME]\n");
-		buffer.append("    .option flags         = ").append( HexDump.toHex( field_1_option_flag ) )
-			.append("\n");
-		buffer.append("    .keyboard shortcut    = ").append( HexDump.toHex( field_2_keyboard_shortcut ) )
-			.append("\n");
-		buffer.append("    .length of the name   = ").append( field_3_length_name_text )
-			.append("\n");
-		buffer.append("    .size of the formula data = ").append( field_4_length_name_definition )
-			.append("\n");
-		buffer.append("    .unused                   = ").append( field_5_index_to_sheet )
-			.append("\n");
-		buffer.append("    .index to sheet (1-based, 0=Global)           = ").append( field_6_sheetNumber )
-			.append("\n");
-		buffer.append("    .Length of menu text (character count)        = ").append( field_7_length_custom_menu )
-			.append("\n");
-		buffer.append("    .Length of description text (character count) = ").append( field_8_length_description_text )
-			.append("\n");
-		buffer.append("    .Length of help topic text (character count)  = ").append( field_9_length_help_topic_text )
-			.append("\n");
-		buffer.append("    .Length of status bar text (character count)  = ").append( field_10_length_status_bar_text )
-			.append("\n");
-		buffer.append("    .Name (Unicode flag)  = ").append( field_11_compressed_unicode_flag )
-			.append("\n");
-		buffer.append("    .Name (Unicode text)  = ").append( getNameText() )
-			.append("\n");
-		
-		buffer.append("    .Parts (" + field_13_name_definition.size() +"):")
-			.append("\n");
-		Iterator it = field_13_name_definition.iterator();
-		while(it.hasNext()) {
-			Ptg ptg = (Ptg)it.next();
-			buffer.append("       " + ptg.toString()).append("\n");
-		}
-		
-		buffer.append("    .Menu text (Unicode string without length field)        = ").append( field_14_custom_menu_text )
-			.append("\n");
-		buffer.append("    .Description text (Unicode string without length field) = ").append( field_15_description_text )
-			.append("\n");
-		buffer.append("    .Help topic text (Unicode string without length field)  = ").append( field_16_help_topic_text )
-			.append("\n");
-		buffer.append("    .Status bar text (Unicode string without length field)  = ").append( field_17_status_bar_text )
-			.append("\n");
-		buffer.append("[/NAME]\n");
-		
-		return buffer.toString();
+		sb.append("[NAME]\n");
+		sb.append("    .option flags           = ").append(HexDump.shortToHex(field_1_option_flag)).append("\n");
+		sb.append("    .keyboard shortcut      = ").append(HexDump.byteToHex(field_2_keyboard_shortcut)).append("\n");
+		sb.append("    .length of the name     = ").append(getNameTextLength()).append("\n");
+		sb.append("    .unused                 = ").append( field_5_index_to_sheet ).append("\n");
+		sb.append("    .index to sheet (1-based, 0=Global) = ").append( field_6_sheetNumber ).append("\n");
+		sb.append("    .Menu text length       = ").append(field_14_custom_menu_text.length()).append("\n");
+		sb.append("    .Description text length= ").append(field_15_description_text.length()).append("\n");
+		sb.append("    .Help topic text length = ").append(field_16_help_topic_text.length()).append("\n");
+		sb.append("    .Status bar text length = ").append(field_17_status_bar_text.length()).append("\n");
+		sb.append("    .NameIsMultibyte        = ").append(field_11_nameIsMultibyte).append("\n");
+		sb.append("    .Name (Unicode text)    = ").append( getNameText() ).append("\n");
+		sb.append("    .Formula (nTokens=").append(field_13_name_definition.length).append("):") .append("\n");
+		for (int i = 0; i < field_13_name_definition.length; i++) {
+			Ptg ptg = field_13_name_definition[i];
+			sb.append("       " + ptg.toString()).append(ptg.getRVAType()).append("\n");
+		}
+
+		sb.append("    .Menu text       = ").append(field_14_custom_menu_text).append("\n");
+		sb.append("    .Description text= ").append(field_15_description_text).append("\n");
+		sb.append("    .Help topic text = ").append(field_16_help_topic_text).append("\n");
+		sb.append("    .Status bar text = ").append(field_17_status_bar_text).append("\n");
+		sb.append("[/NAME]\n");
+
+		return sb.toString();
 	}
 
 	/**Creates a human readable name for built in types
 	 * @return Unknown if the built-in name cannot be translated
 	 */
-	protected String translateBuiltInName(byte name)
+	private static String translateBuiltInName(byte name)
 	{
 		switch (name)
 		{
@@ -859,14 +686,15 @@
 			case NameRecord.BUILTIN_CONSOLIDATE_AREA :  return "Consolidate_Area";
 			case NameRecord.BUILTIN_CRITERIA :          return "Criteria";
 			case NameRecord.BUILTIN_DATABASE :          return "Database";
-			case NameRecord.BUILTIN_DATA_FORM :         return "Data_Form";            
+			case NameRecord.BUILTIN_DATA_FORM :         return "Data_Form";
 			case NameRecord.BUILTIN_PRINT_AREA :        return "Print_Area";
 			case NameRecord.BUILTIN_PRINT_TITLE :       return "Print_Titles";
 			case NameRecord.BUILTIN_RECORDER :          return "Recorder";
 			case NameRecord.BUILTIN_SHEET_TITLE :       return "Sheet_Title";
-			
+			case NameRecord.BUILTIN_FILTER_DB  :        return "_FilterDatabase";
+
 		}
-		
+
 		return "Unknown";
 	}
 }

Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/ArrayPtg.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/ArrayPtg.java?rev=692932&r1=692931&r2=692932&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/ArrayPtg.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/ArrayPtg.java Sun Sep  7 13:11:32 2008
@@ -94,10 +94,14 @@
 
 		buffer.append("columns = ").append(getColumnCount()).append("\n");
 		buffer.append("rows = ").append(getRowCount()).append("\n");
-		for (int x=0;x<getColumnCount();x++) {
-			for (int y=0;y<getRowCount();y++) {
-				Object o = token_3_arrayValues[getValueIndex(x, y)];
-	   			buffer.append("[").append(x).append("][").append(y).append("] = ").append(o).append("\n"); 
+		if (token_3_arrayValues == null) {
+			buffer.append("  #values#uninitialised#\n");
+		} else {
+			for (int x=0;x<getColumnCount();x++) {
+				for (int y=0;y<getRowCount();y++) {
+					Object o = token_3_arrayValues[getValueIndex(x, y)];
+					buffer.append("[").append(x).append("][").append(y).append("] = ").append(o).append("\n"); 
+				}
 			}
 		}
 		return buffer.toString();

Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/Ref3DPtg.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/Ref3DPtg.java?rev=692932&r1=692931&r2=692932&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/Ref3DPtg.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/Ref3DPtg.java Sun Sep  7 13:11:32 2008
@@ -41,7 +41,7 @@
     private static final BitField colRelative = BitFieldFactory.getInstance(0x4000);
 
     private final static int  SIZE = 7; // 6 + 1 for Ptg
-    private short             field_1_index_extern_sheet;
+    private int             field_1_index_extern_sheet;
     /** The row index - zero based unsigned 16 bit value */
     private int            field_2_row;
     /** Field 2 
@@ -93,10 +93,10 @@
     }
 
     public short getExternSheetIndex(){
-        return field_1_index_extern_sheet;
+        return (short)field_1_index_extern_sheet;
     }
 
-    public void setExternSheetIndex(short index){
+    public void setExternSheetIndex(int index){
         field_1_index_extern_sheet = index;
     }
 

Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/atp/AnalysisToolPak.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/atp/AnalysisToolPak.java?rev=692932&r1=692931&r2=692932&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/atp/AnalysisToolPak.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/atp/AnalysisToolPak.java Sun Sep  7 13:11:32 2008
@@ -109,8 +109,8 @@
 		r(m, "IMSUB", null);
 		r(m, "IMSUM", null);
 		r(m, "INTRATE", null);
-		r(m, "ISEVEN", null);
-		r(m, "ISODD", null);
+		r(m, "ISEVEN", ParityFunction.IS_EVEN);
+		r(m, "ISODD", ParityFunction.IS_ODD);
 		r(m, "LCM", null);
 		r(m, "MDURATION", null);
 		r(m, "MROUND", null);

Copied: poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/atp/ParityFunction.java (from r692893, poi/trunk/src/java/org/apache/poi/hssf/record/formula/atp/ParityFunction.java)
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/atp/ParityFunction.java?p2=poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/atp/ParityFunction.java&p1=poi/trunk/src/java/org/apache/poi/hssf/record/formula/atp/ParityFunction.java&r1=692893&r2=692932&rev=692932&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/formula/atp/ParityFunction.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/atp/ParityFunction.java Sun Sep  7 13:11:32 2008
@@ -25,8 +25,8 @@
 import org.apache.poi.hssf.record.formula.eval.OperandResolver;
 import org.apache.poi.hssf.record.formula.eval.ValueEval;
 import org.apache.poi.hssf.record.formula.functions.FreeRefFunction;
-import org.apache.poi.hssf.usermodel.HSSFSheet;
-import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.Workbook;
 /**
  * Implementation of Excel 'Analysis ToolPak' function ISEVEN() ISODD()<br/>
  * 
@@ -42,8 +42,8 @@
 		_desiredParity = desiredParity;
 	}
 
-	public ValueEval evaluate(Eval[] args, int srcCellRow, short srcCellCol, HSSFWorkbook workbook,
-			HSSFSheet sheet) {
+	public ValueEval evaluate(Eval[] args, int srcCellRow, short srcCellCol, Workbook workbook,
+			Sheet sheet) {
 		if (args.length != 1) {
 			return ErrorEval.VALUE_INVALID;  
 		}

Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/atp/YearFrac.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/atp/YearFrac.java?rev=692932&r1=692931&r2=692932&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/atp/YearFrac.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/atp/YearFrac.java Sun Sep  7 13:11:32 2008
@@ -21,6 +21,7 @@
 import java.util.GregorianCalendar;
 import java.util.regex.Pattern;
 
+import org.apache.poi.hssf.record.formula.eval.BlankEval;
 import org.apache.poi.hssf.record.formula.eval.ErrorEval;
 import org.apache.poi.hssf.record.formula.eval.Eval;
 import org.apache.poi.hssf.record.formula.eval.EvaluationException;
@@ -96,6 +97,9 @@
 			Calendar date = parseDate(strVal);
 			return DateUtil.getExcelDate(date, false);
 		}
+		if (ve instanceof BlankEval) {
+			return 0.0;
+		}
 		return OperandResolver.coerceValueToDouble(ve);
 	}
 
@@ -120,7 +124,7 @@
 		} catch (NumberFormatException e) {
 			throw new EvaluationException(ErrorEval.VALUE_INVALID);
 		}
-		if (f0<0 || f1<0 || f2<0 || f0>12 || f1>12 || f2>12) {
+		if (f0<0 || f1<0 || f2<0 || (f0>12 && f1>12 && f2>12)) {
 			// easy to see this cannot be a valid date
 			throw new EvaluationException(ErrorEval.VALUE_INVALID);
 		}
@@ -150,6 +154,7 @@
 		if (day <1 || day>cal.getActualMaximum(Calendar.DAY_OF_MONTH)) {
 			throw new EvaluationException(ErrorEval.VALUE_INVALID);
 		}
+		cal.set(Calendar.DAY_OF_MONTH, day);
 		return cal;
 	}
 

Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/eval/AddEval.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/eval/AddEval.java?rev=692932&r1=692931&r2=692932&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/eval/AddEval.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/eval/AddEval.java Sun Sep  7 13:11:32 2008
@@ -1,27 +1,22 @@
-/*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-* contributor license agreements.  See the NOTICE file distributed with
-* this work for additional information regarding copyright ownership.
-* The ASF licenses this file to You under the Apache License, Version 2.0
-* (the "License"); you may not use this file except in compliance with
-* the License.  You may obtain a copy of the License at
-*
-*     http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-/*
- * Created on May 8, 2005
- *
- */
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+
 package org.apache.poi.hssf.record.formula.eval;
 
-import org.apache.poi.hssf.record.formula.AddPtg;
-import org.apache.poi.hssf.record.formula.Ptg;
 
 /**
  * @author Amol S. Deshmukh &lt; amolweb at ya hoo dot com &gt;
@@ -37,58 +32,14 @@
  * <li> 1+A1 = 2 if A1 contains TRUE or =TRUE
  * <li> 1+A1 = #VALUE! if A1 contains "TRUE" or ="TRUE"
  */
-public class AddEval extends NumericOperationEval {
+public final class AddEval extends TwoOperandNumericOperation {
+
+	public static final OperationEval instance = new AddEval();
+
+	private AddEval() {
+	}
 
-    private AddPtg delegate;
-    private static final ValueEvalToNumericXlator NUM_XLATOR = 
-        new ValueEvalToNumericXlator((short)
-                ( ValueEvalToNumericXlator.BOOL_IS_PARSED 
-                | ValueEvalToNumericXlator.REF_BOOL_IS_PARSED
-                | ValueEvalToNumericXlator.STRING_IS_PARSED
-                | ValueEvalToNumericXlator.REF_STRING_IS_PARSED
-                ));
-
-    public AddEval(Ptg ptg) {
-        delegate = (AddPtg) ptg;
-    }
-
-    public ValueEvalToNumericXlator getXlator() {
-        return NUM_XLATOR;
-    }
-    
-    
-    public Eval evaluate(Eval[] args, int srcRow, short srcCol) {
-    	if(args.length != 2) {
-    		return ErrorEval.VALUE_INVALID;
-    	}
-    	
-        double d = 0;
-        for (int i = 0; i < 2; i++) {
-            ValueEval ve = singleOperandEvaluate(args[i], srcRow, srcCol);
-            if(ve instanceof ErrorEval) {
-				return ve;
-            }
-            if (ve instanceof NumericValueEval) {
-                d += ((NumericValueEval) ve).getNumberValue();
-            }
-            else if (ve instanceof BlankEval) {
-                // do nothing
-            }
-            else {
-                return ErrorEval.VALUE_INVALID;
-            }
-        }
-        if(Double.isNaN(d) || Double.isInfinite(d)) {
-        	return ErrorEval.NUM_ERROR;
-        }
-        return new NumberEval(d);
-    }
-
-    public int getNumberOfOperands() {
-        return delegate.getNumberOfOperands();
-    }
-
-    public int getType() {
-        return delegate.getType();
-    }
+	protected double evaluate(double d0, double d1) {
+		return d0 + d1;
+	}
 }

Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/eval/DivideEval.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/eval/DivideEval.java?rev=692932&r1=692931&r2=692932&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/eval/DivideEval.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/eval/DivideEval.java Sun Sep  7 13:11:32 2008
@@ -1,95 +1,36 @@
-/*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-* contributor license agreements.  See the NOTICE file distributed with
-* this work for additional information regarding copyright ownership.
-* The ASF licenses this file to You under the Apache License, Version 2.0
-* (the "License"); you may not use this file except in compliance with
-* the License.  You may obtain a copy of the License at
-*
-*     http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
 
 package org.apache.poi.hssf.record.formula.eval;
 
-import org.apache.poi.hssf.record.formula.Ptg;
-import org.apache.poi.hssf.record.formula.DividePtg;
-
 /**
  * @author Amol S. Deshmukh &lt; amolweb at ya hoo dot com &gt;
- *  
  */
-public final class DivideEval extends NumericOperationEval {
+public final class DivideEval extends TwoOperandNumericOperation {
+
+	public static final OperationEval instance = new DivideEval();
 
-    private DividePtg delegate;
+	private DivideEval() {
+	}
 
-    private static final ValueEvalToNumericXlator NUM_XLATOR = 
-        new ValueEvalToNumericXlator((short)
-                ( ValueEvalToNumericXlator.BOOL_IS_PARSED 
-                | ValueEvalToNumericXlator.REF_BOOL_IS_PARSED
-                | ValueEvalToNumericXlator.STRING_IS_PARSED
-                | ValueEvalToNumericXlator.REF_STRING_IS_PARSED
-                ));
-
-    public DivideEval(Ptg ptg) {
-        delegate = (DividePtg) ptg;
-    }
-    
-    protected ValueEvalToNumericXlator getXlator() {
-        return NUM_XLATOR;
-    }
-
-    public Eval evaluate(Eval[] args, int srcRow, short srcCol) {
-    	if(args.length != 2) {
-    		return ErrorEval.VALUE_INVALID;
-    	}
-        Eval retval = null;
-        double d0 = 0;
-        double d1 = 0;
-        ValueEval ve = singleOperandEvaluate(args[0], srcRow, srcCol);
-        if (ve instanceof NumericValueEval) {
-            d0 = ((NumericValueEval) ve).getNumberValue();
-        }
-        else if (ve instanceof BlankEval) {
-            // do nothing
-        }
-        else {
-            retval = ErrorEval.VALUE_INVALID;
-        }
-        
-        if (retval == null) { // no error yet
-            ve = singleOperandEvaluate(args[1], srcRow, srcCol);
-            if (ve instanceof NumericValueEval) {
-                d1 = ((NumericValueEval) ve).getNumberValue();
-            }
-            else if (ve instanceof BlankEval) {
-                // do nothing
-            }
-            else {
-                retval = ErrorEval.VALUE_INVALID;
-            }
-        }
-
-        if (retval == null) {
-            retval = (d1 == 0) 
-                ? ErrorEval.DIV_ZERO
-                : (Double.isNaN(d0) || Double.isNaN(d1)) 
-                    ? (ValueEval) ErrorEval.VALUE_INVALID 
-                    : new NumberEval(d0 / d1);
-        }
-        return retval;
-    }
-
-    public int getNumberOfOperands() {
-        return delegate.getNumberOfOperands();
-    }
-
-    public int getType() {
-        return delegate.getType();
-    }
+	protected double evaluate(double d0, double d1) throws EvaluationException {
+		if (d1 == 0.0) {
+			throw new EvaluationException(ErrorEval.DIV_ZERO);
+		}
+		return d0 / d1;
+	}
 }

Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/eval/EqualEval.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/eval/EqualEval.java?rev=692932&r1=692931&r2=692932&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/eval/EqualEval.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/eval/EqualEval.java Sun Sep  7 13:11:32 2008
@@ -1,67 +1,34 @@
-/*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-* contributor license agreements.  See the NOTICE file distributed with
-* this work for additional information regarding copyright ownership.
-* The ASF licenses this file to You under the Apache License, Version 2.0
-* (the "License"); you may not use this file except in compliance with
-* the License.  You may obtain a copy of the License at
-*
-*     http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-/*
- * Created on May 8, 2005
- *
- */
-package org.apache.poi.hssf.record.formula.eval;
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
 
-import org.apache.poi.hssf.record.formula.EqualPtg;
-import org.apache.poi.hssf.record.formula.Ptg;
+package org.apache.poi.hssf.record.formula.eval;
 
 /**
  * @author Amol S. Deshmukh &lt; amolweb at ya hoo dot com &gt;
  *  
  */
-public class EqualEval extends RelationalOperationEval {
-
-    private EqualPtg delegate;
+public final class EqualEval extends RelationalOperationEval {
 
-    public EqualEval(Ptg ptg) {
-        this.delegate = (EqualPtg) ptg;
-    }
-
-    
-    public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
-        ValueEval retval = null;
-        
-        RelationalValues rvs = super.doEvaluate(operands, srcRow, srcCol);
-        retval = rvs.ee;
-        int result = 0;
-        if (retval == null) {
-            result = doComparison(rvs.bs);
-            if (result == 0) {
-                result = doComparison(rvs.ss);
-            }
-            if (result == 0) {
-                result = doComparison(rvs.ds);
-            }
-
-            retval = (result == 0) ? BoolEval.TRUE : BoolEval.FALSE;
-        }
-
-        return retval;
-    }
-
-    public int getNumberOfOperands() {
-        return delegate.getNumberOfOperands();
-    }
-
-    public int getType() {
-        return delegate.getType();
-    }
+	public static final OperationEval instance = new EqualEval();
+	
+	private EqualEval() {
+	}
+
+	protected boolean convertComparisonResult(int cmpResult) {
+		return cmpResult == 0;
+	}
 }

Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/eval/ExternalFunction.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/eval/ExternalFunction.java?rev=692932&r1=692931&r2=692932&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/eval/ExternalFunction.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/eval/ExternalFunction.java Sun Sep  7 13:11:32 2008
@@ -42,7 +42,7 @@
 		FreeRefFunction targetFunc;
 		try {
 			if (nameArg instanceof NameEval) {
-				targetFunc = findInternalUserDefinedFunction(workbook, (NameEval) nameArg);
+				targetFunc = findInternalUserDefinedFunction((NameEval) nameArg);
 			} else if (nameArg instanceof NameXEval) {
 				targetFunc = findExternalUserDefinedFunction(workbook, (NameXEval) nameArg);
 			} else {
@@ -65,7 +65,7 @@
 		if(false) {
 			System.out.println("received call to external user defined function (" + functionName + ")");
 		}
-		// currently only looking for functions from the 'Analysis TookPak'
+		// currently only looking for functions from the 'Analysis TookPak'  e.g. "YEARFRAC" or "ISEVEN"
 		// not sure how much this logic would need to change to support other or multiple add-ins.
 		FreeRefFunction result = AnalysisToolPak.findFunction(functionName);
 		if (result != null) {
@@ -74,24 +74,12 @@
 		throw new EvaluationException(ErrorEval.FUNCTION_NOT_IMPLEMENTED);
 	}
 
-	private FreeRefFunction findInternalUserDefinedFunction(Workbook workbook, NameEval functionNameEval) throws EvaluationException {
-
-		int numberOfNames = workbook.getNumberOfNames();
-		
-		int nameIndex = functionNameEval.getIndex();
-		if(nameIndex < 0 || nameIndex >= numberOfNames) {
-			throw new RuntimeException("Bad name index (" + nameIndex 
-					+ "). Allowed range is (0.." + (numberOfNames-1) + ")");
-		}
-		
-		String functionName = workbook.getNameName(nameIndex);
+	private FreeRefFunction findInternalUserDefinedFunction(NameEval functionNameEval) throws EvaluationException {
+		String functionName = functionNameEval.getFunctionName();
 		if(false) {
 			System.out.println("received call to internal user defined function  (" + functionName + ")");
 		}
-		// TODO - detect if the NameRecord corresponds to a named range, function, or something undefined
-		// throw the right errors in these cases
-		
-		// TODO find the implementation for the external function e.g. "YEARFRAC" or "ISEVEN"
+		// TODO find the implementation for the user defined function
 		
 		throw new EvaluationException(ErrorEval.FUNCTION_NOT_IMPLEMENTED);
 	}

Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/eval/GreaterEqualEval.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/eval/GreaterEqualEval.java?rev=692932&r1=692931&r2=692932&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/eval/GreaterEqualEval.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/eval/GreaterEqualEval.java Sun Sep  7 13:11:32 2008
@@ -1,67 +1,34 @@
-/*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-* contributor license agreements.  See the NOTICE file distributed with
-* this work for additional information regarding copyright ownership.
-* The ASF licenses this file to You under the Apache License, Version 2.0
-* (the "License"); you may not use this file except in compliance with
-* the License.  You may obtain a copy of the License at
-*
-*     http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-/*
- * Created on May 8, 2005
- *
- */
-package org.apache.poi.hssf.record.formula.eval;
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
 
-import org.apache.poi.hssf.record.formula.GreaterEqualPtg;
-import org.apache.poi.hssf.record.formula.Ptg;
+package org.apache.poi.hssf.record.formula.eval;
 
 /**
  * @author Amol S. Deshmukh &lt; amolweb at ya hoo dot com &gt;
  *  
  */
-public class GreaterEqualEval extends RelationalOperationEval {
-
-    private GreaterEqualPtg delegate;
-
-    public GreaterEqualEval(Ptg ptg) {
-        this.delegate = (GreaterEqualPtg) ptg;
-    }
-
-    public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
-        ValueEval retval = null;
-        
-        RelationalValues rvs = super.doEvaluate(operands, srcRow, srcCol);
-        retval = rvs.ee;
-        int result = 0;
-        if (retval == null) {
-            result = doComparison(rvs.bs);
-            if (result == 0) {
-                result = doComparison(rvs.ss);
-            }
-            if (result == 0) {
-                result = doComparison(rvs.ds);
-            }
-
-            retval = (result >= 0) ? BoolEval.TRUE : BoolEval.FALSE;
-        }
-
-        return retval;
-    }
-
-    public int getNumberOfOperands() {
-        return delegate.getNumberOfOperands();
-    }
-
-    public int getType() {
-        return delegate.getType();
-    }
+public final class GreaterEqualEval extends RelationalOperationEval {
 
+	public static final OperationEval instance = new GreaterEqualEval();
+	
+	private GreaterEqualEval() {
+	}
+
+	protected boolean convertComparisonResult(int cmpResult) {
+		return cmpResult >= 0;
+	}
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org