move rebuild actions to new methods (in future - to new classes)

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1150635 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Sergey Vladimirov 2011-07-25 11:31:16 +00:00
parent efdd335f77
commit 689ef50fbf
10 changed files with 48 additions and 101 deletions

View File

@ -250,8 +250,11 @@ public final class HWPFDocument extends HWPFDocumentCore
// Now load the rest of the properties, which need to be adjusted // Now load the rest of the properties, which need to be adjusted
// for where text really begin // for where text really begin
_cbt = new CHPBinTable(_mainStream, _tableStream, _fib.getFcPlcfbteChpx(), _fib.getLcbPlcfbteChpx(), _cft, _tpt, true); _cbt = new CHPBinTable(_mainStream, _tableStream, _fib.getFcPlcfbteChpx(), _fib.getLcbPlcfbteChpx(), _tpt);
_pbt = new PAPBinTable(_mainStream, _tableStream, _dataStream, _fib.getFcPlcfbtePapx(), _fib.getLcbPlcfbtePapx(), _cft, _tpt, true); _pbt = new PAPBinTable(_mainStream, _tableStream, _dataStream, _fib.getFcPlcfbtePapx(), _fib.getLcbPlcfbtePapx(), _tpt);
_cbt.rebuild( _cft );
_pbt.rebuild( _dataStream, _cft );
// Read FSPA and Escher information // Read FSPA and Escher information
_fspa = new FSPATable(_tableStream, _fib.getFcPlcspaMom(), _fib.getLcbPlcspaMom(), getTextTable().getTextPieces()); _fspa = new FSPATable(_tableStream, _fib.getFcPlcspaMom(), _fib.getLcbPlcspaMom(), getTextTable().getTextPieces());

View File

@ -407,7 +407,7 @@ public final class HWPFLister
PAPFormattedDiskPage pfkp = new PAPFormattedDiskPage( PAPFormattedDiskPage pfkp = new PAPFormattedDiskPage(
mainStream, doc.getDataStream(), pageOffset, mainStream, doc.getDataStream(), pageOffset,
doc.getTextTable(), false ); doc.getTextTable() );
System.out.println( "* PFKP: " + pfkp ); System.out.println( "* PFKP: " + pfkp );

View File

@ -65,21 +65,20 @@ public class CHPBinTable
* Constructor used to read a binTable in from a Word document. * Constructor used to read a binTable in from a Word document.
* *
* @deprecated Use * @deprecated Use
* {@link #CHPBinTable(byte[],byte[],int,int,ComplexFileTable,TextPieceTable, boolean)} * {@link #CHPBinTable(byte[],byte[],int,int,TextPieceTable)}
* instead * instead
*/ */
public CHPBinTable( byte[] documentStream, byte[] tableStream, int offset, public CHPBinTable( byte[] documentStream, byte[] tableStream, int offset,
int size, int fcMin, TextPieceTable tpt ) int size, int fcMin, TextPieceTable tpt )
{ {
this( documentStream, tableStream, offset, size, null, tpt, true ); this( documentStream, tableStream, offset, size, tpt );
} }
/** /**
* Constructor used to read a binTable in from a Word document. * Constructor used to read a binTable in from a Word document.
*/ */
public CHPBinTable( byte[] documentStream, byte[] tableStream, int offset, public CHPBinTable( byte[] documentStream, byte[] tableStream, int offset,
int size, ComplexFileTable complexFileTable, TextPieceTable tpt, int size, TextPieceTable tpt )
boolean reconstructChpxTable )
{ {
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
/* /*
@ -102,7 +101,7 @@ public class CHPBinTable
int pageOffset = POIFSConstants.SMALLER_BIG_BLOCK_SIZE * pageNum; int pageOffset = POIFSConstants.SMALLER_BIG_BLOCK_SIZE * pageNum;
CHPFormattedDiskPage cfkp = new CHPFormattedDiskPage(documentStream, CHPFormattedDiskPage cfkp = new CHPFormattedDiskPage(documentStream,
pageOffset, tpt, reconstructChpxTable); pageOffset, tpt);
int fkpSize = cfkp.size(); int fkpSize = cfkp.size();
@ -116,16 +115,11 @@ public class CHPBinTable
logger.log( POILogger.DEBUG, "CHPX FKPs loaded in ", logger.log( POILogger.DEBUG, "CHPX FKPs loaded in ",
Long.valueOf( System.currentTimeMillis() - start ), " ms (", Long.valueOf( System.currentTimeMillis() - start ), " ms (",
Integer.valueOf( _textRuns.size() ), " elements)" ); Integer.valueOf( _textRuns.size() ), " elements)" );
start = System.currentTimeMillis(); }
if ( !reconstructChpxTable ) public void rebuild( ComplexFileTable complexFileTable )
{ {
Collections.sort( _textRuns ); long start = System.currentTimeMillis();
logger.log( POILogger.DEBUG, "CHPX sorted in ",
Long.valueOf( System.currentTimeMillis() - start ), " ms" );
return;
}
if ( complexFileTable != null ) if ( complexFileTable != null )
{ {
@ -359,14 +353,14 @@ public class CHPBinTable
iterator.remove(); iterator.remove();
continue; continue;
} }
previous = current; previous = current;
} }
logger.log( POILogger.DEBUG, "CHPX compacted in ", logger.log( POILogger.DEBUG, "CHPX compacted in ",
Long.valueOf( System.currentTimeMillis() - start ), " ms (", Long.valueOf( System.currentTimeMillis() - start ), " ms (",
Integer.valueOf( _textRuns.size() ), " elements)" ); Integer.valueOf( _textRuns.size() ), " elements)" );
} }
private static int binarySearch( List<CHPX> chpxs, int startPosition ) private static int binarySearch( List<CHPX> chpxs, int startPosition )
{ {

View File

@ -20,6 +20,7 @@ package org.apache.poi.hwpf.model;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.apache.poi.hwpf.sprm.SprmBuffer;
import org.apache.poi.util.LittleEndian; import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.POILogFactory; import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger; import org.apache.poi.util.POILogger;
@ -60,14 +61,14 @@ public final class CHPFormattedDiskPage extends FormattedDiskPage
* read from a Word file). * read from a Word file).
* *
* @deprecated Use * @deprecated Use
* {@link #CHPFormattedDiskPage(byte[],int,TextPieceTable,boolean)} * {@link #CHPFormattedDiskPage(byte[],int,TextPieceTable)}
* instead * instead
*/ */
@SuppressWarnings( "unused" ) @SuppressWarnings( "unused" )
public CHPFormattedDiskPage( byte[] documentStream, int offset, int fcMin, public CHPFormattedDiskPage( byte[] documentStream, int offset, int fcMin,
TextPieceTable tpt ) TextPieceTable tpt )
{ {
this( documentStream, offset, tpt, true ); this( documentStream, offset, tpt );
} }
/** /**
@ -75,39 +76,23 @@ public final class CHPFormattedDiskPage extends FormattedDiskPage
* read from a Word file). * read from a Word file).
*/ */
public CHPFormattedDiskPage( byte[] documentStream, int offset, public CHPFormattedDiskPage( byte[] documentStream, int offset,
TextPieceTable tpt, boolean ignoreChpxWithoutTextPieces ) TextPieceTable tpt )
{ {
super( documentStream, offset ); super( documentStream, offset );
for ( int x = 0; x < _crun; x++ ) for ( int x = 0; x < _crun; x++ )
{ {
int startAt = getStart( x ); int bytesStartAt = getStart( x );
int endAt = getEnd( x ); int bytesEndAt = getEnd( x );
if ( ignoreChpxWithoutTextPieces int charStartAt = tpt.getCharIndex( bytesStartAt );
&& !tpt.isIndexInTable( startAt, endAt ) ) int charEndAt = tpt.getCharIndex( bytesEndAt, charStartAt );
{
logger.log( POILogger.WARN, "CHPX [",
Integer.valueOf( startAt ), "; ",
Integer.valueOf( endAt ),
") (bytes) doesn't have corresponding text pieces "
+ "and will be skipped" );
_chpxList.add( null );
continue;
}
CHPX chpx = new CHPX( startAt, endAt, tpt, getGrpprl( x ) );
if ( ignoreChpxWithoutTextPieces
&& chpx.getStart() == chpx.getEnd() )
{
logger.log( POILogger.WARN, chpx
+ " references zero-length range and will be skipped" );
_chpxList.add( null );
continue;
}
// TODO: CHECK!
// CHPX chpx = new CHPX( bytesStartAt, bytesEndAt, tpt, getGrpprl( x
// ) );
CHPX chpx = new CHPX( charStartAt, charEndAt, new SprmBuffer(
getGrpprl( x ), 0 ) );
_chpxList.add( chpx ); _chpxList.add( chpx );
} }
} }

View File

@ -55,7 +55,7 @@ public final class OldCHPBinTable extends CHPBinTable
int pageOffset = POIFSConstants.SMALLER_BIG_BLOCK_SIZE * pageNum; int pageOffset = POIFSConstants.SMALLER_BIG_BLOCK_SIZE * pageNum;
CHPFormattedDiskPage cfkp = new CHPFormattedDiskPage(documentStream, CHPFormattedDiskPage cfkp = new CHPFormattedDiskPage(documentStream,
pageOffset, tpt, true); pageOffset, tpt);
int fkpSize = cfkp.size(); int fkpSize = cfkp.size();

View File

@ -47,7 +47,7 @@ public final class OldPAPBinTable extends PAPBinTable
int pageOffset = POIFSConstants.SMALLER_BIG_BLOCK_SIZE * pageNum; int pageOffset = POIFSConstants.SMALLER_BIG_BLOCK_SIZE * pageNum;
PAPFormattedDiskPage pfkp = new PAPFormattedDiskPage(documentStream, PAPFormattedDiskPage pfkp = new PAPFormattedDiskPage(documentStream,
documentStream, pageOffset, tpt, true); documentStream, pageOffset, tpt);
int fkpSize = pfkp.size(); int fkpSize = pfkp.size();

View File

@ -33,6 +33,7 @@ import org.apache.poi.hwpf.sprm.SprmBuffer;
import org.apache.poi.hwpf.sprm.SprmIterator; import org.apache.poi.hwpf.sprm.SprmIterator;
import org.apache.poi.hwpf.sprm.SprmOperation; import org.apache.poi.hwpf.sprm.SprmOperation;
import org.apache.poi.poifs.common.POIFSConstants; import org.apache.poi.poifs.common.POIFSConstants;
import org.apache.poi.util.Internal;
import org.apache.poi.util.LittleEndian; import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.POILogFactory; import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger; import org.apache.poi.util.POILogger;
@ -44,6 +45,7 @@ import org.apache.poi.util.POILogger;
* *
* @author Ryan Ackley * @author Ryan Ackley
*/ */
@Internal
public class PAPBinTable public class PAPBinTable
{ {
private static final POILogger logger = POILogFactory private static final POILogger logger = POILogFactory
@ -69,13 +71,11 @@ public class PAPBinTable
byte[] dataStream, int offset, int size, int fcMin, byte[] dataStream, int offset, int size, int fcMin,
TextPieceTable tpt ) TextPieceTable tpt )
{ {
this( documentStream, tableStream, dataStream, offset, size, null, tpt, true ); this( documentStream, tableStream, dataStream, offset, size, tpt );
} }
public PAPBinTable( byte[] documentStream, byte[] tableStream, public PAPBinTable( byte[] documentStream, byte[] tableStream,
byte[] dataStream, int offset, int size, byte[] dataStream, int offset, int size, TextPieceTable tpt )
ComplexFileTable complexFileTable, TextPieceTable tpt,
boolean reconstructPapxTable )
{ {
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
@ -93,8 +93,7 @@ public class PAPBinTable
* pageNum; * pageNum;
PAPFormattedDiskPage pfkp = new PAPFormattedDiskPage( PAPFormattedDiskPage pfkp = new PAPFormattedDiskPage(
documentStream, dataStream, pageOffset, tpt, documentStream, dataStream, pageOffset, tpt );
reconstructPapxTable );
int fkpSize = pfkp.size(); int fkpSize = pfkp.size();
@ -111,16 +110,11 @@ public class PAPBinTable
logger.log( POILogger.DEBUG, "PAPX tables loaded in ", logger.log( POILogger.DEBUG, "PAPX tables loaded in ",
Long.valueOf( System.currentTimeMillis() - start ), " ms (", Long.valueOf( System.currentTimeMillis() - start ), " ms (",
Integer.valueOf( _paragraphs.size() ), " elements)" ); Integer.valueOf( _paragraphs.size() ), " elements)" );
start = System.currentTimeMillis(); }
if ( !reconstructPapxTable ) public void rebuild( byte[] dataStream, ComplexFileTable complexFileTable )
{ {
Collections.sort( _paragraphs ); long start = System.currentTimeMillis();
logger.log( POILogger.DEBUG, "PAPX sorted in ",
Long.valueOf( System.currentTimeMillis() - start ), " ms" );
return;
}
if ( complexFileTable != null ) if ( complexFileTable != null )
{ {

View File

@ -22,10 +22,8 @@ import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import org.apache.poi.hwpf.sprm.SprmBuffer; import org.apache.poi.util.Internal;
import org.apache.poi.util.LittleEndian; import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger;
/** /**
* Represents a PAP FKP. The style properties for paragraph and character runs * Represents a PAP FKP. The style properties for paragraph and character runs
@ -43,10 +41,8 @@ import org.apache.poi.util.POILogger;
* *
* @author Ryan Ackley * @author Ryan Ackley
*/ */
@Internal
public final class PAPFormattedDiskPage extends FormattedDiskPage { public final class PAPFormattedDiskPage extends FormattedDiskPage {
private static final POILogger logger = POILogFactory
.getLogger( PAPFormattedDiskPage.class );
private static final int BX_SIZE = 13; private static final int BX_SIZE = 13;
private static final int FC_SIZE = 4; private static final int FC_SIZE = 4;
@ -70,14 +66,14 @@ public final class PAPFormattedDiskPage extends FormattedDiskPage {
public PAPFormattedDiskPage( byte[] documentStream, byte[] dataStream, public PAPFormattedDiskPage( byte[] documentStream, byte[] dataStream,
int offset, int fcMin, TextPieceTable tpt ) int offset, int fcMin, TextPieceTable tpt )
{ {
this( documentStream, dataStream, offset, tpt, true ); this( documentStream, dataStream, offset, tpt );
} }
/** /**
* Creates a PAPFormattedDiskPage from a 512 byte array * Creates a PAPFormattedDiskPage from a 512 byte array
*/ */
public PAPFormattedDiskPage( byte[] documentStream, byte[] dataStream, public PAPFormattedDiskPage( byte[] documentStream, byte[] dataStream,
int offset, TextPieceTable tpt, boolean ignorePapxWithoutTextPieces ) int offset, TextPieceTable tpt )
{ {
super( documentStream, offset ); super( documentStream, offset );
for ( int x = 0; x < _crun; x++ ) for ( int x = 0; x < _crun; x++ )
@ -85,31 +81,8 @@ public final class PAPFormattedDiskPage extends FormattedDiskPage {
int startAt = getStart( x ); int startAt = getStart( x );
int endAt = getEnd( x ); int endAt = getEnd( x );
if ( ignorePapxWithoutTextPieces
&& !tpt.isIndexInTable( startAt, endAt ) )
{
logger.log( POILogger.WARN, "PAPX [",
Integer.valueOf( startAt ), "; ",
Integer.valueOf( endAt ),
") (bytes) doesn't have corresponding text pieces "
+ "and will be skipped\n\tSkipped SPRM: "
+ new SprmBuffer( getGrpprl( x ), 2 ) );
_papxList.add( null );
continue;
}
PAPX papx = new PAPX( startAt, endAt, tpt, getGrpprl( x ), PAPX papx = new PAPX( startAt, endAt, tpt, getGrpprl( x ),
getParagraphHeight( x ), dataStream ); getParagraphHeight( x ), dataStream );
if ( ignorePapxWithoutTextPieces
&& papx.getStart() == papx.getEnd() )
{
logger.log( POILogger.WARN, papx
+ " references zero-length range and will be skipped" );
_papxList.add( null );
continue;
}
_papxList.add( papx ); _papxList.add( papx );
} }
_fkp = null; _fkp = null;

View File

@ -46,7 +46,7 @@ public final class TestCHPBinTable
byte[] tableStream = _hWPFDocFixture._tableStream; byte[] tableStream = _hWPFDocFixture._tableStream;
int fcMin = fib.getFcMin(); int fcMin = fib.getFcMin();
_cHPBinTable = new CHPBinTable(mainStream, tableStream, fib.getFcPlcfbteChpx(), fib.getLcbPlcfbteChpx(), null, fakeTPT, false); _cHPBinTable = new CHPBinTable(mainStream, tableStream, fib.getFcPlcfbteChpx(), fib.getLcbPlcfbteChpx(), fakeTPT);
HWPFFileSystem fileSys = new HWPFFileSystem(); HWPFFileSystem fileSys = new HWPFFileSystem();
@ -57,7 +57,7 @@ public final class TestCHPBinTable
byte[] newTableStream = tableOut.toByteArray(); byte[] newTableStream = tableOut.toByteArray();
byte[] newMainStream = mainOut.toByteArray(); byte[] newMainStream = mainOut.toByteArray();
CHPBinTable newBinTable = new CHPBinTable(newMainStream, newTableStream, 0, newTableStream.length, null, fakeTPT, false); CHPBinTable newBinTable = new CHPBinTable(newMainStream, newTableStream, 0, newTableStream.length, fakeTPT);
ArrayList oldTextRuns = _cHPBinTable._textRuns; ArrayList oldTextRuns = _cHPBinTable._textRuns;
ArrayList newTextRuns = newBinTable._textRuns; ArrayList newTextRuns = newBinTable._textRuns;

View File

@ -49,8 +49,7 @@ public final class TestPAPBinTable extends TestCase
byte[] tableStream = _hWPFDocFixture._tableStream; byte[] tableStream = _hWPFDocFixture._tableStream;
PAPBinTable _pAPBinTable = new PAPBinTable( mainStream, tableStream, PAPBinTable _pAPBinTable = new PAPBinTable( mainStream, tableStream,
null, fib.getFcPlcfbtePapx(), fib.getLcbPlcfbtePapx(), null, null, fib.getFcPlcfbtePapx(), fib.getLcbPlcfbtePapx(), fakeTPT );
fakeTPT, false );
HWPFFileSystem fileSys = new HWPFFileSystem(); HWPFFileSystem fileSys = new HWPFFileSystem();
@ -62,8 +61,7 @@ public final class TestPAPBinTable extends TestCase
byte[] newMainStream = mainOut.toByteArray(); byte[] newMainStream = mainOut.toByteArray();
PAPBinTable newBinTable = new PAPBinTable( newMainStream, PAPBinTable newBinTable = new PAPBinTable( newMainStream,
newTableStream, null, 0, newTableStream.length, null, fakeTPT, newTableStream, null, 0, newTableStream.length, fakeTPT );
false );
List<PAPX> oldTextRuns = _pAPBinTable.getParagraphs(); List<PAPX> oldTextRuns = _pAPBinTable.getParagraphs();
List<PAPX> newTextRuns = newBinTable.getParagraphs(); List<PAPX> newTextRuns = newBinTable.getParagraphs();