]> source.dussan.org Git - poi.git/commitdiff
shortcut for test case to allow loading bad structure of CHP
authorSergey Vladimirov <sergey@apache.org>
Sat, 9 Jul 2011 16:10:57 +0000 (16:10 +0000)
committerSergey Vladimirov <sergey@apache.org>
Sat, 9 Jul 2011 16:10:57 +0000 (16:10 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1144691 13f79535-47bb-0310-9956-ffa450edef68

src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java
src/scratchpad/src/org/apache/poi/hwpf/model/CHPBinTable.java
src/scratchpad/src/org/apache/poi/hwpf/model/CHPFormattedDiskPage.java
src/scratchpad/src/org/apache/poi/hwpf/model/OldCHPBinTable.java
src/scratchpad/testcases/org/apache/poi/hwpf/model/TestCHPBinTable.java

index 3b69e72762d99d858baf4c49b0fc96f6b7140a43..86e38f34675690e933da60be0803c2d02ef3c958 100644 (file)
@@ -222,7 +222,7 @@ public final class HWPFDocument extends HWPFDocumentCore
 
     // Now load the rest of the properties, which need to be adjusted
     //  for where text really begin
-    _cbt = new CHPBinTable(_mainStream, _tableStream, _fib.getFcPlcfbteChpx(), _fib.getLcbPlcfbteChpx(), cpMin, _tpt);
+    _cbt = new CHPBinTable(_mainStream, _tableStream, _fib.getFcPlcfbteChpx(), _fib.getLcbPlcfbteChpx(), cpMin, _tpt, true);
     _pbt = new PAPBinTable(_mainStream, _tableStream, _dataStream, _fib.getFcPlcfbtePapx(), _fib.getLcbPlcfbtePapx(), cpMin, _tpt, true);
 
     // Read FSPA and Escher information
index 5d392bbf0c11233730a9e02840c13518e60f31fe..097fd58a670e37e0b60c90eb22457cb06c10c56d 100644 (file)
@@ -47,17 +47,25 @@ public class CHPBinTable
   {
   }
 
-  /**
-   * Constructor used to read a binTable in from a Word document.
-   *
-   * @param documentStream
-   * @param tableStream
-   * @param offset
-   * @param size
-   * @param fcMin
-   */
+    /**
+     * Constructor used to read a binTable in from a Word document.
+     * 
+     * @deprecated Use
+     *             {@link #CHPBinTable(byte[],byte[],int,int,int,TextPieceTable,boolean)}
+     *             instead
+     */
     public CHPBinTable( byte[] documentStream, byte[] tableStream, int offset,
             int size, int fcMin, TextPieceTable tpt )
+    {
+        this( documentStream, tableStream, offset, size, fcMin, tpt, true );
+    }
+
+    /**
+     * Constructor used to read a binTable in from a Word document.
+     */
+    public CHPBinTable( byte[] documentStream, byte[] tableStream, int offset,
+            int size, int fcMin, TextPieceTable tpt,
+            boolean ignoreChpxWithoutTextPieces )
     {
         /*
          * Page 35:
@@ -79,7 +87,7 @@ public class CHPBinTable
       int pageOffset = POIFSConstants.SMALLER_BIG_BLOCK_SIZE * pageNum;
 
       CHPFormattedDiskPage cfkp = new CHPFormattedDiskPage(documentStream,
-        pageOffset, fcMin, tpt);
+        pageOffset, fcMin, tpt, ignoreChpxWithoutTextPieces);
 
       int fkpSize = cfkp.size();
 
index 9692ba0142d19555f4406e7d3bb7b3249d966360..5de4e53e98d9c1114c00239f218ef8a61fbca0ab 100644 (file)
@@ -53,8 +53,26 @@ public final class CHPFormattedDiskPage extends FormattedDiskPage
     /**
      * This constructs a CHPFormattedDiskPage from a raw fkp (512 byte array
      * read from a Word file).
+     * 
+     * @deprecated Use
+     *             {@link #CHPFormattedDiskPage(byte[],int,int,TextPieceTable,boolean)}
+     *             instead
      */
-    public CHPFormattedDiskPage(byte[] documentStream, int offset, int fcMin, TextPieceTable tpt)
+    public CHPFormattedDiskPage( byte[] documentStream, int offset, int fcMin,
+            TextPieceTable tpt )
+    {
+        this( documentStream, offset, fcMin, tpt, true );
+    }
+
+    /**
+     * This constructs a CHPFormattedDiskPage from a raw fkp (512 byte array
+     * read from a Word file).
+     * 
+     * @param ignoreChpxWithoutTextPieces
+     *            TODO
+     */
+    public CHPFormattedDiskPage( byte[] documentStream, int offset, int fcMin,
+            TextPieceTable tpt, boolean ignoreChpxWithoutTextPieces )
     {
       super(documentStream, offset);
 
@@ -63,7 +81,7 @@ public final class CHPFormattedDiskPage extends FormattedDiskPage
        int startAt = getStart(x);
                int endAt = getEnd(x);
 
-        if ( !tpt.isIndexInTable( startAt, endAt ) ) {
+        if (ignoreChpxWithoutTextPieces && !tpt.isIndexInTable( startAt, endAt ) ) {
             _chpxList.add(null);
         } else {
                    _chpxList.add(new CHPX(startAt, endAt, tpt, getGrpprl(x)));
index 146fd3b3f7bc4984f2fb1434be73834e825ecc2c..93090d35aa2c19a7a1c3df861ab57eae7c266465 100644 (file)
@@ -55,7 +55,7 @@ public final class OldCHPBinTable extends CHPBinTable
       int pageOffset = POIFSConstants.SMALLER_BIG_BLOCK_SIZE * pageNum;
 
       CHPFormattedDiskPage cfkp = new CHPFormattedDiskPage(documentStream,
-        pageOffset, fcMin, tpt);
+        pageOffset, fcMin, tpt, true);
 
       int fkpSize = cfkp.size();
 
index 40d5a6326c6d0dbb786a194561df39b6efa6bceb..c2b8789011f6b6d45071c80cc1e61625f7e40a24 100644 (file)
@@ -20,10 +20,10 @@ package org.apache.poi.hwpf.model;
 import java.io.ByteArrayOutputStream;
 import java.util.ArrayList;
 
-import junit.framework.*;
+import junit.framework.TestCase;
 
-import org.apache.poi.hwpf.*;
-import org.apache.poi.hwpf.model.io.*;
+import org.apache.poi.hwpf.HWPFDocFixture;
+import org.apache.poi.hwpf.model.io.HWPFFileSystem;
 
 public final class TestCHPBinTable
   extends TestCase
@@ -46,7 +46,7 @@ public final class TestCHPBinTable
     byte[] tableStream = _hWPFDocFixture._tableStream;
     int fcMin = fib.getFcMin();
 
-    _cHPBinTable = new CHPBinTable(mainStream, tableStream, fib.getFcPlcfbteChpx(), fib.getLcbPlcfbteChpx(), fcMin, fakeTPT);
+    _cHPBinTable = new CHPBinTable(mainStream, tableStream, fib.getFcPlcfbteChpx(), fib.getLcbPlcfbteChpx(), fcMin, fakeTPT, false);
 
     HWPFFileSystem fileSys = new HWPFFileSystem();
 
@@ -57,7 +57,7 @@ public final class TestCHPBinTable
     byte[] newTableStream = tableOut.toByteArray();
     byte[] newMainStream = mainOut.toByteArray();
 
-    CHPBinTable newBinTable = new CHPBinTable(newMainStream, newTableStream, 0, newTableStream.length, 0, fakeTPT);
+    CHPBinTable newBinTable = new CHPBinTable(newMainStream, newTableStream, 0, newTableStream.length, 0, fakeTPT, false);
 
     ArrayList oldTextRuns = _cHPBinTable._textRuns;
     ArrayList newTextRuns = newBinTable._textRuns;