]> source.dussan.org Git - poi.git/commitdiff
Fix for 46918 - Allow shorter format for ExtendedPivotTableViewFieldsRecord(SXVDEX...
authorJosh Micich <josh@apache.org>
Tue, 31 Mar 2009 21:12:47 +0000 (21:12 +0000)
committerJosh Micich <josh@apache.org>
Tue, 31 Mar 2009 21:12:47 +0000 (21:12 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@760646 13f79535-47bb-0310-9956-ffa450edef68

src/documentation/content/xdocs/changes.xml
src/documentation/content/xdocs/status.xml
src/java/org/apache/poi/hssf/record/pivottable/ExtendedPivotTableViewFieldsRecord.java
src/testcases/org/apache/poi/hssf/record/pivot/TestExtendedPivotTableViewFieldsRecord.java

index cc2a0ce2865284b4d5ec764c482bee87d3dea8cd..52f96225aab6b6d2c3259dce6a70e98938d99e93 100644 (file)
@@ -37,6 +37,7 @@
 
                <!-- Don't forget to update status.xml too! -->
         <release version="3.5-beta6" date="2009-??-??">
+           <action dev="POI-DEVELOPERS" type="fix">46918 - Fixed ExtendedPivotTableViewFieldsRecord(SXVDEX) to allow shorter format</action>
            <action dev="POI-DEVELOPERS" type="fix">46898 - Fixed formula evaluator to not cache intermediate circular-reference error results</action>
            <action dev="POI-DEVELOPERS" type="fix">46917 - Fixed PageItemRecord(SXPI) to allow multiple field infos</action>
            <action dev="POI-DEVELOPERS" type="fix">46904 - Fix POIFS issue with duplicate block 0 references on very old BIFF5/BIFF7 files</action>
index cb3c8ffa38cf4709afdababdf1759fb51f9a30e3..e6cc63338a96bb42d49cc182e5222057847a58e0 100644 (file)
@@ -34,6 +34,7 @@
        <!-- Don't forget to update changes.xml too! -->
     <changes>
         <release version="3.5-beta6" date="2009-??-??">
+           <action dev="POI-DEVELOPERS" type="fix">46918 - Fixed ExtendedPivotTableViewFieldsRecord(SXVDEX) to allow shorter format</action>
            <action dev="POI-DEVELOPERS" type="fix">46898 - Fixed formula evaluator to not cache intermediate circular-reference error results</action>
            <action dev="POI-DEVELOPERS" type="fix">46917 - Fixed PageItemRecord(SXPI) to allow multiple field infos</action>
            <action dev="POI-DEVELOPERS" type="fix">46904 - Fix POIFS issue with duplicate block 0 references on very old BIFF5/BIFF7 files</action>
index 92911a1f2b5e691afbc7616cda6338c02a426933..70c9ebcc138ae8e7156c3f678e2ed9288da97cc6 100644 (file)
@@ -17,6 +17,7 @@
 
 package org.apache.poi.hssf.record.pivottable;
 
+import org.apache.poi.hssf.record.RecordFormatException;
 import org.apache.poi.hssf.record.RecordInputStream;
 import org.apache.poi.hssf.record.StandardRecord;
 import org.apache.poi.util.HexDump;
@@ -31,7 +32,7 @@ import org.apache.poi.util.StringUtil;
 public final class ExtendedPivotTableViewFieldsRecord extends StandardRecord {
        public static final short sid = 0x0100;
 
-       /** the value of the subname length when the {@link #_subName} is not present */
+       /** the value of the subname length when the {@link #_subtotalName} is not present */
        private static final int STRING_NOT_PRESENT_LEN = 0xFFFF;
 
        private int _grbit1;
@@ -41,7 +42,8 @@ public final class ExtendedPivotTableViewFieldsRecord extends StandardRecord {
        private int _isxdiShow;
        private int _reserved1;
        private int _reserved2;
-       private String _subName;
+       /** custom sub-total name */
+       private String _subtotalName;
 
        public ExtendedPivotTableViewFieldsRecord(RecordInputStream in) {
 
@@ -50,11 +52,26 @@ public final class ExtendedPivotTableViewFieldsRecord extends StandardRecord {
                _citmShow = in.readUByte();
                _isxdiSort = in.readUShort();
                _isxdiShow = in.readUShort();
+               // This record seems to have different valid encodings
+               switch (in.remaining()) {
+                       case 0:
+                               // as per "Microsoft Excel Developer's Kit" book
+                               // older version of SXVDEX - doesn't seem to have a sub-total name
+                               _reserved1 = 0;
+                               _reserved2 = 0;
+                               _subtotalName = null;
+                               return;
+                       case 10:
+                               // as per "MICROSOFT OFFICE EXCEL 97-2007 BINARY FILE FORMAT SPECIFICATION" pdf
+                               break;
+                       default:
+                               throw new RecordFormatException("Unexpected remaining size (" + in.remaining() + ")");
+               }
                int cchSubName = in.readUShort();
                _reserved1 = in.readInt();
                _reserved2 = in.readInt();
                if (cchSubName != STRING_NOT_PRESENT_LEN) {
-                       _subName = in.readUnicodeLEString(cchSubName);
+                       _subtotalName = in.readUnicodeLEString(cchSubName);
                }
        }
 
@@ -67,16 +84,16 @@ public final class ExtendedPivotTableViewFieldsRecord extends StandardRecord {
                out.writeShort(_isxdiSort);
                out.writeShort(_isxdiShow);
 
-               if (_subName == null) {
+               if (_subtotalName == null) {
                        out.writeShort(STRING_NOT_PRESENT_LEN);
                } else {
-                       out.writeShort(_subName.length());
+                       out.writeShort(_subtotalName.length());
                }
 
                out.writeInt(_reserved1);
                out.writeInt(_reserved2);
-               if (_subName != null) {
-                       StringUtil.putUnicodeLE(_subName, out);
+               if (_subtotalName != null) {
+                       StringUtil.putUnicodeLE(_subtotalName, out);
                }
        }
 
@@ -84,7 +101,7 @@ public final class ExtendedPivotTableViewFieldsRecord extends StandardRecord {
        protected int getDataSize() {
                
                return 4 + 1 + 1 + 2 + 2 + 2 +  4 + 4 +
-                                       (_subName == null ? 0 : (2*_subName.length())); // in unicode
+                                       (_subtotalName == null ? 0 : (2*_subtotalName.length())); // in unicode
        }
 
        @Override
@@ -103,7 +120,7 @@ public final class ExtendedPivotTableViewFieldsRecord extends StandardRecord {
                buffer.append("    .citmShow =").append(HexDump.byteToHex(_citmShow)).append("\n");
                buffer.append("    .isxdiSort =").append(HexDump.shortToHex(_isxdiSort)).append("\n");
                buffer.append("    .isxdiShow =").append(HexDump.shortToHex(_isxdiShow)).append("\n");
-               buffer.append("    .subName =").append(_subName).append("\n");
+               buffer.append("    .subtotalName =").append(_subtotalName).append("\n");
                buffer.append("[/SXVDEX]\n");
                return buffer.toString();
        }
index 7ba15d5c26535c4959f6c561d55061e7f7ff3b90..945528dd2dacea7894221de74dbb35f41d82a617 100644 (file)
@@ -51,4 +51,26 @@ public final class TestExtendedPivotTableViewFieldsRecord extends TestCase {
                
                assertEquals(data.length, rec.getRecordSize());
        }
+       
+       public void testOlderFormat_bug46918() {
+               // There are 10 SXVDEX records in the file (not uploaded) that originated bugzilla 46918
+               // They all had the following hex encoding:
+               byte data[] = HexRead.readFromString("00 01 0A 00 1E 14 00 0A FF FF FF FF 00 00");  
+
+               RecordInputStream in = TestcaseRecordInputStream.create(data);
+               ExtendedPivotTableViewFieldsRecord rec;
+               try {
+                       rec = new ExtendedPivotTableViewFieldsRecord(in);
+               } catch (RecordFormatException e) {
+                       if (e.getMessage().equals("Not enough data (0) to read requested (2) bytes")) {
+                               throw new AssertionFailedError("Identified bug 46918");
+                       }
+                       throw e;
+               }
+
+               byte expReserData[] = HexRead.readFromString("1E 14 00 0A FF FF FF FF 00 00" +
+                               "FF FF 00 00 00 00 00 00 00 00");  
+               
+               TestcaseRecordInputStream.confirmRecordEncoding(ExtendedPivotTableViewFieldsRecord.sid, expReserData, rec.serialize());
+       }
 }