use of org.apache.poi.hwpf.model.SubdocumentType in project poi by apache.
the class TestBugs method test51604p2.
/**
* [RESOLVED FIXED] Bug 51604 - replace text fails for doc (poi 3.8 beta
* release from download site )
*/
@Test
public void test51604p2() throws Exception {
HWPFDocument doc = HWPFTestDataSamples.openSampleFile("Bug51604.doc");
Range range = doc.getRange();
int numParagraph = range.numParagraphs();
replaceText(range, numParagraph);
doc = HWPFTestDataSamples.writeOutAndReadBack(doc);
final FileInformationBlock fileInformationBlock = doc.getFileInformationBlock();
int totalLength = 0;
for (SubdocumentType type : SubdocumentType.values()) {
final int partLength = fileInformationBlock.getSubdocumentTextStreamLength(type);
assert (partLength >= 0);
totalLength += partLength;
}
assertEquals(doc.getText().length(), totalLength);
}
use of org.apache.poi.hwpf.model.SubdocumentType in project poi by apache.
the class Range method adjustFIB.
/**
* Adjust the value of the various FIB character count fields, eg
* <code>FIB.CCPText</code> after an insert or a delete...
*
* Works on all CCP fields from this range onwards
*
* @param adjustment
* The (signed) value that should be added to the FIB CCP fields
*/
protected void adjustFIB(int adjustment) {
assert (_doc instanceof HWPFDocument);
// update the FIB.CCPText field (this should happen once per adjustment,
// so we don't want it in
// adjustForInsert() or it would get updated multiple times if the range
// has a parent)
// without this, OpenOffice.org (v. 2.2.x) does not see all the text in
// the document
FileInformationBlock fib = _doc.getFileInformationBlock();
// // Do for each affected part
// if (_start < cpS.getMainDocumentEnd()) {
// fib.setCcpText(fib.getCcpText() + adjustment);
// }
//
// if (_start < cpS.getCommentsEnd()) {
// fib.setCcpAtn(fib.getCcpAtn() + adjustment);
// }
// if (_start < cpS.getEndNoteEnd()) {
// fib.setCcpEdn(fib.getCcpEdn() + adjustment);
// }
// if (_start < cpS.getFootnoteEnd()) {
// fib.setCcpFtn(fib.getCcpFtn() + adjustment);
// }
// if (_start < cpS.getHeaderStoryEnd()) {
// fib.setCcpHdd(fib.getCcpHdd() + adjustment);
// }
// if (_start < cpS.getHeaderTextboxEnd()) {
// fib.setCcpHdrTxtBx(fib.getCcpHdrTxtBx() + adjustment);
// }
// if (_start < cpS.getMainTextboxEnd()) {
// fib.setCcpTxtBx(fib.getCcpTxtBx() + adjustment);
// }
// much simple implementation base on SubdocumentType --sergey
int currentEnd = 0;
for (SubdocumentType type : SubdocumentType.ORDERED) {
int currentLength = fib.getSubdocumentTextStreamLength(type);
currentEnd += currentLength;
// do we need to shift this part?
if (_start > currentEnd)
continue;
fib.setSubdocumentTextStreamLength(type, currentLength + adjustment);
break;
}
}
Aggregations