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
This commit is contained in:
Sergey Vladimirov 2011-07-09 16:10:57 +00:00
parent bb9b395b69
commit 6b96874866
5 changed files with 45 additions and 19 deletions

View 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

View 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();

View 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)));

View 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();

View 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;