List textRuns = cbt.getTextRuns();
Iterator runIt = textRuns.iterator();
Iterator textIt = textPieces.iterator();
TextPiece currentPiece = (TextPiece)textIt.next();
int currentTextStart = currentPiece.getStart();
int currentTextEnd = currentPiece.getEnd();
WordTextBuffer finalTextBuf = new WordTextBuffer();
// iterate through all text runs extract the text only if they haven't been
// deleted
while (runIt.hasNext())
{
CHPX chpx = (CHPX)runIt.next();
boolean deleted = isDeleted(chpx.getGrpprl());
if (deleted)
{
continue;
}
int runStart = chpx.getStart();
int runEnd = chpx.getEnd();
while (runStart >= currentTextEnd)
{
currentPiece = (TextPiece) textIt.next ();
currentTextStart = currentPiece.getStart ();
currentTextEnd = currentPiece.getEnd ();
}
if (runEnd < currentTextEnd)
{
String str = currentPiece.substring(runStart - currentTextStart, runEnd - currentTextStart);
finalTextBuf.append(str);
}
else if (runEnd > currentTextEnd)
{
while (runEnd > currentTextEnd)
{
String str = currentPiece.substring(runStart - currentTextStart,
currentTextEnd - currentTextStart);
finalTextBuf.append(str);
if (textIt.hasNext())
{
currentPiece = (TextPiece) textIt.next ();
currentTextStart = currentPiece.getStart ();
runStart = currentTextStart;
currentTextEnd = currentPiece.getEnd ();
}
else
{
return finalTextBuf.toString();
}
}
String str = currentPiece.substring(0, runEnd - currentTextStart);
finalTextBuf.append(str);
}
else
{
String str = currentPiece.substring(runStart - currentTextStart, runEnd - currentTextStart);
if (textIt.hasNext())
{
currentPiece = (TextPiece) textIt.next();
currentTextStart = currentPiece.getStart();
currentTextEnd = currentPiece.getEnd();
}
finalTextBuf.append(str);
}
}
return finalTextBuf.toString();