From: Sergey Vladimirov Date: Sat, 9 Jul 2011 16:10:57 +0000 (+0000) Subject: shortcut for test case to allow loading bad structure of CHP X-Git-Tag: REL_3_8_BETA4~228 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=fa89d7ae6865683271061d0ca7a96bb298107f96;p=poi.git shortcut for test case to allow loading bad structure of CHP git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1144691 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java b/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java index 3b69e72762..86e38f3467 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java @@ -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 diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/CHPBinTable.java b/src/scratchpad/src/org/apache/poi/hwpf/model/CHPBinTable.java index 5d392bbf0c..097fd58a67 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/CHPBinTable.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/CHPBinTable.java @@ -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(); diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/CHPFormattedDiskPage.java b/src/scratchpad/src/org/apache/poi/hwpf/model/CHPFormattedDiskPage.java index 9692ba0142..5de4e53e98 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/CHPFormattedDiskPage.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/CHPFormattedDiskPage.java @@ -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))); diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/OldCHPBinTable.java b/src/scratchpad/src/org/apache/poi/hwpf/model/OldCHPBinTable.java index 146fd3b3f7..93090d35aa 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/OldCHPBinTable.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/OldCHPBinTable.java @@ -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(); diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestCHPBinTable.java b/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestCHPBinTable.java index 40d5a6326c..c2b8789011 100644 --- a/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestCHPBinTable.java +++ b/src/scratchpad/testcases/org/apache/poi/hwpf/model/TestCHPBinTable.java @@ -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;