poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r686977 - in /poi/trunk/src: java/org/apache/poi/hssf/model/Sheet.java testcases/org/apache/poi/hssf/model/TestSheet.java
Date Tue, 19 Aug 2008 07:44:58 GMT
Author: josh
Date: Tue Aug 19 00:44:57 2008
New Revision: 686977

URL: http://svn.apache.org/viewvc?rev=686977&view=rev
Log:
Fix for bug 45640 - avoid creating multiple GUTS records

Modified:
    poi/trunk/src/java/org/apache/poi/hssf/model/Sheet.java
    poi/trunk/src/testcases/org/apache/poi/hssf/model/TestSheet.java

Modified: poi/trunk/src/java/org/apache/poi/hssf/model/Sheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/model/Sheet.java?rev=686977&r1=686976&r2=686977&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/model/Sheet.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/model/Sheet.java Tue Aug 19 00:44:57 2008
@@ -106,7 +106,7 @@
 
     protected ArrayList                  records           =     null;
               int                        preoffset         =     0;            // offset
of the sheet in a new file
-    protected int                        dimsloc           =     -1;  // TODO - is it legal
for dims record to be missing?
+    protected int                        dimsloc           =     -1;  // TODO - remove dimsloc
     protected PrintGridlinesRecord       printGridlines    =     null;
     protected GridsetRecord              gridset           =     null;
     private   GutsRecord                 _gutsRecord;
@@ -125,7 +125,8 @@
     private   MergedCellsTable           _mergedCellsTable;
     /** always present in this POI object, not always written to Excel file */
     /*package*/ColumnInfoRecordsAggregate _columnInfos;
-    protected DimensionsRecord           dims;
+    /** the DimensionsRecord is always present */
+    private DimensionsRecord             _dimensions;
     protected RowRecordsAggregate        _rowsAggregate              =     null;
     private   DataValidityTable          _dataValidityTable=     null;
     private   ConditionalFormattingTable condFormatting;
@@ -287,7 +288,7 @@
                     records.add(retval._columnInfos);
                 }
 
-                retval.dims    = ( DimensionsRecord ) rec;
+                retval._dimensions    = ( DimensionsRecord ) rec;
                 retval.dimsloc = records.size();
             }
             else if (rec.getSid() == DefaultColWidthRecord.sid)
@@ -333,7 +334,7 @@
 
             records.add(rec);
         }
-        if (retval.dimsloc < 0) {
+        if (retval._dimensions == null) {
             throw new RuntimeException("DimensionsRecord was not found");
         }
         retval.records = records;
@@ -404,6 +405,8 @@
 
     public static Sheet createSheet()
     {
+         // TODO - convert this method to a constructor
+
         if (log.check( POILogger.DEBUG ))
             log.log(POILogger.DEBUG, "Sheet createsheet from scratch called");
         Sheet     retval  = new Sheet();
@@ -423,7 +426,8 @@
         records.add( retval.printGridlines );
         retval.gridset = createGridset();
         records.add( retval.gridset );
-        records.add( retval.createGuts() );
+        retval._gutsRecord = createGuts();
+        records.add( retval._gutsRecord );
         retval.defaultrowheight = createDefaultRowHeight();
         records.add( retval.defaultrowheight );
         records.add( retval.createWSBool() );
@@ -440,8 +444,8 @@
         ColumnInfoRecordsAggregate columns = new ColumnInfoRecordsAggregate();
         records.add( columns );
         retval._columnInfos = columns;
-        retval.dims    =  createDimensions();
-        records.add(retval.dims);
+        retval._dimensions = createDimensions();
+        records.add(retval._dimensions);
         retval.dimsloc = records.size()-1;
         records.add(retval.windowTwo = retval.createWindowTwo());
         retval.selection = createSelection();
@@ -460,7 +464,7 @@
         if (_rowsAggregate == null)
         {
             _rowsAggregate = new RowRecordsAggregate();
-            records.add(getDimsLoc() + 1, _rowsAggregate);
+            records.add(dimsloc + 1, _rowsAggregate);
         }
     }
     private MergedCellsTable getMergedRecords() {
@@ -556,10 +560,10 @@
                         .append(lastrow).append("lastcol").append(lastcol)
                         .toString());
         }
-        dims.setFirstCol(firstcol);
-        dims.setFirstRow(firstrow);
-        dims.setLastCol(lastcol);
-        dims.setLastRow(lastrow);
+        _dimensions.setFirstCol(firstcol);
+        _dimensions.setFirstRow(firstrow);
+        _dimensions.setLastCol(lastcol);
+        _dimensions.setLastRow(lastrow);
         if (log.check( POILogger.DEBUG ))
             log.log(POILogger.DEBUG, "Sheet.setDimensions exiting");
     }
@@ -696,7 +700,7 @@
         if(log.check(POILogger.DEBUG)) {
           log.log(POILogger.DEBUG, "add value record  row" + row);
         }
-        DimensionsRecord d = ( DimensionsRecord ) records.get(getDimsLoc());
+        DimensionsRecord d = _dimensions;
 
         if (col.getColumn() > d.getLastCol())
         {
@@ -720,8 +724,8 @@
      */
     public void removeValueRecord(int row, CellValueRecordInterface col) {
 
-        log.logFormatted(POILogger.DEBUG, "remove value record row,dimsloc %,%",
-                         new int[]{row, dimsloc} );
+        log.logFormatted(POILogger.DEBUG, "remove value record row %",
+                         new int[]{row } );
         _rowsAggregate.removeCell(col);
     }
 
@@ -766,7 +770,7 @@
         checkRows();
         if (log.check( POILogger.DEBUG ))
             log.log(POILogger.DEBUG, "addRow ");
-        DimensionsRecord d = ( DimensionsRecord ) records.get(getDimsLoc());
+        DimensionsRecord d = _dimensions;
 
         if (row.getRowNumber() >= d.getLastRow())
         {
@@ -1331,27 +1335,6 @@
     }
 
     /**
-     * get the location of the DimensionsRecord (which is the last record before the value
section)
-     * @return location in the array of records of the DimensionsRecord
-     */
-
-    public int getDimsLoc()
-    {
-        if (log.check( POILogger.DEBUG ))
-            log.log(POILogger.DEBUG, "getDimsLoc dimsloc= " + dimsloc);
-        return dimsloc;
-    }
-
-    /**
-     * 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) {
-            dimsloc = recloc;
-        }
-    }
-
-    /**
      * @return the serialized size of this sheet
      */
     public int getSize() {

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/model/TestSheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/model/TestSheet.java?rev=686977&r1=686976&r2=686977&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/model/TestSheet.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/model/TestSheet.java Tue Aug 19 00:44:57 2008
@@ -32,6 +32,7 @@
 import org.apache.poi.hssf.record.ColumnInfoRecord;
 import org.apache.poi.hssf.record.DimensionsRecord;
 import org.apache.poi.hssf.record.EOFRecord;
+import org.apache.poi.hssf.record.GutsRecord;
 import org.apache.poi.hssf.record.IndexRecord;
 import org.apache.poi.hssf.record.MergeCellsRecord;
 import org.apache.poi.hssf.record.Record;
@@ -41,6 +42,8 @@
 import org.apache.poi.hssf.record.aggregates.ColumnInfoRecordsAggregate;
 import org.apache.poi.hssf.record.aggregates.PageSettingsBlock;
 import org.apache.poi.hssf.record.aggregates.RowRecordsAggregate;
+import org.apache.poi.hssf.usermodel.HSSFSheet;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.hssf.util.CellRangeAddress;
 
 /**
@@ -438,8 +441,8 @@
         if (false) {
             // make sure that RRA and VRA are in the right place
             // (Aug 2008) since the VRA is now part of the RRA, there is much less chance
that
-        	// they could get out of order. Still, one could write serialize the sheet here,

-        	// and read back with EventRecordFactory to make sure...
+            // they could get out of order. Still, one could write serialize the sheet here,

+            // and read back with EventRecordFactory to make sure...
         }
         assertEquals(242, dbCellRecordPos);
     }
@@ -475,5 +478,29 @@
             return _indexRecord;
         }
     }
+    
+    /**
+     * Checks for bug introduced around r682282-r683880 that caused a second GUTS records
+     * which in turn got the dimensions record out of alignment
+     */
+    public void testGutsRecord_bug45640() {
+        
+        Sheet sheet = Sheet.createSheet();
+        sheet.addRow(new RowRecord(0));
+        sheet.addRow(new RowRecord(1));
+        sheet.groupRowRange( 0, 1, true );
+        sheet.toString();
+        List recs = sheet.getRecords();
+        int count=0;
+        for(int i=0; i< recs.size(); i++) {
+            if (recs.get(i) instanceof GutsRecord) {
+                count++;
+            }
+        }
+        if (count == 2) {
+            throw new AssertionFailedError("Identified bug 45640");
+        }
+        assertEquals(1, count);
+    }
 }
 



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


Mime
View raw message