use of org.apache.poi.hwpf.model.FileInformationBlock in project poi by apache.
the class HWPFLister method dumpFIB.
public void dumpFIB() {
FileInformationBlock fib = _doc.getFileInformationBlock();
System.out.println(fib);
}
use of org.apache.poi.hwpf.model.FileInformationBlock 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.FileInformationBlock in project poi by apache.
the class HWPFDocFixture method setUp.
public void setUp() throws IOException {
POIFSFileSystem filesystem = new POIFSFileSystem(POIDataSamples.getDocumentInstance().openResourceAsStream(_testFile));
DocumentEntry documentProps = (DocumentEntry) filesystem.getRoot().getEntry("WordDocument");
_mainStream = new byte[documentProps.getSize()];
filesystem.createDocumentInputStream("WordDocument").read(_mainStream);
// use the fib to determine the name of the table stream.
_fib = new FileInformationBlock(_mainStream);
String name = "0Table";
if (_fib.getFibBase().isFWhichTblStm()) {
name = "1Table";
}
// read in the table stream.
DocumentEntry tableProps = (DocumentEntry) filesystem.getRoot().getEntry(name);
_tableStream = new byte[tableProps.getSize()];
filesystem.createDocumentInputStream(name).read(_tableStream);
_fib.fillVariableFields(_mainStream, _tableStream);
}
use of org.apache.poi.hwpf.model.FileInformationBlock in project poi by apache.
the class TestFieldsTables method testReadFields.
@Test
public void testReadFields() {
FileInformationBlock fib = _hWPFDocFixture._fib;
byte[] tableStream = _hWPFDocFixture._tableStream;
FieldsTables fieldsTables = new FieldsTables(tableStream, fib);
int i = 0;
for (FieldsDocumentPart part : FieldsDocumentPart.values()) {
String result = dumpPlexes(fieldsTables.getFieldsPLCF(part));
assertEquals(EXPECTED[i++], result);
}
}
use of org.apache.poi.hwpf.model.FileInformationBlock 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