poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject svn commit: r684213 [1/3] - in /poi/branches/ooxml: ./ src/documentation/content/xdocs/ src/java/org/apache/poi/hssf/model/ src/java/org/apache/poi/hssf/record/ src/java/org/apache/poi/hssf/record/aggregates/ src/java/org/apache/poi/hssf/record/formula...
Date Sat, 09 Aug 2008 09:52:37 GMT
Author: nick
Date: Sat Aug  9 02:52:35 2008
New Revision: 684213

URL: http://svn.apache.org/viewvc?rev=684213&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-683902 via svnmerge from 
https://svn.apache.org/repos/asf/poi/trunk

........
  r683758 | josh | 2008-08-08 00:49:10 +0100 (Fri, 08 Aug 2008) | 1 line
  
  Consolidating ValueRecordsAggregate within RowRecordsAggregate
........
  r683788 | josh | 2008-08-08 02:30:30 +0100 (Fri, 08 Aug 2008) | 1 line
  
  Converted RowRecordsAggregate to proper RecordAggregate
........
  r683871 | josh | 2008-08-08 07:27:06 +0100 (Fri, 08 Aug 2008) | 1 line
  
  Extracting PageSettingsBlock from Sheet
........
  r683880 | josh | 2008-08-08 07:56:06 +0100 (Fri, 08 Aug 2008) | 1 line
  
  Finished extracting PageSettingsBlock logic from Sheet
........
  r683901 | josh | 2008-08-08 09:05:07 +0100 (Fri, 08 Aug 2008) | 1 line
  
  Patch 45577 - Added implementations for Excel functions NOW and TODAY, added property getters to HSSFConditionalFormattingRule
........

Added:
    poi/branches/ooxml/src/java/org/apache/poi/hssf/record/aggregates/PageSettingsBlock.java
      - copied unchanged from r683901, poi/trunk/src/java/org/apache/poi/hssf/record/aggregates/PageSettingsBlock.java
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/hssf/model/RecordOrderer.java
    poi/branches/ooxml/src/java/org/apache/poi/hssf/model/RecordStream.java
    poi/branches/ooxml/src/java/org/apache/poi/hssf/model/Sheet.java
    poi/branches/ooxml/src/java/org/apache/poi/hssf/record/DBCellRecord.java
    poi/branches/ooxml/src/java/org/apache/poi/hssf/record/PrintSetupRecord.java
    poi/branches/ooxml/src/java/org/apache/poi/hssf/record/RowRecord.java
    poi/branches/ooxml/src/java/org/apache/poi/hssf/record/aggregates/RecordAggregate.java
    poi/branches/ooxml/src/java/org/apache/poi/hssf/record/aggregates/RowRecordsAggregate.java
    poi/branches/ooxml/src/java/org/apache/poi/hssf/record/aggregates/ValueRecordsAggregate.java
    poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/functions/Now.java
    poi/branches/ooxml/src/java/org/apache/poi/hssf/record/formula/functions/Today.java
    poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFCell.java
    poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFConditionalFormattingRule.java
    poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFRow.java
    poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java
    poi/branches/ooxml/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java
    poi/branches/ooxml/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Row.java
    poi/branches/ooxml/src/testcases/org/apache/poi/hssf/model/TestSheet.java
    poi/branches/ooxml/src/testcases/org/apache/poi/hssf/record/aggregates/TestValueRecordsAggregate.java
    poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/SanityChecker.java
    poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java
    poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestFormulas.java
    poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java
    poi/branches/ooxml/src/testcases/org/apache/poi/hssf/usermodel/TestWorkbook.java

Propchange: poi/branches/ooxml/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Sat Aug  9 02:52:35 2008
@@ -1 +1 @@
-/poi/trunk:1-638784,638786-639486,639488-639601,639603-640056,640058-642562,642564-642566,642568-642574,642576-642736,642739-650914,650916-683734
+/poi/trunk:1-638784,638786-639486,639488-639601,639603-640056,640058-642562,642564-642566,642568-642574,642576-642736,642739-650914,650916-683902

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=684213&r1=684212&r2=684213&view=diff
==============================================================================
--- poi/branches/ooxml/src/documentation/content/xdocs/changes.xml (original)
+++ poi/branches/ooxml/src/documentation/content/xdocs/changes.xml Sat Aug  9 02:52:35 2008
@@ -54,7 +54,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="add">45582 - Fix for workbook streams with extra bytes trailing the EOFRecord</action>
+           <action dev="POI-DEVELOPERS" type="add">45577 - Added implementations for Excel functions NOW and TODAY</action>
+           <action dev="POI-DEVELOPERS" type="fix">45582 - Fix for workbook streams with extra bytes trailing the EOFRecord</action>
            <action dev="POI-DEVELOPERS" type="add">45537 - Include headers and footers (of slides and notes) in the extracted text from HSLF</action>
            <action dev="POI-DEVELOPERS" type="fix">45472 - Fixed incorrect default row height in OpenOffice 2.3</action>
            <action dev="POI-DEVELOPERS" type="fix">44692 - HSSFPicture.resize() stretched image when there was a text next to it</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=684213&r1=684212&r2=684213&view=diff
==============================================================================
--- poi/branches/ooxml/src/documentation/content/xdocs/status.xml (original)
+++ poi/branches/ooxml/src/documentation/content/xdocs/status.xml Sat Aug  9 02:52:35 2008
@@ -51,7 +51,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="add">45582 - Fix for workbook streams with extra bytes trailing the EOFRecord</action>
+           <action dev="POI-DEVELOPERS" type="add">45577 - Added implementations for Excel functions NOW and TODAY</action>
+           <action dev="POI-DEVELOPERS" type="fix">45582 - Fix for workbook streams with extra bytes trailing the EOFRecord</action>
            <action dev="POI-DEVELOPERS" type="add">45537 - Include headers and footers (of slides and notes) in the extracted text from HSLF</action>
            <action dev="POI-DEVELOPERS" type="fix">45472 - Fixed incorrect default row height in OpenOffice 2.3</action>
            <action dev="POI-DEVELOPERS" type="fix">44692 - HSSFPicture.resize() stretched image when there was a text next to it</action>

Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/model/RecordOrderer.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/model/RecordOrderer.java?rev=684213&r1=684212&r2=684213&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/model/RecordOrderer.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/model/RecordOrderer.java Sat Aug  9 02:52:35 2008
@@ -29,7 +29,6 @@
 import org.apache.poi.hssf.record.EOFRecord;
 import org.apache.poi.hssf.record.GridsetRecord;
 import org.apache.poi.hssf.record.GutsRecord;
-import org.apache.poi.hssf.record.HorizontalPageBreakRecord;
 import org.apache.poi.hssf.record.HyperlinkRecord;
 import org.apache.poi.hssf.record.IndexRecord;
 import org.apache.poi.hssf.record.IterationRecord;
@@ -44,11 +43,11 @@
 import org.apache.poi.hssf.record.SaveRecalcRecord;
 import org.apache.poi.hssf.record.SelectionRecord;
 import org.apache.poi.hssf.record.UncalcedRecord;
-import org.apache.poi.hssf.record.VerticalPageBreakRecord;
 import org.apache.poi.hssf.record.WindowTwoRecord;
 import org.apache.poi.hssf.record.aggregates.ConditionalFormattingTable;
 import org.apache.poi.hssf.record.aggregates.DataValidityTable;
 import org.apache.poi.hssf.record.aggregates.MergedCellsTable;
+import org.apache.poi.hssf.record.aggregates.PageSettingsBlock;
 
 /**
  * Finds correct insert positions for records in workbook streams<p/>
@@ -88,28 +87,25 @@
 		if (recClass == GutsRecord.class) {
 			return getGutsRecordInsertPos(records);
 		}
-		if (recClass == HorizontalPageBreakRecord.class) {
-			return getPageBreakRecordInsertPos(records, true);
-		}
-		if (recClass == VerticalPageBreakRecord.class) {
-			return getPageBreakRecordInsertPos(records, false);
+		if (recClass == PageSettingsBlock.class) {
+			return getPageBreakRecordInsertPos(records);
 		}
 		throw new RuntimeException("Unexpected record class (" + recClass.getName() + ")");
 	}
 
-	private static int getPageBreakRecordInsertPos(List records, boolean isHorizonal) {
+	private static int getPageBreakRecordInsertPos(List records) {
 		int dimensionsIndex = getDimensionsIndex(records);
 		int i = dimensionsIndex-1;
 		while (i > 0) {
 			i--;
 			Object rb = records.get(i);
-			if (isPageBreakPriorRecord(rb, isHorizonal)) {
+			if (isPageBreakPriorRecord(rb)) {
 				return i+1;
 			}
 		}
 		throw new RuntimeException("Did not find insert point for GUTS");
 	}
-	private static boolean isPageBreakPriorRecord(Object rb, boolean newRecIsHorizontal) {
+	private static boolean isPageBreakPriorRecord(Object rb) {
 		if (rb instanceof Record) {
 			Record record = (Record) rb;
 			switch (record.getSid()) {
@@ -132,19 +128,7 @@
 				case DefaultRowHeightRecord.sid:
 				case 0x0081: // SHEETPR
 					return true;
-			}
-			switch (record.getSid()) {
-				// page settings block
-				case HorizontalPageBreakRecord.sid:
-					if (!newRecIsHorizontal) {
-						return true;
-					}
-					return false;
-				case VerticalPageBreakRecord.sid:
-					return false;
-	   			// next is case HeaderRecord.sid: case FooterRecord.sid:
-				// then more records in page settings block	
-			
+				// next is the 'Worksheet Protection Block'
 			}
 		}
 		return false;

Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/model/RecordStream.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/model/RecordStream.java?rev=684213&r1=684212&r2=684213&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/model/RecordStream.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/model/RecordStream.java Sat Aug  9 02:52:35 2008
@@ -59,6 +59,13 @@
 		return _list.get(_nextIndex).getClass();
 	}
 
+	public int peekNextSid() {
+		if(_nextIndex >= _list.size()) {
+			return -1;
+		}
+		return ((Record)_list.get(_nextIndex)).getSid();
+	}
+
 	public int getCountRead() {
 		return _countRead;
 	}

Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/model/Sheet.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/model/Sheet.java?rev=684213&r1=684212&r2=684213&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/model/Sheet.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/model/Sheet.java Sat Aug  9 02:52:35 2008
@@ -22,7 +22,6 @@
 import java.util.List;
 
 import org.apache.poi.hssf.record.BOFRecord;
-import org.apache.poi.hssf.record.BottomMarginRecord;
 import org.apache.poi.hssf.record.CFHeaderRecord;
 import org.apache.poi.hssf.record.CalcCountRecord;
 import org.apache.poi.hssf.record.CalcModeRecord;
@@ -37,52 +36,38 @@
 import org.apache.poi.hssf.record.DrawingRecord;
 import org.apache.poi.hssf.record.EOFRecord;
 import org.apache.poi.hssf.record.EscherAggregate;
-import org.apache.poi.hssf.record.FooterRecord;
 import org.apache.poi.hssf.record.GridsetRecord;
 import org.apache.poi.hssf.record.GutsRecord;
-import org.apache.poi.hssf.record.HCenterRecord;
-import org.apache.poi.hssf.record.HeaderRecord;
-import org.apache.poi.hssf.record.HorizontalPageBreakRecord;
 import org.apache.poi.hssf.record.IndexRecord;
 import org.apache.poi.hssf.record.IterationRecord;
-import org.apache.poi.hssf.record.LeftMarginRecord;
-import org.apache.poi.hssf.record.Margin;
 import org.apache.poi.hssf.record.MergeCellsRecord;
 import org.apache.poi.hssf.record.ObjRecord;
 import org.apache.poi.hssf.record.ObjectProtectRecord;
-import org.apache.poi.hssf.record.PageBreakRecord;
 import org.apache.poi.hssf.record.PaneRecord;
 import org.apache.poi.hssf.record.PasswordRecord;
 import org.apache.poi.hssf.record.PrintGridlinesRecord;
 import org.apache.poi.hssf.record.PrintHeadersRecord;
-import org.apache.poi.hssf.record.PrintSetupRecord;
 import org.apache.poi.hssf.record.ProtectRecord;
 import org.apache.poi.hssf.record.Record;
 import org.apache.poi.hssf.record.RecordBase;
 import org.apache.poi.hssf.record.RefModeRecord;
-import org.apache.poi.hssf.record.RightMarginRecord;
 import org.apache.poi.hssf.record.RowRecord;
 import org.apache.poi.hssf.record.SCLRecord;
 import org.apache.poi.hssf.record.SaveRecalcRecord;
 import org.apache.poi.hssf.record.ScenarioProtectRecord;
 import org.apache.poi.hssf.record.SelectionRecord;
-import org.apache.poi.hssf.record.SharedFormulaRecord;
 import org.apache.poi.hssf.record.StringRecord;
-import org.apache.poi.hssf.record.TopMarginRecord;
 import org.apache.poi.hssf.record.UncalcedRecord;
-import org.apache.poi.hssf.record.VCenterRecord;
-import org.apache.poi.hssf.record.VerticalPageBreakRecord;
 import org.apache.poi.hssf.record.WSBoolRecord;
 import org.apache.poi.hssf.record.WindowTwoRecord;
 import org.apache.poi.hssf.record.aggregates.CFRecordsAggregate;
 import org.apache.poi.hssf.record.aggregates.ColumnInfoRecordsAggregate;
 import org.apache.poi.hssf.record.aggregates.ConditionalFormattingTable;
 import org.apache.poi.hssf.record.aggregates.DataValidityTable;
-import org.apache.poi.hssf.record.aggregates.FormulaRecordAggregate;
 import org.apache.poi.hssf.record.aggregates.MergedCellsTable;
+import org.apache.poi.hssf.record.aggregates.PageSettingsBlock;
 import org.apache.poi.hssf.record.aggregates.RecordAggregate;
 import org.apache.poi.hssf.record.aggregates.RowRecordsAggregate;
-import org.apache.poi.hssf.record.aggregates.ValueRecordsAggregate;
 import org.apache.poi.hssf.record.aggregates.RecordAggregate.RecordVisitor;
 import org.apache.poi.ss.util.CellRangeAddress;
 import org.apache.poi.hssf.util.PaneInformation;
@@ -121,37 +106,33 @@
 
     protected ArrayList                  records           =     null;
               int                        preoffset         =     0;            // offset of the sheet in a new file
-              int                        loc               =     0;
     protected int                        dimsloc           =     -1;  // TODO - is it legal for dims record to be missing?
-    protected DimensionsRecord           dims;
+    protected PrintGridlinesRecord       printGridlines    =     null;
+    protected GridsetRecord              gridset           =     null;
+    private   GutsRecord                 _gutsRecord;
     protected DefaultColWidthRecord      defaultcolwidth   =     null;
     protected DefaultRowHeightRecord     defaultrowheight  =     null;
-    protected GridsetRecord              gridset           =     null;
-	private   GutsRecord                 _gutsRecord;
-    protected PrintSetupRecord           printSetup        =     null;
-    protected HeaderRecord               header            =     null;
-    protected FooterRecord               footer            =     null;
-    protected PrintGridlinesRecord       printGridlines    =     null;
+    private PageSettingsBlock _psBlock;
+
+    // 'Worksheet Protection Block'
+    protected ProtectRecord              protect           =     null;
+    protected ObjectProtectRecord        objprotect        =     null;
+    protected ScenarioProtectRecord      scenprotect       =     null;
+    protected PasswordRecord             password          =     null;
+    
     protected WindowTwoRecord            windowTwo         =     null;
-    protected Margin[]                   margins           =     null;
-    private   MergedCellsTable           _mergedCellsTable;
     protected SelectionRecord            selection         =     null;
+    private   MergedCellsTable           _mergedCellsTable;
     /** always present in this POI object, not always written to Excel file */
     /*package*/ColumnInfoRecordsAggregate _columnInfos;
-    protected ValueRecordsAggregate      cells             =     null;
+    protected DimensionsRecord           dims;
     protected RowRecordsAggregate        _rowsAggregate              =     null;
-    private   Iterator                   valueRecIterator  =     null;
-    private   Iterator                   rowRecIterator    =     null;
-    protected int                        eofLoc            =     0;
-    protected ProtectRecord              protect           =     null;
-    protected PageBreakRecord            _rowBreaksRecord;
-    protected PageBreakRecord            _columnBreaksRecord;
     private   DataValidityTable          _dataValidityTable=     null;
-    protected ObjectProtectRecord        objprotect        =     null;
-    protected ScenarioProtectRecord      scenprotect       =     null;
-    protected PasswordRecord             password          =     null;
     private   ConditionalFormattingTable condFormatting;
 
+    protected int                        eofLoc            =     0;
+    private   Iterator                   rowRecIterator    =     null;
+
     /** Add an UncalcedRecord if not true indicating formulas have not been calculated */
     protected boolean _isUncalced = false;
     
@@ -196,17 +177,8 @@
         boolean   isfirstcell        = true;
         int       bofEofNestingLevel = 0;
 
-        for (int k = offset; k < recs.size(); k++)
-        {
+        for (int k = offset; k < recs.size(); k++) {
             Record rec = ( Record ) recs.get(k);
-            if (rec.isValue() != (rec instanceof CellValueRecordInterface)) {
-            	if (rec instanceof SharedFormulaRecord) {
-            		
-            	} else {
-            	"".length();
-            	}
-            }
-
             if ( rec.getSid() == DBCellRecord.sid ) {
                 continue;
             }
@@ -239,23 +211,51 @@
                 retval._dataValidityTable = new DataValidityTable(rs);
                 k += rs.getCountRead() - 1; // TODO - convert this method result to be zero based
                 records.add(retval._dataValidityTable);
-                continue; // TODO
+                continue;
             }
-            if ( rec.getSid() == RowRecord.sid )
-            {
+            // TODO construct RowRecordsAggregate from RecordStream
+            if ( rec.getSid() == RowRecord.sid ) {
                 RowRecord row = (RowRecord)rec;
                 if (retval._rowsAggregate == null) {
                     retval._rowsAggregate = new RowRecordsAggregate();
                     records.add(retval._rowsAggregate); //only add the aggregate once
-				}
+                }
                 retval._rowsAggregate.insertRow(row);
                 continue;
             }
+            if ( rec.isValue() && bofEofNestingLevel == 1 ) {
+                if (isfirstcell) {
+                    isfirstcell = false;
+                    if (retval._rowsAggregate == null) {
+                        retval._rowsAggregate = new RowRecordsAggregate();
+                        records.add(retval._rowsAggregate); //only add the aggregate once
+                    }
+                    retval._rowsAggregate.constructCellValues( k, recs );
+                }
+               continue;
+            }
+             
+            if (PageSettingsBlock.isComponentRecord(rec.getSid())) {
+                RecordStream rs = new RecordStream(recs, k);
+                PageSettingsBlock psb = new PageSettingsBlock(rs);
+                if (bofEofNestingLevel == 1) {
+                    if (retval._psBlock == null) {
+                        retval._psBlock = psb;
+                    } else {
+                        // more than one 'Page Settings Block' at nesting level 1 ?
+                        // apparently this happens in about 15 test sample files
+                    }
+                }
+                records.add(psb);
+                k += rs.getCountRead()-1;
+                continue;
+            }
+            
             if (rec.getSid() == MergeCellsRecord.sid) {
                 RecordStream rs = new RecordStream(recs, k);
                 retval._mergedCellsTable = new MergedCellsTable(rs);
                 records.add(retval._mergedCellsTable);
-                continue; // TODO
+                continue;
             }
             
             if (rec.getSid() == BOFRecord.sid)
@@ -290,21 +290,7 @@
                 retval.dims    = ( DimensionsRecord ) rec;
                 retval.dimsloc = records.size();
             }
-            else if ( rec.isValue() && bofEofNestingLevel == 1 )
-            {
-                if ( isfirstcell )
-                {
-                    retval.cells = new ValueRecordsAggregate();
-                    rec = retval.cells;
-                    retval.cells.construct( k, recs );
-                    isfirstcell = false;
-                }
-                else
-                {
-                    rec = null;
-                }
-            }
-            else  if (rec.getSid() == DefaultColWidthRecord.sid)
+            else if (rec.getSid() == DefaultColWidthRecord.sid)
             {
                 retval.defaultcolwidth = ( DefaultColWidthRecord ) rec;
             }
@@ -320,34 +306,6 @@
             {
                 retval.gridset = (GridsetRecord) rec;
             }
-            else if ( rec.getSid() == HeaderRecord.sid && bofEofNestingLevel == 1)
-            {
-                retval.header = (HeaderRecord) rec;
-            }
-            else if ( rec.getSid() == FooterRecord.sid && bofEofNestingLevel == 1)
-            {
-                retval.footer = (FooterRecord) rec;
-            }
-            else if ( rec.getSid() == PrintSetupRecord.sid && bofEofNestingLevel == 1)
-            {
-                retval.printSetup = (PrintSetupRecord) rec;
-            }
-            else if ( rec.getSid() == LeftMarginRecord.sid)
-            {
-                retval.getMargins()[LeftMargin] = (LeftMarginRecord) rec;
-            }
-            else if ( rec.getSid() == RightMarginRecord.sid)
-            {
-                retval.getMargins()[RightMargin] = (RightMarginRecord) rec;
-            }
-            else if ( rec.getSid() == TopMarginRecord.sid)
-            {
-                retval.getMargins()[TopMargin] = (TopMarginRecord) rec;
-            }
-            else if ( rec.getSid() == BottomMarginRecord.sid)
-            {
-                retval.getMargins()[BottomMargin] = (BottomMarginRecord) rec;
-            }
             else if ( rec.getSid() == SelectionRecord.sid )
             {
                 retval.selection = (SelectionRecord) rec;
@@ -372,26 +330,14 @@
             {
                 retval.password = (PasswordRecord) rec;
             }
-            else if (rec.getSid() == HorizontalPageBreakRecord.sid)
-            {
-                retval._rowBreaksRecord = (HorizontalPageBreakRecord)rec;
-            }
-            else if (rec.getSid() == VerticalPageBreakRecord.sid)
-            {
-                retval._columnBreaksRecord = (VerticalPageBreakRecord)rec;
-            }
 
-            if (rec != null)
-            {
-                records.add(rec);
-            }
+            records.add(rec);
         }
         if (retval.dimsloc < 0) {
-        	throw new RuntimeException("DimensionsRecord was not found");
+            throw new RuntimeException("DimensionsRecord was not found");
         }
         retval.records = records;
         retval.checkRows();
-        retval.checkCells();
         if (log.check( POILogger.DEBUG ))
             log.log(POILogger.DEBUG, "sheet createSheet (existing file) exited");
         return retval;
@@ -399,15 +345,16 @@
 
     private static final class RecordCloner implements RecordVisitor {
 
-		private final List _destList;
+        private final List _destList;
 
-		public RecordCloner(List destList) {
-			_destList = destList;
-		}
-		public void visitRecord(Record r) {
-			_destList.add(r.clone());
-		}
+        public RecordCloner(List destList) {
+            _destList = destList;
+        }
+        public void visitRecord(Record r) {
+            _destList.add(r.clone());
+        }
     }
+
     /**
      * Clones the low level records of this sheet and returns the new sheet instance.
      * This method is implemented by adding methods for deep cloning to all records that
@@ -415,57 +362,18 @@
      * When adding a new record, implement a public clone method if and only if the record
      * belongs to a sheet.
      */
-    public Sheet cloneSheet()
-    {
-      ArrayList clonedRecords = new ArrayList(this.records.size());
-      for (int i=0; i<this.records.size();i++) {
-        RecordBase rb = (RecordBase) this.records.get(i);
-        if (rb instanceof RecordAggregate) {
-        	((RecordAggregate)rb).visitContainedRecords(new RecordCloner(clonedRecords));
-        	// TODO - make sure this logic works for the other RecordAggregates
-        	continue;
-        }
-		Record rec = (Record)((Record)rb).clone();
-        //Need to pull out the Row record and the Value records from their
-        //Aggregates.
-        //This is probably the best way to do it since we probably dont want the createSheet
-        //To cater for these artificial Record types
-        if (rec instanceof RowRecordsAggregate) {
-          RowRecordsAggregate rrAgg = (RowRecordsAggregate)rec;
-          for (Iterator rowIter = rrAgg.getIterator();rowIter.hasNext();) {
-            Record rowRec = (Record)rowIter.next();
-            clonedRecords.add(rowRec);
-          }
-        } else if (rec instanceof ValueRecordsAggregate) {
-          ValueRecordsAggregate vrAgg = (ValueRecordsAggregate)rec;
-          for (Iterator cellIter = vrAgg.getIterator();cellIter.hasNext();) {
-            Record valRec = (Record)cellIter.next();
-
-            if (valRec instanceof FormulaRecordAggregate) {
-                FormulaRecordAggregate fmAgg = (FormulaRecordAggregate)valRec;
-                Record fmAggRec = fmAgg.getFormulaRecord();
-                if (fmAggRec != null)
-                  clonedRecords.add(fmAggRec);
-                fmAggRec =   fmAgg.getStringRecord();
-                if (fmAggRec != null)
-                  clonedRecords.add(fmAggRec);
-              } else {
-                clonedRecords.add(valRec);
-              }
-          }
-        } else if (rec instanceof FormulaRecordAggregate) {  //Is this required now??
-          FormulaRecordAggregate fmAgg = (FormulaRecordAggregate)rec;
-          Record fmAggRec = fmAgg.getFormulaRecord();
-          if (fmAggRec != null)
-            clonedRecords.add(fmAggRec);
-          fmAggRec =   fmAgg.getStringRecord();
-          if (fmAggRec != null)
-            clonedRecords.add(fmAggRec);
-        } else {
-          clonedRecords.add(rec);
+    public Sheet cloneSheet() {
+        ArrayList clonedRecords = new ArrayList(this.records.size());
+        for (int i = 0; i < this.records.size(); i++) {
+            RecordBase rb = (RecordBase) this.records.get(i);
+            if (rb instanceof RecordAggregate) {
+                ((RecordAggregate) rb).visitContainedRecords(new RecordCloner(clonedRecords));
+                continue;
+            }
+            Record rec = (Record) ((Record) rb).clone();
+            clonedRecords.add(rec);
         }
-      }
-      return createSheet(clonedRecords, 0, 0);
+        return createSheet(clonedRecords, 0, 0);
     }
 
 
@@ -521,20 +429,9 @@
         records.add( retval.createWSBool() );
         
         // 'Page Settings Block'
-        retval._rowBreaksRecord = new HorizontalPageBreakRecord();
-        records.add(retval._rowBreaksRecord);
-        retval._columnBreaksRecord = new VerticalPageBreakRecord();
-        records.add(retval._columnBreaksRecord);
-
-        retval.header = createHeader();
-        records.add( retval.header );
-        retval.footer = createFooter();
-        records.add( retval.footer );
-        records.add(createHCenter() );
-        records.add(createVCenter() );
-        retval.printSetup = createPrintSetup();
-        records.add( retval.printSetup );
-
+        retval._psBlock = new PageSettingsBlock();
+        records.add(retval._psBlock);
+        
         // 'Worksheet Protection Block' (after 'Page Settings Block' and before DEFCOLWIDTH)
         // PROTECT record normally goes here, don't add yet since the flag is initially false
         
@@ -547,7 +444,6 @@
         records.add(retval.dims);
         retval.dimsloc = records.size()-1;
         records.add(retval.windowTwo = retval.createWindowTwo());
-        retval.setLoc(records.size() - 1);
         retval.selection = createSelection();
         records.add(retval.selection);
         records.add(EOFRecord.instance);
@@ -559,23 +455,6 @@
         return retval;
     }
 
-    private void checkCells()
-    {
-        if (cells == null)
-        {
-            cells = new ValueRecordsAggregate();
-            // In the worksheet stream, the row records always occur before the cell (value) 
-            // records. Therefore POI's aggregates (RowRecordsAggregate, ValueRecordsAggregate) 
-            // should follow suit. Some methods in this class tolerate either order, while 
-            // others have been found to fail (see bug 45145).
-            int rraIndex = getDimsLoc() + 1;
-            if (records.get(rraIndex).getClass() != RowRecordsAggregate.class) {
-                throw new IllegalStateException("Cannot create value records before row records exist");
-            }
-            records.add(rraIndex+1, cells);
-        }
-    }
-
     private void checkRows()
     {
         if (_rowsAggregate == null)
@@ -585,16 +464,16 @@
         }
     }
     private MergedCellsTable getMergedRecords() {
-    	if (_mergedCellsTable == null) {
-    		MergedCellsTable mct = new MergedCellsTable();
-    		RecordOrderer.addNewSheetRecord(records, mct);
-    		_mergedCellsTable = mct;
-    	}
-    	return _mergedCellsTable;
+        if (_mergedCellsTable == null) {
+            MergedCellsTable mct = new MergedCellsTable();
+            RecordOrderer.addNewSheetRecord(records, mct);
+            _mergedCellsTable = mct;
+        }
+        return _mergedCellsTable;
     }
 
 
-	public int addMergedRegion(int rowFrom, int colFrom, int rowTo, int colTo) {
+    public int addMergedRegion(int rowFrom, int colFrom, int rowTo, int colTo) {
         // Validate input
         if (rowTo < rowFrom) {
             throw new IllegalArgumentException("The 'to' row (" + rowTo
@@ -606,7 +485,7 @@
         }
 
         MergedCellsTable mrt = getMergedRecords();
-		mrt.addArea(rowFrom, colFrom, rowTo, colTo);
+        mrt.addArea(rowFrom, colFrom, rowTo, colTo);
         return mrt.getNumberOfMergedRegions()-1;
     }
 
@@ -614,44 +493,44 @@
     {
         //safety checks
         MergedCellsTable mrt = getMergedRecords();
-		if (index >= mrt.getNumberOfMergedRegions()) {
-			return;
-		}
-		mrt.remove(index);
+        if (index >= mrt.getNumberOfMergedRegions()) {
+            return;
+        }
+        mrt.remove(index);
     }
 
     public CellRangeAddress getMergedRegionAt(int index) {
         //safety checks
         MergedCellsTable mrt = getMergedRecords();
-		if (index >=  mrt.getNumberOfMergedRegions()) {
-			return null;
-		}
-		return mrt.get(index);
+        if (index >=  mrt.getNumberOfMergedRegions()) {
+            return null;
+        }
+        return mrt.get(index);
     }
 
     public int getNumMergedRegions() {
         return getMergedRecords().getNumberOfMergedRegions();
     }
     private ConditionalFormattingTable getConditionalFormattingTable() {
-    	if (condFormatting == null) {
-        	condFormatting = new ConditionalFormattingTable();
-        	RecordOrderer.addNewSheetRecord(records, condFormatting);
-    	}
-		return condFormatting;
+        if (condFormatting == null) {
+            condFormatting = new ConditionalFormattingTable();
+            RecordOrderer.addNewSheetRecord(records, condFormatting);
+        }
+        return condFormatting;
     }
 
 
-	public int addConditionalFormatting(CFRecordsAggregate cfAggregate) {
-		ConditionalFormattingTable cft = getConditionalFormattingTable();
+    public int addConditionalFormatting(CFRecordsAggregate cfAggregate) {
+        ConditionalFormattingTable cft = getConditionalFormattingTable();
         return cft.add(cfAggregate);
     }
 
     public void removeConditionalFormatting(int index) {
-    	getConditionalFormattingTable().remove(index);
+        getConditionalFormattingTable().remove(index);
     }
 
     public CFRecordsAggregate getCFRecordsAggregateAt(int index) {
-    	return getConditionalFormattingTable().get(index);
+        return getConditionalFormattingTable().get(index);
     }
 
     public int getNumConditionalFormattings() {
@@ -659,32 +538,6 @@
     }
 
     /**
-     * Returns the number of low level binary records in this sheet.  This adjusts things for the so called
-     * AgregateRecords.
-     *
-     * @see org.apache.poi.hssf.record.Record
-     */
-
-    public int getNumRecords()
-    {
-        checkCells();
-        checkRows();
-        if (log.check( POILogger.DEBUG ))
-        {
-            log.log(POILogger.DEBUG, "Sheet.getNumRecords");
-            log.logFormatted(POILogger.DEBUG, "returning % + % + % - 2 = %", new int[]
-            {
-                records.size(), cells.getPhysicalNumberOfCells(),
-                _rowsAggregate.getPhysicalNumberOfRows(),
-                records.size() + cells.getPhysicalNumberOfCells()
-                + _rowsAggregate.getPhysicalNumberOfRows() - 2
-            });
-        }
-        return records.size() + cells.getPhysicalNumberOfCells()
-               + _rowsAggregate.getPhysicalNumberOfRows() - 2;
-    }
-
-    /**
      * Per an earlier reported bug in working with Andy Khan's excel read library.  This
      * sets the values in the sheet's DimensionsRecord object to be correct.  Excel doesn't
      * really care, but we want to play nice with other libraries.
@@ -712,42 +565,6 @@
     }
 
     /**
-     * set the locator for where we should look for the next value record.  The
-     * algorithm will actually start here and find the correct location so you
-     * can set this to 0 and watch performance go down the tubes but it will work.
-     * After a value is set this is automatically advanced.  Its also set by the
-     * create method.  So you probably shouldn't mess with this unless you have
-     * a compelling reason why or the help for the method you're calling says so.
-     * Check the other methods for whether they care about
-     * the loc pointer.  Many of the "modify" and "remove" methods re-initialize this
-     * to "dimsloc" which is the location of the Dimensions Record and presumably the
-     * start of the value section (at or around 19 dec).
-     *
-     * @param loc the record number to start at
-     *
-     */
-
-    public void setLoc(int loc)
-    {
-        valueRecIterator = null;
-        if (log.check( POILogger.DEBUG ))
-            log.log(POILogger.DEBUG, "sheet.setLoc(): " + loc);
-        this.loc = loc;
-    }
-
-    /**
-     * Returns the location pointer to the first record to look for when adding rows/values
-     *
-     */
-
-    public int getLoc()
-    {
-        if (log.check( POILogger.DEBUG ))
-            log.log(POILogger.DEBUG, "sheet.getLoc():" + loc);
-        return loc;
-    }
-
-    /**
      * Set the preoffset when using DBCELL records (currently unused) - this is
      * the position of this sheet within the whole file.
      *
@@ -790,7 +607,7 @@
 
         for (int k = 0; k < records.size(); k++)
         {
-        	RecordBase record = (RecordBase) records.get(k);
+            RecordBase record = (RecordBase) records.get(k);
 
             // Don't write out UncalcedRecord entries, as
             //  we handle those specially just below
@@ -800,13 +617,7 @@
 
             // Once the rows have been found in the list of records, start
             //  writing out the blocked row information. This includes the DBCell references
-            if (record instanceof RowRecordsAggregate) {
-              pos += ((RowRecordsAggregate)record).serialize(pos, data, cells);
-            } else if (record instanceof ValueRecordsAggregate) {
-              //Do nothing here. The records were serialized during the RowRecordAggregate block serialization
-            } else {
-              pos += record.serialize(pos, data );
-            }
+            pos += record.serialize(pos, data);
 
             // If the BOF record was just serialized then add the IndexRecord
             if (record instanceof BOFRecord) {
@@ -838,13 +649,7 @@
      * @param indexRecordOffset also happens to be the end of the BOF record
      * @return the size of the serialized INDEX record
      */
-    private int serializeIndexRecord(final int bofRecordIndex, final int indexRecordOffset,
-            byte[] data) {
-        IndexRecord index = new IndexRecord();
-        index.setFirstRow(_rowsAggregate.getFirstRowNum());
-        index.setLastRowAdd1(_rowsAggregate.getLastRowNum() + 1);
-        // Calculate the size of the records from the end of the BOF
-        // and up to the RowRecordsAggregate...
+    private int serializeIndexRecord(int bofRecordIndex, int indexRecordOffset, byte[] data) {
 
         // 'initial sheet records' are between INDEX and first ROW record.
         int sizeOfInitialSheetRecords = 0;
@@ -862,32 +667,7 @@
         if (_isUncalced) {
             sizeOfInitialSheetRecords += UncalcedRecord.getStaticRecordSize();
         }
-
-        // Add the references to the DBCells in the IndexRecord (one for each block)
-        // Note: The offsets are relative to the Workbook BOF. Assume that this is
-        // 0 for now.....
-
-        int blockCount = _rowsAggregate.getRowBlockCount();
-        // Calculate the size of this IndexRecord
-        int indexRecSize = IndexRecord.getRecordSizeForBlockCount(blockCount);
-
-        int currentOffset = indexRecordOffset + indexRecSize + sizeOfInitialSheetRecords;
-
-        for (int block = 0; block < blockCount; block++) {
-            // each row-block has a DBCELL record.
-            // The offset of each DBCELL record needs to be updated in the INDEX record
-
-            // account for row records in this row-block
-            currentOffset += _rowsAggregate.getRowBlockSize(block);
-            // account for cell value records after those
-            currentOffset += null == cells ? 0 : cells.getRowCellBlockSize(_rowsAggregate
-                    .getStartRowNumberForBlock(block), _rowsAggregate.getEndRowNumberForBlock(block));
-
-            // currentOffset is now the location of the DBCELL record for this row-block
-            index.addDbcell(currentOffset);
-            // Add space required to write the DBCELL record (whose reference was just added).
-            currentOffset += (8 + (_rowsAggregate.getRowCountForBlock(block) * 2));
-        }
+        IndexRecord index = _rowsAggregate.createIndexRecord(indexRecordOffset, sizeOfInitialSheetRecords);
         return index.serialize(indexRecordOffset, data);
     }
 
@@ -911,15 +691,10 @@
      * @param row the row to add the cell value to
      * @param col the cell value record itself.
      */
-    public void addValueRecord(int row, CellValueRecordInterface col)
-    {
-        checkCells();
-        if(log.check(POILogger.DEBUG))
-        {
-          log.logFormatted(POILogger.DEBUG, "add value record  row,loc %,%", new int[]
-          {
-              row, loc
-          });
+    public void addValueRecord(int row, CellValueRecordInterface col) {
+
+        if(log.check(POILogger.DEBUG)) {
+          log.log(POILogger.DEBUG, "add value record  row" + row);
         }
         DimensionsRecord d = ( DimensionsRecord ) records.get(getDimsLoc());
 
@@ -931,7 +706,7 @@
         {
             d.setFirstCol(col.getColumn());
         }
-        cells.insertCell(col);
+        _rowsAggregate.insertCell(col);
     }
 
     /**
@@ -943,13 +718,11 @@
      * @param col - a record supporting the CellValueRecordInterface.
      * @see org.apache.poi.hssf.record.CellValueRecordInterface
      */
-    public void removeValueRecord(int row, CellValueRecordInterface col)
-    {
-        checkCells();
+    public void removeValueRecord(int row, CellValueRecordInterface col) {
+
         log.logFormatted(POILogger.DEBUG, "remove value record row,dimsloc %,%",
                          new int[]{row, dimsloc} );
-        loc = dimsloc;
-        cells.removeCell(col);
+        _rowsAggregate.removeCell(col);
     }
 
     /**
@@ -962,10 +735,8 @@
      *                be added.
      */
 
-    public void replaceValueRecord(CellValueRecordInterface newval)
-    {
-        checkCells();
-        setLoc(dimsloc);
+    public void replaceValueRecord(CellValueRecordInterface newval) {
+
         if (log.check( POILogger.DEBUG ))
             log.log(POILogger.DEBUG, "replaceValueRecord ");
         //The ValueRecordsAggregate use a tree map underneath.
@@ -973,8 +744,8 @@
         //key and the value, if we dont do a remove, then
         //the previous instance of the key is retained, effectively using
         //double the memory
-        cells.removeCell(newval);
-        cells.insertCell(newval);
+        _rowsAggregate.removeCell(newval);
+        _rowsAggregate.insertCell(newval);
     }
 
     /**
@@ -1005,11 +776,12 @@
         {
             d.setFirstRow(row.getRowNumber());
         }
-        //IndexRecord index = null;
-         //If the row exists remove it, so that any cells attached to the row are removed
-         RowRecord existingRow = _rowsAggregate.getRow(row.getRowNumber());
-         if (existingRow != null)
-           _rowsAggregate.removeRow(existingRow);
+
+        //If the row exists remove it, so that any cells attached to the row are removed
+        RowRecord existingRow = _rowsAggregate.getRow(row.getRowNumber());
+        if (existingRow != null) {
+            _rowsAggregate.removeRow(existingRow);
+        }
 
         _rowsAggregate.insertRow(row);
 
@@ -1024,12 +796,8 @@
      *
      * @param row  the row record to remove
      */
-
-    public void removeRow(RowRecord row)
-    {
+    public void removeRow(RowRecord row) {
         checkRows();
-
-        setLoc(getDimsLoc());
         _rowsAggregate.removeRow(row);
     }
 
@@ -1047,20 +815,8 @@
      * @return CellValueRecordInterface representing the next value record or NULL if there are no more
      * @see #setLoc(int)
      */
-
-    public CellValueRecordInterface getNextValueRecord()
-    {
-        if (log.check( POILogger.DEBUG ))
-            log.log(POILogger.DEBUG, "getNextValue loc= " + loc);
-        if (valueRecIterator == null)
-        {
-            valueRecIterator = cells.getIterator();
-        }
-        if (!valueRecIterator.hasNext())
-        {
-            return null;
-        }
-        return ( CellValueRecordInterface ) valueRecIterator.next();
+    public CellValueRecordInterface[] getValueRecords() {
+        return _rowsAggregate.getValueRecords();
     }
 
     /**
@@ -1077,11 +833,7 @@
      * @see #setLoc(int)
      *
      */
-
-    public RowRecord getNextRow()
-    {
-        if (log.check( POILogger.DEBUG ))
-            log.log(POILogger.DEBUG, "getNextRow loc= " + loc);
+    public RowRecord getNextRow() {
         if (rowRecIterator == null)
         {
             rowRecIterator = _rowsAggregate.getIterator();
@@ -1110,8 +862,6 @@
      *
      */
     public RowRecord getRow(int rownum) {
-        if (log.check( POILogger.DEBUG ))
-            log.log(POILogger.DEBUG, "getNextRow loc= " + loc);
         return _rowsAggregate.getRow(rownum);
     }
 
@@ -1235,13 +985,13 @@
         return retval;
     }
     private GutsRecord getGutsRecord() {
-    	if (_gutsRecord == null) {
-    		GutsRecord result = createGuts();
-    		RecordOrderer.addNewSheetRecord(records, result);
-			_gutsRecord = result;
-		}
+        if (_gutsRecord == null) {
+            GutsRecord result = createGuts();
+            RecordOrderer.addNewSheetRecord(records, result);
+            _gutsRecord = result;
+        }
 
-		return _gutsRecord;
+        return _gutsRecord;
     }
 
     /**
@@ -1266,70 +1016,6 @@
         return retval;
     }
 
-    /**
-     * creates the Header Record and sets it to nothing/0 length
-     */
-    private static HeaderRecord createHeader() {
-        HeaderRecord retval = new HeaderRecord();
-
-        retval.setHeaderLength(( byte ) 0);
-        retval.setHeader(null);
-        return retval;
-    }
-
-    /**
-     * creates the Footer Record and sets it to nothing/0 length
-     */
-    private static FooterRecord createFooter() {
-        FooterRecord retval = new FooterRecord();
-
-        retval.setFooterLength(( byte ) 0);
-        retval.setFooter(null);
-        return retval;
-    }
-
-    /**
-     * creates the HCenter Record and sets it to false (don't horizontally center)
-     */
-    private static HCenterRecord createHCenter() {
-        HCenterRecord retval = new HCenterRecord();
-
-        retval.setHCenter(false);
-        return retval;
-    }
-
-    /**
-     * creates the VCenter Record and sets it to false (don't horizontally center)
-    */
-    private static VCenterRecord createVCenter() {
-        VCenterRecord retval = new VCenterRecord();
-
-        retval.setVCenter(false);
-        return retval;
-    }
-
-    /**
-     * creates the PrintSetup Record and sets it to defaults and marks it invalid
-     * @see org.apache.poi.hssf.record.PrintSetupRecord
-     * @see org.apache.poi.hssf.record.Record
-     * @return record containing a PrintSetupRecord
-     */
-    private static PrintSetupRecord createPrintSetup() {
-        PrintSetupRecord retval = new PrintSetupRecord();
-
-        retval.setPaperSize(( short ) 1);
-        retval.setScale(( short ) 100);
-        retval.setPageStart(( short ) 1);
-        retval.setFitWidth(( short ) 1);
-        retval.setFitHeight(( short ) 1);
-        retval.setOptions(( short ) 2);
-        retval.setHResolution(( short ) 300);
-        retval.setVResolution(( short ) 300);
-        retval.setHeaderMargin( 0.5);
-        retval.setFooterMargin( 0.5);
-        retval.setCopies(( short ) 0);
-        return retval;
-    }
 
     /**
      * creates the DefaultColWidth Record and sets it to 8
@@ -1418,7 +1104,7 @@
 
         ColumnInfoRecord ci = _columnInfos.findColumnInfo(columnIndex);
         if (ci != null) {
-        	return ci.getColumnWidth();
+            return ci.getColumnWidth();
         }
         //default column width is measured in characters
         //multiply
@@ -1443,18 +1129,18 @@
         ColumnInfoRecord ci = _columnInfos.findColumnInfo(columnIndex);
         if (ci != null) {
             return ci.getXFIndex();
- 	    }
-	    return 0xF;
-	}
+         }
+        return 0xF;
+    }
 
     /**
-	 * set the width for a given column in 1/256th of a character width units
-	 * 
-	 * @param column -
-	 *            the column number
-	 * @param width
-	 *            (in units of 1/256th of a character width)
-	 */
+     * set the width for a given column in 1/256th of a character width units
+     * 
+     * @param column -
+     *            the column number
+     * @param width
+     *            (in units of 1/256th of a character width)
+     */
     public void setColumnWidth(short column, short width) {
         setColumn( column, new Short(width), null, null, null);
     }
@@ -1468,11 +1154,11 @@
      * @return whether the column is hidden or not.
      */
     public boolean isColumnHidden(short columnIndex) {
-    	ColumnInfoRecord cir = _columnInfos.findColumnInfo(columnIndex);
-    	if (cir == null) {
-    		return false;
-    	}
-    	return cir.getHidden();
+        ColumnInfoRecord cir = _columnInfos.findColumnInfo(columnIndex);
+        if (cir == null) {
+            return false;
+        }
+        return cir.getHidden();
     }
 
     /**
@@ -1659,12 +1345,8 @@
     /**
      * in the event the record is a dimensions record, resets both the loc index and dimsloc index
      */
-
-    public void checkDimsLoc(Record rec, int recloc)
-    {
-        if (rec.getSid() == DimensionsRecord.sid)
-        {
-            loc     = recloc;
+    public void checkDimsLoc(Record rec, int recloc) {
+        if (rec.getSid() == DimensionsRecord.sid) {
             dimsloc = recloc;
         }
     }
@@ -1672,32 +1354,21 @@
     /**
      * @return the serialized size of this sheet
      */
-    public int getSize()
-    {
+    public int getSize() {
         int retval = 0;
 
         for ( int k = 0; k < records.size(); k++) {
-        	RecordBase record = (RecordBase) records.get(k);
+            RecordBase record = (RecordBase) records.get(k);
             if (record instanceof UncalcedRecord) {
                 // skip the UncalcedRecord if present, it's only encoded if the isUncalced flag is set
                 continue;
             }
             retval += record.getRecordSize();
         }
+        // add space for IndexRecord if needed
         if (_rowsAggregate != null) {
-            // Add space for the IndexRecord and DBCell records
-            final int nBlocks = _rowsAggregate.getRowBlockCount();
-            int nRows = 0;
-            if (cells != null) {
-                for (Iterator itr = _rowsAggregate.getIterator(); itr.hasNext();) {
-                    RowRecord row = (RowRecord)itr.next();
-                    if (cells.rowHasCells(row.getRowNumber())) {
-                        nRows++;
-                    }
-                }
-            }
-            retval += IndexRecord.getRecordSizeForBlockCount(nBlocks);
-            retval += DBCellRecord.calculateSizeOfRecords(nBlocks, nRows);
+            // rowsAggregate knows how to make the index record
+            retval += IndexRecord.getRecordSizeForBlockCount(_rowsAggregate.getRowBlockCount());
         }
         // Add space for UncalcedRecord
         if (_isUncalced) {
@@ -1726,11 +1397,11 @@
 
     public Record findFirstRecordBySid(short sid)
     {
-    	int ix = findFirstRecordLocBySid(sid);
-    	if (ix < 0) {
-    		return null;
-    	}
-    	return (Record) records.get(ix);
+        int ix = findFirstRecordLocBySid(sid);
+        if (ix < 0) {
+            return null;
+        }
+        return (Record) records.get(ix);
     }
 
     /**
@@ -1765,9 +1436,9 @@
     public int findFirstRecordLocBySid( short sid ) { // TODO - remove this method
         int max = records.size();
         for (int i=0; i< max; i++) {
-        	Object rb = records.get(i);
+            Object rb = records.get(i);
             if (!(rb instanceof Record)) {
-            	continue;
+                continue;
             }
             Record record = (Record) rb;
             if (record.getSid() == sid) {
@@ -1777,63 +1448,10 @@
         return -1;
     }
 
-    /**
-     * Returns the HeaderRecord.
-     * @return HeaderRecord for the sheet.
-     */
-    public HeaderRecord getHeader ()
-    {
-    return header;
-    }
-
     public WindowTwoRecord getWindowTwo() {
         return windowTwo;
     }
-    /**
-     * Sets the HeaderRecord.
-     * @param newHeader The new HeaderRecord for the sheet.
-     */
-    public void setHeader (HeaderRecord newHeader)
-    {
-        header = newHeader;
-    }
-
-    /**
-     * Returns the FooterRecord.
-     * @return FooterRecord for the sheet.
-     */
-    public FooterRecord getFooter ()
-    {
-        return footer;
-    }
-
-    /**
-     * Sets the FooterRecord.
-     * @param newFooter The new FooterRecord for the sheet.
-     */
-    public void setFooter (FooterRecord newFooter)
-    {
-        footer = newFooter;
-    }
-
-    /**
-     * Returns the PrintSetupRecord.
-     * @return PrintSetupRecord for the sheet.
-     */
-    public PrintSetupRecord getPrintSetup ()
-    {
-        return printSetup;
-    }
-
-    /**
-     * Sets the PrintSetupRecord.
-     * @param newPrintSetup The new PrintSetupRecord for the sheet.
-     */
-    public void setPrintSetup (PrintSetupRecord newPrintSetup)
-    {
-        printSetup = newPrintSetup;
-    }
-
+ 
     /**
      * Returns the PrintGridlinesRecord.
      * @return PrintGridlinesRecord for the sheet.
@@ -1860,65 +1478,6 @@
         windowTwo.setSelected(sel);
     }
 
-     /**
-      * Gets the size of the margin in inches.
-      * @param margin which margin to get
-      * @return the size of the margin
-      */
-    public double getMargin(short margin) {
-    if (getMargins()[margin] != null)
-        return margins[margin].getMargin();
-    else {
-        switch ( margin )
-        {
-        case LeftMargin:
-            return .75;
-        case RightMargin:
-            return .75;
-        case TopMargin:
-            return 1.0;
-        case BottomMargin:
-            return 1.0;
-        default :
-            throw new RuntimeException( "Unknown margin constant:  " + margin );
-        }
-    }
-    }
-
-     /**
-      * Sets the size of the margin in inches.
-      * @param margin which margin to get
-      * @param size the size of the margin
-      */
-    public void setMargin(short margin, double size) {
-    Margin m = getMargins()[margin];
-    if (m  == null) {
-        switch ( margin )
-        {
-        case LeftMargin:
-            m = new LeftMarginRecord();
-            records.add( getDimsLoc() + 1, m );
-            break;
-        case RightMargin:
-            m = new RightMarginRecord();
-            records.add( getDimsLoc() + 1, m );
-            break;
-        case TopMargin:
-            m = new TopMarginRecord();
-            records.add( getDimsLoc() + 1, m );
-            break;
-        case BottomMargin:
-            m = new BottomMarginRecord();
-            records.add( getDimsLoc() + 1, m );
-            break;
-        default :
-            throw new RuntimeException( "Unknown margin constant:  " + margin );
-        }
-        margins[margin] = m;
-    }
-    m.setMargin( size );
-    }
-
     public int getEofLoc()
     {
         return eofLoc;
@@ -2095,8 +1654,8 @@
      */
     private static PasswordRecord createPassword() {
         if (log.check( POILogger.DEBUG )) {
-			log.log(POILogger.DEBUG, "create password record with 00 password");
-		}
+            log.log(POILogger.DEBUG, "create password record with 00 password");
+        }
         PasswordRecord retval = new PasswordRecord();
 
         retval.setPassword((short)00);
@@ -2168,17 +1727,6 @@
     }
 
     /**
-     * Returns the array of margins.  If not created, will create.
-     *
-     * @return the array of marings.
-     */
-    protected Margin[] getMargins() {
-        if (margins == null)
-            margins = new Margin[4];
-        return margins;
-    }
-
-    /**
      * Finds the DrawingRecord for our sheet, and
      *  attaches it to the DrawingManager (which knows about
      *  the overall DrawingGroup for our workbook).
@@ -2246,153 +1794,16 @@
         }
     }
 
-    /**
-     * Shifts all the page breaks in the range "count" number of rows/columns
-     * @param breaks The page record to be shifted
-     * @param start Starting "main" value to shift breaks
-     * @param stop Ending "main" value to shift breaks
-     * @param count number of units (rows/columns) to shift by
-     */
-    private static void shiftBreaks(PageBreakRecord breaks, int start, int stop, int count) {
-
-        Iterator iterator = breaks.getBreaksIterator();
-        List shiftedBreak = new ArrayList();
-        while(iterator.hasNext())
-        {
-            PageBreakRecord.Break breakItem = (PageBreakRecord.Break)iterator.next();
-            int breakLocation = breakItem.main;
-            boolean inStart = (breakLocation >= start);
-            boolean inEnd = (breakLocation <= stop);
-            if(inStart && inEnd)
-                shiftedBreak.add(breakItem);
-        }
-
-        iterator = shiftedBreak.iterator();
-        while (iterator.hasNext()) {
-            PageBreakRecord.Break breakItem = (PageBreakRecord.Break)iterator.next();
-            breaks.removeBreak(breakItem.main);
-            breaks.addBreak((short)(breakItem.main+count), breakItem.subFrom, breakItem.subTo);
-        }
-    }
-
-    private PageBreakRecord getRowBreaksRecord() {
-    	if (_rowBreaksRecord == null) {
-			_rowBreaksRecord = new HorizontalPageBreakRecord();
-			RecordOrderer.addNewSheetRecord(records, _rowBreaksRecord);
-			dimsloc++;
-		}
-		return _rowBreaksRecord;
-    }
-    
-    private PageBreakRecord getColumnBreaksRecord() {
-    	if (_columnBreaksRecord == null) {
-    		_columnBreaksRecord = new VerticalPageBreakRecord();
-			RecordOrderer.addNewSheetRecord(records, _columnBreaksRecord);
-			dimsloc++;
-		}
-		return _columnBreaksRecord;
-    }
-    
     
-    /**
-     * Sets a page break at the indicated row
-     * @param row
-     */
-    public void setRowBreak(int row, short fromCol, short toCol) {
-        getRowBreaksRecord().addBreak((short)row, fromCol, toCol);
-    }
-
-    /**
-     * Removes a page break at the indicated row
-     * @param row
-     */
-    public void removeRowBreak(int row) {
-        if (getRowBreaks() == null)
-            throw new IllegalArgumentException("Sheet does not define any row breaks");
-        getRowBreaksRecord().removeBreak((short)row);
-    }
-
-    /**
-     * Queries if the specified row has a page break
-     * @param row
-     * @return true if the specified row has a page break
-     */
-    public boolean isRowBroken(int row) {
-        return getRowBreaksRecord().getBreak(row) != null;
-    }
-
-    /**
-     * Sets a page break at the indicated column
-     *
-     */
-    public void setColumnBreak(short column, short fromRow, short toRow) {
-        getColumnBreaksRecord().addBreak(column, fromRow, toRow);
-    }
-
-    /**
-     * Removes a page break at the indicated column
-     *
-     */
-    public void removeColumnBreak(short column) {
-    	getColumnBreaksRecord().removeBreak(column);
-    }
-
-    /**
-     * Queries if the specified column has a page break
-     *
-     * @return <code>true</code> if the specified column has a page break
-     */
-    public boolean isColumnBroken(short column) {
-        return getColumnBreaksRecord().getBreak(column) != null;
-    }
-
-    /**
-     * Shifts the horizontal page breaks for the indicated count
-     * @param startingRow
-     * @param endingRow
-     * @param count
-     */
-    public void shiftRowBreaks(int startingRow, int endingRow, int count) {
-        shiftBreaks(getRowBreaksRecord(), startingRow, endingRow, count);
-    }
-
-    /**
-     * Shifts the vertical page breaks for the indicated count
-     * @param startingCol
-     * @param endingCol
-     * @param count
-     */
-    public void shiftColumnBreaks(short startingCol, short endingCol, short count) {
-        shiftBreaks(getColumnBreaksRecord(), startingCol, endingCol, count);
-    }
-
-    /**
-     * @return all the horizontal page breaks, never <code>null</code>
-     */
-    public int[] getRowBreaks() {
-        return getRowBreaksRecord().getBreaks();
-    }
-
-    /**
-     * @return the number of row page breaks
-     */
-    public int getNumRowBreaks(){
-        return getRowBreaksRecord().getNumBreaks();
-    }
-
-    /**
-     * @return all the column page breaks, never <code>null</code>
-     */
-    public int[] getColumnBreaks(){
-        return getColumnBreaksRecord().getBreaks();
+    public PageSettingsBlock getPageSettings() {
+        if (_psBlock == null) {
+            _psBlock = new PageSettingsBlock();
+            RecordOrderer.addNewSheetRecord(records, _psBlock);
+            dimsloc++;
+        }
+        return _psBlock;
     }
 
-    /**
-     * @return the number of column page breaks
-     */
-    public int getNumColumnBreaks(){
-        return getColumnBreaksRecord().getNumBreaks();
-    }
 
     public void setColumnGroupCollapsed( short columnNumber, boolean collapsed )
     {
@@ -2520,8 +1931,8 @@
     }
     public DataValidityTable getOrCreateDataValidityTable() {
         if (_dataValidityTable == null) {
-    		DataValidityTable result = new DataValidityTable();
-    		RecordOrderer.addNewSheetRecord(records, result);
+            DataValidityTable result = new DataValidityTable();
+            RecordOrderer.addNewSheetRecord(records, result);
             _dataValidityTable = result;
         }
         return _dataValidityTable;

Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/record/DBCellRecord.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/record/DBCellRecord.java?rev=684213&r1=684212&r2=684213&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/record/DBCellRecord.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/record/DBCellRecord.java Sat Aug  9 02:52:35 2008
@@ -35,6 +35,7 @@
 
     public DBCellRecord()
     {
+        field_2_cell_offsets = new short[0];
     }
 
     /**
@@ -185,4 +186,9 @@
     {
         return true;
     }
+    public Object clone() {
+        // TODO - make immutable.
+        // this should be safe because only the instantiating code mutates these objects
+        return this;
+    }
 }

Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/record/PrintSetupRecord.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/record/PrintSetupRecord.java?rev=684213&r1=684212&r2=684213&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/record/PrintSetupRecord.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/record/PrintSetupRecord.java Sat Aug  9 02:52:35 2008
@@ -1,4 +1,3 @@
-
 /* ====================================================================
    Licensed to the Apache Software Foundation (ASF) under one or more
    contributor license agreements.  See the NOTICE file distributed with
@@ -15,7 +14,6 @@
    See the License for the specific language governing permissions and
    limitations under the License.
 ==================================================================== */
-        
 
 package org.apache.poi.hssf.record;
 
@@ -24,18 +22,15 @@
 import org.apache.poi.util.BitFieldFactory;
 
 /**
- * Title:        Print Setup Record<P>
- * Description:  Stores print setup options -- bogus for HSSF (and marked as such)<P>
- * REFERENCE:  PG 385 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P>
+ * Title:        PAGESETUP (0x00A1)<p/>
+ * Description:  Stores print setup options -- bogus for HSSF (and marked as such)<p/>
+ * REFERENCE:  PG 385 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<p/>
  * @author Andrew C. Oliver (acoliver at apache dot org)
  * @author Jason Height (jheight at chariot dot net dot au)
  * @version 2.0-pre
  */
-
-public class PrintSetupRecord
-    extends Record
-{
-    public final static short     sid = 0xa1;
+public class PrintSetupRecord extends Record {
+    public final static short     sid = 0x00A1;
     private short                 field_1_paper_size;
     private short                 field_2_scale;
     private short                 field_3_page_start;

Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/record/RowRecord.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/record/RowRecord.java?rev=684213&r1=684212&r2=684213&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/record/RowRecord.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/record/RowRecord.java Sat Aug  9 02:52:35 2008
@@ -22,15 +22,17 @@
 import org.apache.poi.util.LittleEndian;
 
 /**
- * Title:        Row Record<P>
- * Description:  stores the row information for the sheet. <P>
+ * Title:        Row Record (0x0208)<P/>
+ * Description:  stores the row information for the sheet. <P/>
  * REFERENCE:  PG 379 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P>
  * @author Andrew C. Oliver (acoliver at apache dot org)
  * @author Jason Height (jheight at chariot dot net dot au)
  * @version 2.0-pre
  */
 public final class RowRecord extends Record implements Comparable {
-	public final static short sid = 0x208;
+    public final static short sid = 0x0208;
+
+    public static final int ENCODED_SIZE = 20;
     
     private static final int OPTION_BITS_ALWAYS_SET = 0x0100;
     private static final int DEFAULT_HEIGHT_BIT = 0x8000;
@@ -407,23 +409,23 @@
 
     public int serialize(int offset, byte [] data)
     {
-        LittleEndian.putShort(data, 0 + offset, sid);
-        LittleEndian.putShort(data, 2 + offset, ( short ) 16);
-        LittleEndian.putShort(data, 4 + offset, ( short ) getRowNumber());
-        LittleEndian.putShort(data, 6 + offset, getFirstCol() == -1 ? (short)0 : getFirstCol());
-        LittleEndian.putShort(data, 8 + offset, getLastCol() == -1 ? (short)0 : getLastCol());
-        LittleEndian.putShort(data, 10 + offset, getHeight());
-        LittleEndian.putShort(data, 12 + offset, getOptimize());
-        LittleEndian.putShort(data, 14 + offset, field_6_reserved);
-        LittleEndian.putShort(data, 16 + offset, getOptionFlags());
+        LittleEndian.putUShort(data, 0 + offset, sid);
+        LittleEndian.putUShort(data, 2 + offset, ENCODED_SIZE - 4);
+        LittleEndian.putUShort(data, 4 + offset, getRowNumber());
+        LittleEndian.putUShort(data, 6 + offset, getFirstCol() == -1 ? (short)0 : getFirstCol());
+        LittleEndian.putUShort(data, 8 + offset, getLastCol() == -1 ? (short)0 : getLastCol());
+        LittleEndian.putUShort(data, 10 + offset, getHeight());
+        LittleEndian.putUShort(data, 12 + offset, getOptimize());
+        LittleEndian.putUShort(data, 14 + offset, field_6_reserved);
+        LittleEndian.putUShort(data, 16 + offset, getOptionFlags());
 
-        LittleEndian.putShort(data, 18 + offset, getXFIndex());
-        return getRecordSize();
+        LittleEndian.putUShort(data, 18 + offset, getXFIndex());
+        return ENCODED_SIZE;
     }
 
     public int getRecordSize()
     {
-        return 20;
+        return ENCODED_SIZE;
     }
 
     public short getSid()

Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/record/aggregates/RecordAggregate.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/record/aggregates/RecordAggregate.java?rev=684213&r1=684212&r2=684213&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/record/aggregates/RecordAggregate.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/record/aggregates/RecordAggregate.java Sat Aug  9 02:52:35 2008
@@ -54,6 +54,10 @@
 	}
 	
 	public interface RecordVisitor {
+		/**
+		 * Implementors may call non-mutating methods on Record r.
+		 * @param r must not be <code>null</code>
+		 */
 		void visitRecord(Record r);
 	}
 	

Modified: poi/branches/ooxml/src/java/org/apache/poi/hssf/record/aggregates/RowRecordsAggregate.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/hssf/record/aggregates/RowRecordsAggregate.java?rev=684213&r1=684212&r2=684213&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/hssf/record/aggregates/RowRecordsAggregate.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/hssf/record/aggregates/RowRecordsAggregate.java Sat Aug  9 02:52:35 2008
@@ -1,4 +1,3 @@
-
 /* ====================================================================
    Licensed to the Apache Software Foundation (ASF) under one or more
    contributor license agreements.  See the NOTICE file distributed with
@@ -16,85 +15,88 @@
    limitations under the License.
 ==================================================================== */
 
-
 package org.apache.poi.hssf.record.aggregates;
 
-import org.apache.poi.hssf.record.DBCellRecord;
-import org.apache.poi.hssf.record.Record;
-import org.apache.poi.hssf.record.RecordInputStream;
-import org.apache.poi.hssf.record.RowRecord;
-
-
+import java.util.ArrayList;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 import java.util.TreeMap;
 
+import org.apache.poi.hssf.record.CellValueRecordInterface;
+import org.apache.poi.hssf.record.DBCellRecord;
+import org.apache.poi.hssf.record.IndexRecord;
+import org.apache.poi.hssf.record.Record;
+import org.apache.poi.hssf.record.RowRecord;
+
 /**
  *
  * @author  andy
  * @author Jason Height (jheight at chariot dot net dot au)
  */
-
-public final class RowRecordsAggregate extends Record {
-    private int     firstrow = -1;
-    private int     lastrow  = -1;
-    private Map records  = null; // TODO - use a proper key in this map
-    private int     size     = 0;
+public final class RowRecordsAggregate extends RecordAggregate {
+    private int _firstrow = -1;
+    private int _lastrow  = -1;
+    private final Map _rowRecords;
+    private final ValueRecordsAggregate _valuesAgg;
 
     /** Creates a new instance of ValueRecordsAggregate */
 
-    public RowRecordsAggregate()
-    {
-        records = new TreeMap();  
+    public RowRecordsAggregate() {
+        this(new TreeMap(), new ValueRecordsAggregate());
+    }
+    private RowRecordsAggregate(TreeMap rowRecords, ValueRecordsAggregate valuesAgg) {
+        _rowRecords = rowRecords;
+        _valuesAgg = valuesAgg;
     }
 
-    public void insertRow(RowRecord row)
-    {
-        size += row.getRecordSize();
-
+    public void insertRow(RowRecord row) {
         // Integer integer = new Integer(row.getRowNumber());
-        records.put(row, row);
-        if ((row.getRowNumber() < firstrow) || (firstrow == -1))
+        _rowRecords.put(new Integer(row.getRowNumber()), row);
+        if ((row.getRowNumber() < _firstrow) || (_firstrow == -1))
         {
-            firstrow = row.getRowNumber();
+            _firstrow = row.getRowNumber();
         }
-        if ((row.getRowNumber() > lastrow) || (lastrow == -1))
+        if ((row.getRowNumber() > _lastrow) || (_lastrow == -1))
         {
-            lastrow = row.getRowNumber();
+            _lastrow = row.getRowNumber();
         }
     }
 
-    public void removeRow(RowRecord row)
-    {
-        size -= row.getRecordSize();
-
-        // Integer integer = new Integer(row.getRowNumber());
-        records.remove(row);
+    public void removeRow(RowRecord row) {
+        int rowIndex = row.getRowNumber();
+        _valuesAgg.removeAllCellsValuesForRow(rowIndex);
+        Integer key = new Integer(rowIndex);
+        RowRecord rr = (RowRecord) _rowRecords.remove(key);
+        if (rr == null) {
+            throw new RuntimeException("Invalid row index (" + key.intValue() + ")");
+        }
+        if (row != rr) {
+            _rowRecords.put(key, rr);
+            throw new RuntimeException("Attempt to remove row that does not belong to this sheet");
+        }
     }
 
-    public RowRecord getRow(int rownum) {
-        // Row must be between 0 and 65535
-        if(rownum < 0 || rownum > 65535) {
+    public RowRecord getRow(int rowIndex) {
+        if (rowIndex < 0 || rowIndex > 65535) {
             throw new IllegalArgumentException("The row number must be between 0 and 65535");
         }
-
-        RowRecord row = new RowRecord(rownum);
-        return ( RowRecord ) records.get(row);
+        return (RowRecord) _rowRecords.get(new Integer(rowIndex));
     }
 
     public int getPhysicalNumberOfRows()
     {
-        return records.size();
+        return _rowRecords.size();
     }
 
     public int getFirstRowNum()
     {
-        return firstrow;
+        return _firstrow;
     }
 
     public int getLastRowNum()
     {
-        return lastrow;
+        return _lastrow;
     }
     
     /** Returns the number of row blocks.
@@ -102,184 +104,134 @@
      * after them
      */
     public int getRowBlockCount() {
-      int size = records.size()/DBCellRecord.BLOCK_SIZE;
-      if ((records.size() % DBCellRecord.BLOCK_SIZE) != 0)
+      int size = _rowRecords.size()/DBCellRecord.BLOCK_SIZE;
+      if ((_rowRecords.size() % DBCellRecord.BLOCK_SIZE) != 0)
           size++;
       return size;
     }
 
-    public int getRowBlockSize(int block) {
-      return 20 * getRowCountForBlock(block);
+    private int getRowBlockSize(int block) {
+      return RowRecord.ENCODED_SIZE * getRowCountForBlock(block);
     }
 
     /** Returns the number of physical rows within a block*/
     public int getRowCountForBlock(int block) {
       int startIndex = block * DBCellRecord.BLOCK_SIZE;
       int endIndex = startIndex + DBCellRecord.BLOCK_SIZE - 1;
-      if (endIndex >= records.size())
-        endIndex = records.size()-1;
+      if (endIndex >= _rowRecords.size())
+        endIndex = _rowRecords.size()-1;
 
       return endIndex-startIndex+1;
     }
 
     /** Returns the physical row number of the first row in a block*/
-    public int getStartRowNumberForBlock(int block) {
+    private int getStartRowNumberForBlock(int block) {
       //Given that we basically iterate through the rows in order,
-      //For a performance improvement, it would be better to return an instance of
+      // TODO - For a performance improvement, it would be better to return an instance of
       //an iterator and use that instance throughout, rather than recreating one and
       //having to move it to the right position.
       int startIndex = block * DBCellRecord.BLOCK_SIZE;
-      Iterator rowIter = records.values().iterator();
+      Iterator rowIter = _rowRecords.values().iterator();
       RowRecord row = null;
       //Position the iterator at the start of the block
       for (int i=0; i<=startIndex;i++) {
         row = (RowRecord)rowIter.next();
       }
+      if (row == null) {
+          throw new RuntimeException("Did not find start row for block " + block);
+      }
 
       return row.getRowNumber();
     }
 
     /** Returns the physical row number of the end row in a block*/
-    public int getEndRowNumberForBlock(int block) {
+    private int getEndRowNumberForBlock(int block) {
       int endIndex = ((block + 1)*DBCellRecord.BLOCK_SIZE)-1;
-      if (endIndex >= records.size())
-        endIndex = records.size()-1;
+      if (endIndex >= _rowRecords.size())
+        endIndex = _rowRecords.size()-1;
 
-      Iterator rowIter = records.values().iterator();
+      Iterator rowIter = _rowRecords.values().iterator();
       RowRecord row = null;
       for (int i=0; i<=endIndex;i++) {
         row = (RowRecord)rowIter.next();
       }
+      if (row == null) {
+          throw new RuntimeException("Did not find start row for block " + block);
+      }
       return row.getRowNumber();
     }
-
-
-    /** Serializes a block of the rows */
-    private int serializeRowBlock(final int block, final int offset, byte[] data) {
-      final int startIndex = block*DBCellRecord.BLOCK_SIZE;
-      final int endIndex = startIndex + DBCellRecord.BLOCK_SIZE;
-
-      Iterator rowIterator = records.values().iterator();
-      int pos = offset;
-
-      //Given that we basically iterate through the rows in order,
-      //For a performance improvement, it would be better to return an instance of
-      //an iterator and use that instance throughout, rather than recreating one and
-      //having to move it to the right position.
-      int i=0;
-      for (;i<startIndex;i++)
-        rowIterator.next();
-      while(rowIterator.hasNext() && (i++ < endIndex)) {
-        RowRecord row = (RowRecord)rowIterator.next();
-        pos += row.serialize(pos, data);
+    
+    private int visitRowRecordsForBlock(int blockIndex, RecordVisitor rv) {
+        final int startIndex = blockIndex*DBCellRecord.BLOCK_SIZE;
+        final int endIndex = startIndex + DBCellRecord.BLOCK_SIZE;
+
+        Iterator rowIterator = _rowRecords.values().iterator();
+
+        //Given that we basically iterate through the rows in order,
+        //For a performance improvement, it would be better to return an instance of
+        //an iterator and use that instance throughout, rather than recreating one and
+        //having to move it to the right position.
+        int i=0;
+        for (;i<startIndex;i++)
+          rowIterator.next();
+        int result = 0;
+        while(rowIterator.hasNext() && (i++ < endIndex)) {
+          Record rec = (Record)rowIterator.next();
+          result += rec.getRecordSize();
+          rv.visitRecord(rec);
+        }
+        return result;
       }
-      return pos - offset;
-    }
-
-    public int serialize(int offset, byte [] data) {
-      throw new RuntimeException("The serialize method that passes in cells should be used");
-    }
     
-
-    /**
-     * called by the class that is responsible for writing this sucker.
-     * Subclasses should implement this so that their data is passed back in a
-     * byte array.
-     *
-     * @param offset    offset to begin writing at
-     * @param data      byte array containing instance data
-     * @return number of bytes written
-     */
-
-    public int serialize(int offset, byte [] data, ValueRecordsAggregate cells)
-    {
-        int pos = offset;
-
+    public void visitContainedRecords(RecordVisitor rv) {
+        ValueRecordsAggregate cells = _valuesAgg;
+       
         //DBCells are serialized before row records.
         final int blockCount = getRowBlockCount();
-        for (int block=0;block<blockCount;block++) {
-          //Serialize a block of rows.
-          //Hold onto the position of the first row in the block
-          final int rowStartPos = pos;
-          //Hold onto the size of this block that was serialized
-          final int rowBlockSize = serializeRowBlock(block, pos, data);
-          pos += rowBlockSize;
-          //Serialize a block of cells for those rows
-          final int startRowNumber = getStartRowNumberForBlock(block);
-          final int endRowNumber = getEndRowNumberForBlock(block);
-          DBCellRecord cellRecord = new DBCellRecord();
-          //Note: Cell references start from the second row...
-          int cellRefOffset = (rowBlockSize-20);
-          for (int row=startRowNumber;row<=endRowNumber;row++) {
-            if (null != cells && cells.rowHasCells(row)) {
-              final int rowCellSize = cells.serializeCellRow(row, pos, data);
-              pos += rowCellSize;
-              //Add the offset to the first cell for the row into the DBCellRecord.
-              cellRecord.addCellOffset((short)cellRefOffset);
-              cellRefOffset = rowCellSize;
+        for (int blockIndex = 0; blockIndex < blockCount; blockIndex++) {
+            // Serialize a block of rows.
+            // Hold onto the position of the first row in the block
+            int pos=0;
+            // Hold onto the size of this block that was serialized
+            final int rowBlockSize = visitRowRecordsForBlock(blockIndex, rv);
+            pos += rowBlockSize;
+            // Serialize a block of cells for those rows
+            final int startRowNumber = getStartRowNumberForBlock(blockIndex);
+            final int endRowNumber = getEndRowNumberForBlock(blockIndex);
+            DBCellRecord cellRecord = new DBCellRecord();
+            // Note: Cell references start from the second row...
+            int cellRefOffset = (rowBlockSize - RowRecord.ENCODED_SIZE);
+            for (int row = startRowNumber; row <= endRowNumber; row++) {
+                if (cells.rowHasCells(row)) {
+                    final int rowCellSize = cells.visitCellsForRow(row, rv);
+                    pos += rowCellSize;
+                    // Add the offset to the first cell for the row into the
+                    // DBCellRecord.
+                    cellRecord.addCellOffset((short) cellRefOffset);
+                    cellRefOffset = rowCellSize;
+                }
             }
-          }
-          //Calculate Offset from the start of a DBCellRecord to the first Row
-          cellRecord.setRowOffset(pos - rowStartPos);
-          pos += cellRecord.serialize(pos, data);
-
+            // Calculate Offset from the start of a DBCellRecord to the first Row
+            cellRecord.setRowOffset(pos);
+            rv.visitRecord(cellRecord);
         }
-        return pos - offset;
-    }
-
-    /**
-     * You never fill an aggregate
-     */
-    protected void fillFields(RecordInputStream in)
-    {
-    }
-
-    /**
-     * called by constructor, should throw runtime exception in the event of a
-     * record passed with a differing ID.
-     *
-     * @param id alleged id for this record
-     */
-
-    protected void validateSid(short id)
-    {
-    }
-
-    /**
-     * return the non static version of the id for this record.
-     */
-
-    public short getSid()
-    {
-        return -1000;
-    }
-
-    public int getRecordSize()
-    {
-        return size;
     }
 
-    public Iterator getIterator()
-    {
-        return records.values().iterator();
+    public Iterator getIterator() {
+        return _rowRecords.values().iterator();
     }
     
-    /**
-     * Performs a deep clone of the record
-     */
-    public Object clone()
-    {
-        RowRecordsAggregate rec = new RowRecordsAggregate();
-        for ( Iterator rowIter = getIterator(); rowIter.hasNext(); )
-        {
-            //return the cloned Row Record & insert
-            RowRecord row = (RowRecord) ( (RowRecord) rowIter.next() ).clone();
-            rec.insertRow( row );
+    
+    public Iterator getAllRecordsIterator() {
+        List result = new ArrayList(_rowRecords.size() * 2);
+        result.addAll(_rowRecords.values());
+        Iterator vi = _valuesAgg.getIterator();
+        while (vi.hasNext()) {
+            result.add(vi.next());
         }
-        return rec;
+        return result.iterator();
     }
 
-
     public int findStartOfRowOutlineGroup(int row)
     {
         // Find the start of the group.
@@ -449,5 +401,52 @@
         }
     }
 
+    public CellValueRecordInterface[] getValueRecords() {
+        return _valuesAgg.getValueRecords();
+    }
+
+    public IndexRecord createIndexRecord(int indexRecordOffset, int sizeOfInitialSheetRecords) {
+        IndexRecord result = new IndexRecord();
+        result.setFirstRow(_firstrow);
+        result.setLastRowAdd1(_lastrow + 1);
+        // Calculate the size of the records from the end of the BOF
+        // and up to the RowRecordsAggregate...
+
+        // Add the references to the DBCells in the IndexRecord (one for each block)
+        // Note: The offsets are relative to the Workbook BOF. Assume that this is
+        // 0 for now.....
+
+        int blockCount = getRowBlockCount();
+        // Calculate the size of this IndexRecord
+        int indexRecSize = IndexRecord.getRecordSizeForBlockCount(blockCount);
+
+        int currentOffset = indexRecordOffset + indexRecSize + sizeOfInitialSheetRecords;
+
+        for (int block = 0; block < blockCount; block++) {
+            // each row-block has a DBCELL record.
+            // The offset of each DBCELL record needs to be updated in the INDEX record
+
+            // account for row records in this row-block
+            currentOffset += getRowBlockSize(block);
+            // account for cell value records after those
+            currentOffset += _valuesAgg.getRowCellBlockSize(
+                    getStartRowNumberForBlock(block), getEndRowNumberForBlock(block));
+
+            // currentOffset is now the location of the DBCELL record for this row-block
+            result.addDbcell(currentOffset);
+            // Add space required to write the DBCELL record (whose reference was just added).
+            currentOffset += (8 + (getRowCountForBlock(block) * 2));
+        }
+        return result;
+    }
+    public void constructCellValues(int offset, List records) {
+        _valuesAgg.construct(offset, records);
+    }
+    public void insertCell(CellValueRecordInterface cvRec) {
+        _valuesAgg.insertCell(cvRec);
+    }
+    public void removeCell(CellValueRecordInterface cvRec) {
+        _valuesAgg.removeCell(cvRec);
+    }
 }
 



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


Mime
View raw message