Adjust toString() of ExternalNameRecord

Fix some IntelliJ warnings
 Reformat TextPieceTable

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1773776 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Dominik Stadler 2016-12-12 11:41:07 +00:00
parent 701b19cf21
commit 230453d76e
4 changed files with 146 additions and 212 deletions

View File

@ -214,15 +214,15 @@ public final class ExternalNameRecord extends StandardRecord {
@Override @Override
public String toString() { public String toString() {
StringBuffer sb = new StringBuffer(); StringBuilder sb = new StringBuilder();
sb.append("[EXTERNALNAME]\n"); sb.append("[EXTERNALNAME]\n");
sb.append(" .options = ").append(field_1_option_flag).append("\n"); sb.append(" .options = ").append(field_1_option_flag).append("\n");
sb.append(" .ix = ").append(field_2_ixals).append("\n"); sb.append(" .ix = ").append(field_2_ixals).append("\n");
sb.append(" .name = ").append(field_4_name).append("\n"); sb.append(" .name = ").append(field_4_name).append("\n");
if(field_5_name_definition != null) { if(field_5_name_definition != null) {
Ptg[] ptgs = field_5_name_definition.getTokens(); Ptg[] ptgs = field_5_name_definition.getTokens();
for (Ptg ptg : ptgs) { for (Ptg ptg : ptgs) {
sb.append(ptg.toString()).append(ptg.getRVAType()).append("\n"); sb.append(" .namedef = ").append(ptg.toString()).append(ptg.getRVAType()).append("\n");
} }
} }
sb.append("[/EXTERNALNAME]\n"); sb.append("[/EXTERNALNAME]\n");

View File

@ -163,6 +163,7 @@ public class XSSFSheetXMLHandler extends DefaultHandler {
private void init() { private void init() {
if (commentsTable != null) { if (commentsTable != null) {
commentCellRefs = new LinkedList<CellAddress>(); commentCellRefs = new LinkedList<CellAddress>();
//noinspection deprecation
for (CTComment comment : commentsTable.getCTComments().getCommentList().getCommentArray()) { for (CTComment comment : commentsTable.getCTComments().getCommentList().getCommentArray()) {
commentCellRefs.add(new CellAddress(comment.getRef())); commentCellRefs.add(new CellAddress(comment.getRef()));
} }
@ -228,10 +229,10 @@ public class XSSFSheetXMLHandler extends DefaultHandler {
// match the current cell // match the current cell
if(formulasNotResults) { if(formulasNotResults) {
logger.log(POILogger.WARN, "shared formulas not yet supported!"); logger.log(POILogger.WARN, "shared formulas not yet supported!");
} else { } /*else {
// It's a shared formula, so we can't get at the formula string yet // It's a shared formula, so we can't get at the formula string yet
// However, they don't care about the formula string, so that's ok! // However, they don't care about the formula string, so that's ok!
} }*/
} }
} else { } else {
fIsOpen = true; fIsOpen = true;
@ -334,7 +335,7 @@ public class XSSFSheetXMLHandler extends DefaultHandler {
thisStr = fv; thisStr = fv;
} }
} else { } else {
// No formating applied, just do raw value in all cases // No formatting applied, just do raw value in all cases
thisStr = fv; thisStr = fv;
} }
} }

View File

@ -34,59 +34,52 @@ import org.apache.poi.util.POILogger;
* The piece table for matching up character positions to bits of text. This * The piece table for matching up character positions to bits of text. This
* mostly works in bytes, but the TextPieces themselves work in characters. This * mostly works in bytes, but the TextPieces themselves work in characters. This
* does the icky convertion. * does the icky convertion.
* *
* @author Ryan Ackley * @author Ryan Ackley
*/ */
@Internal @Internal
public class TextPieceTable implements CharIndexTranslator public class TextPieceTable implements CharIndexTranslator {
{
private static final POILogger logger = POILogFactory private static final POILogger logger = POILogFactory
.getLogger( TextPieceTable.class ); .getLogger(TextPieceTable.class);
// int _multiple; // int _multiple;
int _cpMin; int _cpMin;
protected ArrayList<TextPiece> _textPieces = new ArrayList<TextPiece>(); protected ArrayList<TextPiece> _textPieces = new ArrayList<TextPiece>();
protected ArrayList<TextPiece> _textPiecesFCOrder = new ArrayList<TextPiece>(); protected ArrayList<TextPiece> _textPiecesFCOrder = new ArrayList<TextPiece>();
public TextPieceTable() public TextPieceTable() {
{
} }
public TextPieceTable( byte[] documentStream, byte[] tableStream, public TextPieceTable(byte[] documentStream, byte[] tableStream,
int offset, int size, int fcMin ) int offset, int size, int fcMin) {
{
// get our plex of PieceDescriptors // get our plex of PieceDescriptors
PlexOfCps pieceTable = new PlexOfCps( tableStream, offset, size, PlexOfCps pieceTable = new PlexOfCps(tableStream, offset, size,
PieceDescriptor.getSizeInBytes() ); PieceDescriptor.getSizeInBytes());
int length = pieceTable.length(); int length = pieceTable.length();
PieceDescriptor[] pieces = new PieceDescriptor[length]; PieceDescriptor[] pieces = new PieceDescriptor[length];
// iterate through piece descriptors raw bytes and create // iterate through piece descriptors raw bytes and create
// PieceDescriptor objects // PieceDescriptor objects
for ( int x = 0; x < length; x++ ) for (int x = 0; x < length; x++) {
{ GenericPropertyNode node = pieceTable.getProperty(x);
GenericPropertyNode node = pieceTable.getProperty( x ); pieces[x] = new PieceDescriptor(node.getBytes(), 0);
pieces[x] = new PieceDescriptor( node.getBytes(), 0 );
} }
// Figure out the cp of the earliest text piece // Figure out the cp of the earliest text piece
// Note that text pieces don't have to be stored in order! // Note that text pieces don't have to be stored in order!
_cpMin = pieces[0].getFilePosition() - fcMin; _cpMin = pieces[0].getFilePosition() - fcMin;
for ( int x = 0; x < pieces.length; x++ ) for (PieceDescriptor piece : pieces) {
{ int start = piece.getFilePosition() - fcMin;
int start = pieces[x].getFilePosition() - fcMin; if (start < _cpMin) {
if ( start < _cpMin )
{
_cpMin = start; _cpMin = start;
} }
} }
// using the PieceDescriptors, build our list of TextPieces. // using the PieceDescriptors, build our list of TextPieces.
for ( int x = 0; x < pieces.length; x++ ) for (int x = 0; x < pieces.length; x++) {
{
int start = pieces[x].getFilePosition(); int start = pieces[x].getFilePosition();
GenericPropertyNode node = pieceTable.getProperty( x ); GenericPropertyNode node = pieceTable.getProperty(x);
// Grab the start and end, which are in characters // Grab the start and end, which are in characters
int nodeStartChars = node.getStart(); int nodeStartChars = node.getStart();
@ -95,82 +88,72 @@ public class TextPieceTable implements CharIndexTranslator
// What's the relationship between bytes and characters? // What's the relationship between bytes and characters?
boolean unicode = pieces[x].isUnicode(); boolean unicode = pieces[x].isUnicode();
int multiple = 1; int multiple = 1;
if ( unicode ) if (unicode) {
{
multiple = 2; multiple = 2;
} }
// Figure out the length, in bytes and chars // Figure out the length, in bytes and chars
int textSizeChars = ( nodeEndChars - nodeStartChars ); int textSizeChars = (nodeEndChars - nodeStartChars);
int textSizeBytes = textSizeChars * multiple; int textSizeBytes = textSizeChars * multiple;
// Grab the data that makes up the piece // Grab the data that makes up the piece
byte[] buf = new byte[textSizeBytes]; byte[] buf = new byte[textSizeBytes];
System.arraycopy( documentStream, start, buf, 0, textSizeBytes ); System.arraycopy(documentStream, start, buf, 0, textSizeBytes);
// And now build the piece // And now build the piece
final TextPiece newTextPiece = new TextPiece( nodeStartChars, nodeEndChars, buf, final TextPiece newTextPiece = new TextPiece(nodeStartChars, nodeEndChars, buf,
pieces[x] ); pieces[x]);
_textPieces.add( newTextPiece ); _textPieces.add(newTextPiece);
} }
// In the interest of our sanity, now sort the text pieces // In the interest of our sanity, now sort the text pieces
// into order, if they're not already // into order, if they're not already
Collections.sort( _textPieces ); Collections.sort(_textPieces);
_textPiecesFCOrder = new ArrayList<TextPiece>( _textPieces ); _textPiecesFCOrder = new ArrayList<TextPiece>(_textPieces);
Collections.sort( _textPiecesFCOrder, new FCComparator() ); Collections.sort(_textPiecesFCOrder, new FCComparator());
} }
public void add( TextPiece piece ) public void add(TextPiece piece) {
{ _textPieces.add(piece);
_textPieces.add( piece ); _textPiecesFCOrder.add(piece);
_textPiecesFCOrder.add( piece ); Collections.sort(_textPieces);
Collections.sort( _textPieces ); Collections.sort(_textPiecesFCOrder, new FCComparator());
Collections.sort( _textPiecesFCOrder, new FCComparator() );
} }
/** /**
* Adjust all the text piece after inserting some text into one of them * Adjust all the text piece after inserting some text into one of them
* *
* @param listIndex * @param listIndex The TextPiece that had characters inserted into
* The TextPiece that had characters inserted into * @param length The number of characters inserted
* @param length
* The number of characters inserted
*/ */
public int adjustForInsert( int listIndex, int length ) public int adjustForInsert(int listIndex, int length) {
{
int size = _textPieces.size(); int size = _textPieces.size();
TextPiece tp = _textPieces.get( listIndex ); TextPiece tp = _textPieces.get(listIndex);
// Update with the new end // Update with the new end
tp.setEnd( tp.getEnd() + length ); tp.setEnd(tp.getEnd() + length);
// Now change all subsequent ones // Now change all subsequent ones
for ( int x = listIndex + 1; x < size; x++ ) for (int x = listIndex + 1; x < size; x++) {
{ tp = _textPieces.get(x);
tp = _textPieces.get( x ); tp.setStart(tp.getStart() + length);
tp.setStart( tp.getStart() + length ); tp.setEnd(tp.getEnd() + length);
tp.setEnd( tp.getEnd() + length );
} }
// All done // All done
return length; return length;
} }
public boolean equals( Object o ) public boolean equals(Object o) {
{
if (!(o instanceof TextPieceTable)) return false; if (!(o instanceof TextPieceTable)) return false;
TextPieceTable tpt = (TextPieceTable) o; TextPieceTable tpt = (TextPieceTable) o;
int size = tpt._textPieces.size(); int size = tpt._textPieces.size();
if ( size == _textPieces.size() ) if (size == _textPieces.size()) {
{ for (int x = 0; x < size; x++) {
for ( int x = 0; x < size; x++ ) if (!tpt._textPieces.get(x).equals(_textPieces.get(x))) {
{
if ( !tpt._textPieces.get( x ).equals( _textPieces.get( x ) ) )
{
return false; return false;
} }
} }
@ -179,27 +162,23 @@ public class TextPieceTable implements CharIndexTranslator
return false; return false;
} }
public int getByteIndex( int charPos ) public int getByteIndex(int charPos) {
{
int byteCount = 0; int byteCount = 0;
for ( TextPiece tp : _textPieces ) for (TextPiece tp : _textPieces) {
{ if (charPos >= tp.getEnd()) {
if ( charPos >= tp.getEnd() )
{
byteCount = tp.getPieceDescriptor().getFilePosition() byteCount = tp.getPieceDescriptor().getFilePosition()
+ ( tp.getEnd() - tp.getStart() ) + (tp.getEnd() - tp.getStart())
* ( tp.isUnicode() ? 2 : 1 ); * (tp.isUnicode() ? 2 : 1);
if ( charPos == tp.getEnd() ) if (charPos == tp.getEnd())
break; break;
continue; continue;
} }
if ( charPos < tp.getEnd() ) if (charPos < tp.getEnd()) {
{
int left = charPos - tp.getStart(); int left = charPos - tp.getStart();
byteCount = tp.getPieceDescriptor().getFilePosition() + left byteCount = tp.getPieceDescriptor().getFilePosition() + left
* ( tp.isUnicode() ? 2 : 1 ); * (tp.isUnicode() ? 2 : 1);
break; break;
} }
} }
@ -207,20 +186,17 @@ public class TextPieceTable implements CharIndexTranslator
} }
@Deprecated @Deprecated
public int getCharIndex( int bytePos ) public int getCharIndex(int bytePos) {
{ return getCharIndex(bytePos, 0);
return getCharIndex( bytePos, 0 );
} }
@Deprecated @Deprecated
public int getCharIndex( int startBytePos, int startCP ) public int getCharIndex(int startBytePos, int startCP) {
{
int charCount = 0; int charCount = 0;
int bytePos = lookIndexForward( startBytePos ); int bytePos = lookIndexForward(startBytePos);
for ( TextPiece tp : _textPieces ) for (TextPiece tp : _textPieces) {
{
int pieceStart = tp.getPieceDescriptor().getFilePosition(); int pieceStart = tp.getPieceDescriptor().getFilePosition();
int bytesLength = tp.bytesLength(); int bytesLength = tp.bytesLength();
@ -228,31 +204,22 @@ public class TextPieceTable implements CharIndexTranslator
int toAdd; int toAdd;
if ( bytePos < pieceStart || bytePos > pieceEnd ) if (bytePos < pieceStart || bytePos > pieceEnd) {
{
toAdd = bytesLength; toAdd = bytesLength;
} } else if (bytePos > pieceStart && bytePos < pieceEnd) {
else if ( bytePos > pieceStart && bytePos < pieceEnd ) toAdd = (bytePos - pieceStart);
{ } else {
toAdd = ( bytePos - pieceStart ); toAdd = bytesLength - (pieceEnd - bytePos);
}
else
{
toAdd = bytesLength - ( pieceEnd - bytePos );
} }
if ( tp.isUnicode() ) if (tp.isUnicode()) {
{
charCount += toAdd / 2; charCount += toAdd / 2;
} } else {
else
{
charCount += toAdd; charCount += toAdd;
} }
if ( bytePos >= pieceStart && bytePos <= pieceEnd if (bytePos >= pieceStart && bytePos <= pieceEnd
&& charCount >= startCP ) && charCount >= startCP) {
{
break; break;
} }
} }
@ -261,106 +228,94 @@ public class TextPieceTable implements CharIndexTranslator
} }
@Override @Override
public int[][] getCharIndexRanges( int startBytePosInclusive, public int[][] getCharIndexRanges(int startBytePosInclusive,
int endBytePosExclusive ) int endBytePosExclusive) {
{
List<int[]> result = new LinkedList<int[]>(); List<int[]> result = new LinkedList<int[]>();
for ( TextPiece textPiece : _textPiecesFCOrder ) for (TextPiece textPiece : _textPiecesFCOrder) {
{
final int tpStart = textPiece.getPieceDescriptor() final int tpStart = textPiece.getPieceDescriptor()
.getFilePosition(); .getFilePosition();
final int tpEnd = textPiece.getPieceDescriptor().getFilePosition() final int tpEnd = textPiece.getPieceDescriptor().getFilePosition()
+ textPiece.bytesLength(); + textPiece.bytesLength();
if ( startBytePosInclusive > tpEnd ) if (startBytePosInclusive > tpEnd)
continue; continue;
if ( endBytePosExclusive <= tpStart ) if (endBytePosExclusive <= tpStart)
break; break;
final int rangeStartBytes = Math.max( tpStart, final int rangeStartBytes = Math.max(tpStart,
startBytePosInclusive ); startBytePosInclusive);
final int rangeEndBytes = Math.min( tpEnd, endBytePosExclusive ); final int rangeEndBytes = Math.min(tpEnd, endBytePosExclusive);
final int rangeLengthBytes = rangeEndBytes - rangeStartBytes; final int rangeLengthBytes = rangeEndBytes - rangeStartBytes;
if ( rangeStartBytes > rangeEndBytes ) if (rangeStartBytes > rangeEndBytes)
continue; continue;
final int encodingMultiplier = textPiece.isUnicode() ? 2 : 1; final int encodingMultiplier = textPiece.isUnicode() ? 2 : 1;
final int rangeStartCp = textPiece.getStart() final int rangeStartCp = textPiece.getStart()
+ ( rangeStartBytes - tpStart ) / encodingMultiplier; + (rangeStartBytes - tpStart) / encodingMultiplier;
final int rangeEndCp = rangeStartCp + rangeLengthBytes final int rangeEndCp = rangeStartCp + rangeLengthBytes
/ encodingMultiplier; / encodingMultiplier;
result.add( new int[] { rangeStartCp, rangeEndCp } ); result.add(new int[]{rangeStartCp, rangeEndCp});
} }
return result.toArray( new int[result.size()][] ); return result.toArray(new int[result.size()][]);
} }
public int getCpMin() public int getCpMin() {
{
return _cpMin; return _cpMin;
} }
public StringBuilder getText() public StringBuilder getText() {
{
final long start = System.currentTimeMillis(); final long start = System.currentTimeMillis();
// rebuild document paragraphs structure // rebuild document paragraphs structure
StringBuilder docText = new StringBuilder(); StringBuilder docText = new StringBuilder();
for ( TextPiece textPiece : _textPieces ) for (TextPiece textPiece : _textPieces) {
{
String toAppend = textPiece.getStringBuilder().toString(); String toAppend = textPiece.getStringBuilder().toString();
int toAppendLength = toAppend.length(); int toAppendLength = toAppend.length();
if ( toAppendLength != textPiece.getEnd() - textPiece.getStart() ) if (toAppendLength != textPiece.getEnd() - textPiece.getStart()) {
{
logger.log( logger.log(
POILogger.WARN, POILogger.WARN,
"Text piece has boundaries [", "Text piece has boundaries [",
Integer.valueOf( textPiece.getStart() ), Integer.valueOf(textPiece.getStart()),
"; ", "; ",
Integer.valueOf( textPiece.getEnd() ), Integer.valueOf(textPiece.getEnd()),
") but length ", ") but length ",
Integer.valueOf( textPiece.getEnd() Integer.valueOf(textPiece.getEnd()
- textPiece.getStart() ) ); - textPiece.getStart()));
} }
docText.replace( textPiece.getStart(), textPiece.getStart() docText.replace(textPiece.getStart(), textPiece.getStart()
+ toAppendLength, toAppend ); + toAppendLength, toAppend);
} }
logger.log( POILogger.DEBUG, "Document text were rebuilded in ", logger.log(POILogger.DEBUG, "Document text were rebuilded in ",
Long.valueOf( System.currentTimeMillis() - start ), " ms (", Long.valueOf(System.currentTimeMillis() - start), " ms (",
Integer.valueOf( docText.length() ), " chars)" ); Integer.valueOf(docText.length()), " chars)");
return docText; return docText;
} }
public List<TextPiece> getTextPieces() public List<TextPiece> getTextPieces() {
{
return _textPieces; return _textPieces;
} }
@Override @Override
public int hashCode() public int hashCode() {
{
return _textPieces.size(); return _textPieces.size();
} }
public boolean isIndexInTable( int bytePos ) public boolean isIndexInTable(int bytePos) {
{ for (TextPiece tp : _textPiecesFCOrder) {
for ( TextPiece tp : _textPiecesFCOrder )
{
int pieceStart = tp.getPieceDescriptor().getFilePosition(); int pieceStart = tp.getPieceDescriptor().getFilePosition();
if ( bytePos > pieceStart + tp.bytesLength() ) if (bytePos > pieceStart + tp.bytesLength()) {
{
continue; continue;
} }
if ( pieceStart > bytePos ) if (pieceStart > bytePos) {
{
return false; return false;
} }
@ -370,21 +325,18 @@ public class TextPieceTable implements CharIndexTranslator
return false; return false;
} }
boolean isIndexInTable( int startBytePos, int endBytePos ) boolean isIndexInTable(int startBytePos, int endBytePos) {
{ for (TextPiece tp : _textPiecesFCOrder) {
for ( TextPiece tp : _textPiecesFCOrder )
{
int pieceStart = tp.getPieceDescriptor().getFilePosition(); int pieceStart = tp.getPieceDescriptor().getFilePosition();
if ( startBytePos >= pieceStart + tp.bytesLength() ) if (startBytePos >= pieceStart + tp.bytesLength()) {
{
continue; continue;
} }
int left = Math.max( startBytePos, pieceStart ); int left = Math.max(startBytePos, pieceStart);
int right = Math.min( endBytePos, pieceStart + tp.bytesLength() ); int right = Math.min(endBytePos, pieceStart + tp.bytesLength());
if ( left >= right ) if (left >= right)
return false; return false;
return true; return true;
@ -393,23 +345,19 @@ public class TextPieceTable implements CharIndexTranslator
return false; return false;
} }
public int lookIndexBackward( final int startBytePos ) public int lookIndexBackward(final int startBytePos) {
{
int bytePos = startBytePos; int bytePos = startBytePos;
int lastEnd = 0; int lastEnd = 0;
for ( TextPiece tp : _textPiecesFCOrder ) for (TextPiece tp : _textPiecesFCOrder) {
{
int pieceStart = tp.getPieceDescriptor().getFilePosition(); int pieceStart = tp.getPieceDescriptor().getFilePosition();
if ( bytePos > pieceStart + tp.bytesLength() ) if (bytePos > pieceStart + tp.bytesLength()) {
{
lastEnd = pieceStart + tp.bytesLength(); lastEnd = pieceStart + tp.bytesLength();
continue; continue;
} }
if ( pieceStart > bytePos ) if (pieceStart > bytePos) {
{
bytePos = lastEnd; bytePos = lastEnd;
} }
@ -419,101 +367,87 @@ public class TextPieceTable implements CharIndexTranslator
return bytePos; return bytePos;
} }
public int lookIndexForward( final int startBytePos ) public int lookIndexForward(final int startBytePos) {
{ if (_textPiecesFCOrder.isEmpty())
if ( _textPiecesFCOrder.isEmpty() ) throw new IllegalStateException("Text pieces table is empty");
throw new IllegalStateException( "Text pieces table is empty" );
if ( _textPiecesFCOrder.get( 0 ).getPieceDescriptor().getFilePosition() > startBytePos ) if (_textPiecesFCOrder.get(0).getPieceDescriptor().getFilePosition() > startBytePos)
return _textPiecesFCOrder.get( 0 ).getPieceDescriptor().getFilePosition(); return _textPiecesFCOrder.get(0).getPieceDescriptor().getFilePosition();
if ( _textPiecesFCOrder.get( _textPiecesFCOrder.size() - 1 ) if (_textPiecesFCOrder.get(_textPiecesFCOrder.size() - 1)
.getPieceDescriptor().getFilePosition() <= startBytePos ) .getPieceDescriptor().getFilePosition() <= startBytePos)
return startBytePos; return startBytePos;
int low = 0; int low = 0;
int high = _textPiecesFCOrder.size() - 1; int high = _textPiecesFCOrder.size() - 1;
while ( low <= high ) while (low <= high) {
{ int mid = (low + high) >>> 1;
int mid = ( low + high ) >>> 1; final TextPiece textPiece = _textPiecesFCOrder.get(mid);
final TextPiece textPiece = _textPiecesFCOrder.get( mid );
int midVal = textPiece.getPieceDescriptor().getFilePosition(); int midVal = textPiece.getPieceDescriptor().getFilePosition();
if ( midVal < startBytePos ) if (midVal < startBytePos)
low = mid + 1; low = mid + 1;
else if ( midVal > startBytePos ) else if (midVal > startBytePos)
high = mid - 1; high = mid - 1;
else else
// found piece with exact start // found piece with exact start
return textPiece.getPieceDescriptor().getFilePosition(); return textPiece.getPieceDescriptor().getFilePosition();
} }
assert low == high; assert low == high;
assert _textPiecesFCOrder.get( low ).getPieceDescriptor() assert _textPiecesFCOrder.get(low).getPieceDescriptor()
.getFilePosition() < startBytePos; .getFilePosition() < startBytePos;
// last line can't be current, can it? // last line can't be current, can it?
assert _textPiecesFCOrder.get( low + 1 ).getPieceDescriptor() assert _textPiecesFCOrder.get(low + 1).getPieceDescriptor()
.getFilePosition() > startBytePos; .getFilePosition() > startBytePos;
// shifting to next piece start // shifting to next piece start
return _textPiecesFCOrder.get( low + 1 ).getPieceDescriptor().getFilePosition(); return _textPiecesFCOrder.get(low + 1).getPieceDescriptor().getFilePosition();
} }
public byte[] writeTo( HWPFOutputStream docStream ) throws IOException public byte[] writeTo(HWPFOutputStream docStream) throws IOException {
{ PlexOfCps textPlex = new PlexOfCps(PieceDescriptor.getSizeInBytes());
PlexOfCps textPlex = new PlexOfCps( PieceDescriptor.getSizeInBytes() );
// int fcMin = docStream.getOffset(); // int fcMin = docStream.getOffset();
int size = _textPieces.size(); for (TextPiece next : _textPieces) {
for ( int x = 0; x < size; x++ )
{
TextPiece next = _textPieces.get( x );
PieceDescriptor pd = next.getPieceDescriptor(); PieceDescriptor pd = next.getPieceDescriptor();
int offset = docStream.getOffset(); int offset = docStream.getOffset();
int mod = ( offset % POIFSConstants.SMALLER_BIG_BLOCK_SIZE ); int mod = (offset % POIFSConstants.SMALLER_BIG_BLOCK_SIZE);
if ( mod != 0 ) if (mod != 0) {
{
mod = POIFSConstants.SMALLER_BIG_BLOCK_SIZE - mod; mod = POIFSConstants.SMALLER_BIG_BLOCK_SIZE - mod;
byte[] buf = new byte[mod]; byte[] buf = new byte[mod];
docStream.write( buf ); docStream.write(buf);
} }
// set the text piece position to the current docStream offset. // set the text piece position to the current docStream offset.
pd.setFilePosition( docStream.getOffset() ); pd.setFilePosition(docStream.getOffset());
// write the text to the docstream and save the piece descriptor to // write the text to the docstream and save the piece descriptor to
// the // the
// plex which will be written later to the tableStream. // plex which will be written later to the tableStream.
docStream.write( next.getRawBytes() ); docStream.write(next.getRawBytes());
// The TextPiece is already in characters, which // The TextPiece is already in characters, which
// makes our life much easier // makes our life much easier
int nodeStart = next.getStart(); int nodeStart = next.getStart();
int nodeEnd = next.getEnd(); int nodeEnd = next.getEnd();
textPlex.addProperty( new GenericPropertyNode( nodeStart, nodeEnd, textPlex.addProperty(new GenericPropertyNode(nodeStart, nodeEnd,
pd.toByteArray() ) ); pd.toByteArray()));
} }
return textPlex.toByteArray(); return textPlex.toByteArray();
} }
private static class FCComparator implements Comparator<TextPiece>, Serializable private static class FCComparator implements Comparator<TextPiece>, Serializable {
{ public int compare(TextPiece textPiece, TextPiece textPiece1) {
public int compare( TextPiece textPiece, TextPiece textPiece1 ) if (textPiece.getPieceDescriptor().fc > textPiece1
{ .getPieceDescriptor().fc) {
if ( textPiece.getPieceDescriptor().fc > textPiece1
.getPieceDescriptor().fc )
{
return 1; return 1;
} } else if (textPiece.getPieceDescriptor().fc < textPiece1
else if ( textPiece.getPieceDescriptor().fc < textPiece1 .getPieceDescriptor().fc) {
.getPieceDescriptor().fc )
{
return -1; return -1;
} } else {
else
{
return 0; return 0;
} }
} }

View File

@ -118,7 +118,6 @@ public final class TestFormulaBugs {
/** /**
* Bug 42448 - Can't parse SUMPRODUCT(A!C7:A!C67, B8:B68) / B69 <p/> * Bug 42448 - Can't parse SUMPRODUCT(A!C7:A!C67, B8:B68) / B69 <p/>
* @throws IOException
*/ */
@Test @Test
public void test42448() throws IOException { public void test42448() throws IOException {