]> source.dussan.org Git - poi.git/commitdiff
fix additional issue found in bug 52032, add test files
authorSergey Vladimirov <sergey@apache.org>
Sat, 29 Oct 2011 23:57:48 +0000 (23:57 +0000)
committerSergey Vladimirov <sergey@apache.org>
Sat, 29 Oct 2011 23:57:48 +0000 (23:57 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1195077 13f79535-47bb-0310-9956-ffa450edef68

src/scratchpad/src/org/apache/poi/hwpf/model/ListLevel.java
src/scratchpad/src/org/apache/poi/hwpf/model/ListTables.java
src/scratchpad/testcases/org/apache/poi/hwpf/model/types/LFOLVLBaseAbstractTypeTest.java [new file with mode: 0644]
test-data/document/Bug52032.doc [deleted file]
test-data/document/Bug52032_1.doc [new file with mode: 0644]
test-data/document/Bug52032_2.doc [new file with mode: 0644]
test-data/document/Bug52032_3.doc [new file with mode: 0644]

index 9d4d97a65503bc78e56c34bfa0d0f7037af18a1b..e33ccb2d96de4b327caf27d4b8649a5bcffe40b9 100644 (file)
@@ -38,71 +38,23 @@ import org.apache.poi.util.POILogger;
 @Internal
 public final class ListLevel
 {
-    private static final POILogger logger = POILogFactory.getLogger( ListLevel.class );
-    
+    private static final POILogger logger = POILogFactory
+            .getLogger( ListLevel.class );
+
     private byte[] _grpprlChpx;
     private byte[] _grpprlPapx;
     private LVLF _lvlf;
     private char[] _xst = {};
 
-    public ListLevel( final byte[] buf, final int startOffset )
+    ListLevel()
     {
-        int offset = startOffset;
 
-        _lvlf = new LVLF( buf, offset );
-        offset += LVLF.getSize();
-
-        _grpprlPapx = new byte[_lvlf.getCbGrpprlPapx()];
-        System.arraycopy( buf, offset, _grpprlPapx, 0, _lvlf.getCbGrpprlPapx() );
-        offset += _lvlf.getCbGrpprlPapx();
-
-        _grpprlChpx = new byte[_lvlf.getCbGrpprlChpx()];
-        System.arraycopy( buf, offset, _grpprlChpx, 0, _lvlf.getCbGrpprlChpx() );
-        offset += _lvlf.getCbGrpprlChpx();
-
-        /*
-         * "If this level uses bullets (see lvlf.nfc), the cch field of this Xst
-         * MUST be equal to 0x0001, and this MUST NOT contain any placeholders."
-         * -- page 389 of 621 -- [MS-DOC] -- v20110315 Word (.doc) Binary File
-         * Format
-         */
-        if ( _lvlf.getNfc() == 0x17 )
-        {
-            int numberTextLength = LittleEndian.getShort( buf, offset );
-            offset += LittleEndian.SHORT_SIZE;
-
-            if ( numberTextLength != 1 )
-            {
-                logger.log( POILogger.WARN, "LVL at offset ",
-                        Integer.valueOf( startOffset ),
-                        " has nfc == 0x17 (bullets), but cch != 1 (",
-                        Integer.valueOf( numberTextLength ), ")" );
-            }
-
-            _xst = new char[] { (char) LittleEndian.getShort( buf, offset ) };
-            offset += LittleEndian.SHORT_SIZE;
-        }
-        else
-        {
-            int numberTextLength = LittleEndian.getShort( buf, offset );
-            offset += LittleEndian.SHORT_SIZE;
+    }
 
-            if ( numberTextLength > 0 )
-            {
-                _xst = new char[numberTextLength];
-                for ( int x = 0; x < numberTextLength; x++ )
-                {
-                    _xst[x] = (char) LittleEndian.getShort( buf, offset );
-                    offset += LittleEndian.SHORT_SIZE;
-                }
-            }
-            else
-            {
-                /* sometimes numberTextLength<0 */
-                /* by derjohng */
-                _xst = new char[] {};
-            }
-        }
+    @Deprecated
+    public ListLevel( final byte[] buf, final int startOffset )
+    {
+        read( buf, startOffset );
     }
 
     public ListLevel( int level, boolean numbered )
@@ -206,6 +158,74 @@ public final class ListLevel
         return _lvlf.getIxchFollow();
     }
 
+    int read( final byte[] data, final int startOffset )
+    {
+        int offset = startOffset;
+
+        _lvlf = new LVLF( data, offset );
+        offset += LVLF.getSize();
+
+        _grpprlPapx = new byte[_lvlf.getCbGrpprlPapx()];
+        System.arraycopy( data, offset, _grpprlPapx, 0, _lvlf.getCbGrpprlPapx() );
+        offset += _lvlf.getCbGrpprlPapx();
+
+        _grpprlChpx = new byte[_lvlf.getCbGrpprlChpx()];
+        System.arraycopy( data, offset, _grpprlChpx, 0, _lvlf.getCbGrpprlChpx() );
+        offset += _lvlf.getCbGrpprlChpx();
+
+        /*
+         * "If this level uses bullets (see lvlf.nfc), the cch field of this Xst
+         * MUST be equal to 0x0001, and this MUST NOT contain any placeholders."
+         * -- page 389 of 621 -- [MS-DOC] -- v20110315 Word (.doc) Binary File
+         * Format
+         */
+        if ( _lvlf.getNfc() == 0x17 )
+        {
+            int cch = LittleEndian.getUShort( data, offset );
+            offset += LittleEndian.SHORT_SIZE;
+
+            if ( cch != 1 )
+            {
+                logger.log( POILogger.WARN, "LVL at offset ",
+                        Integer.valueOf( startOffset ),
+                        " has nfc == 0x17 (bullets), but cch != 1 (",
+                        Integer.valueOf( cch ), ")" );
+            }
+
+            _xst = new char[cch];
+            for ( int x = 0; x < cch; x++ )
+            {
+                _xst[x] = (char) LittleEndian.getShort( data, offset );
+                offset += LittleEndian.SHORT_SIZE;
+            }
+        }
+        else
+        {
+            int cch = LittleEndian.getUShort( data, offset );
+            offset += LittleEndian.SHORT_SIZE;
+
+            if ( cch > 0 )
+            {
+                _xst = new char[cch];
+                for ( int x = 0; x < cch; x++ )
+                {
+                    _xst[x] = (char) LittleEndian.getShort( data, offset );
+                    offset += LittleEndian.SHORT_SIZE;
+                }
+            }
+            else
+            {
+                logger.log( POILogger.WARN, "LVL.xst.cch <= 0: ",
+                        Integer.valueOf( cch ) );
+                /* sometimes numberTextLength<0 */
+                /* by derjohng */
+                _xst = new char[] {};
+            }
+        }
+
+        return offset - startOffset;
+    }
+
     public void setAlignment( int alignment )
     {
         _lvlf.setJc( (byte) alignment );
@@ -276,9 +296,10 @@ public final class ListLevel
     @Override
     public String toString()
     {
-        return "ListLevel: " + ( "\n" + _lvlf ).replaceAll( "\n", "\n    " )
+        return "LVL: " + ( "\n" + _lvlf ).replaceAll( "\n", "\n    " )
                 + "\n"
                 + ( "PAPX's grpprl: " + Arrays.toString( _grpprlPapx ) + "\n" )
-                + ( "CHPX's grpprl: " + Arrays.toString( _grpprlChpx ) + "\n" );
+                + ( "CHPX's grpprl: " + Arrays.toString( _grpprlChpx ) + "\n" )
+                + ( "xst: " + Arrays.toString( _xst ) + "\n" );
     }
 }
index 88524d0f7766b76d5c172e33c065faac6340d408..009f42f7b496dd8ba32a9d604dbaf72b0081a194 100644 (file)
@@ -41,7 +41,6 @@ import org.apache.poi.util.POILogger;
 @Internal
 public final class ListTables
 {
-  private static final int LIST_DATA_SIZE = 28;
   private static POILogger log = POILogFactory.getLogger(ListTables.class);
 
   ListMap _listMap = new ListMap();
@@ -65,7 +64,7 @@ public final class ListTables
 
             int cLst = LittleEndian.getShort( tableStream, offset );
             offset += LittleEndian.SHORT_SIZE;
-            int levelOffset = offset + ( cLst * LIST_DATA_SIZE );
+            int levelOffset = offset + ( cLst * LSTF.getSize() );
 
             for ( int x = 0; x < cLst; x++ )
             {
@@ -76,9 +75,9 @@ public final class ListTables
                 int num = lst.numLevels();
                 for ( int y = 0; y < num; y++ )
                 {
-                    ListLevel lvl = new ListLevel( tableStream, levelOffset );
+                    ListLevel lvl = new ListLevel();
+                    levelOffset += lvl.read( tableStream, levelOffset );
                     lst.setLevel( y, lvl );
-                    levelOffset += lvl.getSizeInBytes();
                 }
             }
         }
diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/model/types/LFOLVLBaseAbstractTypeTest.java b/src/scratchpad/testcases/org/apache/poi/hwpf/model/types/LFOLVLBaseAbstractTypeTest.java
new file mode 100644 (file)
index 0000000..90919cf
--- /dev/null
@@ -0,0 +1,34 @@
+/* ====================================================================
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+package org.apache.poi.hwpf.model.types;
+
+import junit.framework.TestCase;
+
+/**
+ * Test cases for {@link LFOLVLBaseAbstractType}
+ * 
+ * @author Sergey Vladimirov (vlsergey {at} gmail {dot} com)
+ */
+public class LFOLVLBaseAbstractTypeTest extends TestCase
+{
+
+    public void testGetSize()
+    {
+        assertEquals( 8, LFOLVLBaseAbstractType.getSize() );
+    }
+
+}
diff --git a/test-data/document/Bug52032.doc b/test-data/document/Bug52032.doc
deleted file mode 100644 (file)
index c91d240..0000000
Binary files a/test-data/document/Bug52032.doc and /dev/null differ
diff --git a/test-data/document/Bug52032_1.doc b/test-data/document/Bug52032_1.doc
new file mode 100644 (file)
index 0000000..adfa972
Binary files /dev/null and b/test-data/document/Bug52032_1.doc differ
diff --git a/test-data/document/Bug52032_2.doc b/test-data/document/Bug52032_2.doc
new file mode 100644 (file)
index 0000000..cc0ede1
Binary files /dev/null and b/test-data/document/Bug52032_2.doc differ
diff --git a/test-data/document/Bug52032_3.doc b/test-data/document/Bug52032_3.doc
new file mode 100644 (file)
index 0000000..c91d240
Binary files /dev/null and b/test-data/document/Bug52032_3.doc differ