Search in sources :

Example 1 with FileInformationBlock

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);
}
Also used : FileInformationBlock(org.apache.poi.hwpf.model.FileInformationBlock)

Example 2 with FileInformationBlock

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);
}
Also used : HWPFDocument(org.apache.poi.hwpf.HWPFDocument) FileInformationBlock(org.apache.poi.hwpf.model.FileInformationBlock) SubdocumentType(org.apache.poi.hwpf.model.SubdocumentType) Test(org.junit.Test)

Example 3 with FileInformationBlock

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);
}
Also used : POIFSFileSystem(org.apache.poi.poifs.filesystem.POIFSFileSystem) FileInformationBlock(org.apache.poi.hwpf.model.FileInformationBlock) DocumentEntry(org.apache.poi.poifs.filesystem.DocumentEntry)

Example 4 with FileInformationBlock

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);
    }
}
Also used : FieldsDocumentPart(org.apache.poi.hwpf.model.FieldsDocumentPart) FileInformationBlock(org.apache.poi.hwpf.model.FileInformationBlock) FieldsTables(org.apache.poi.hwpf.model.FieldsTables) Test(org.junit.Test)

Example 5 with FileInformationBlock

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;
    }
}
Also used : HWPFDocument(org.apache.poi.hwpf.HWPFDocument) FileInformationBlock(org.apache.poi.hwpf.model.FileInformationBlock) SubdocumentType(org.apache.poi.hwpf.model.SubdocumentType)

Aggregations

FileInformationBlock (org.apache.poi.hwpf.model.FileInformationBlock)5 HWPFDocument (org.apache.poi.hwpf.HWPFDocument)2 SubdocumentType (org.apache.poi.hwpf.model.SubdocumentType)2 Test (org.junit.Test)2 FieldsDocumentPart (org.apache.poi.hwpf.model.FieldsDocumentPart)1 FieldsTables (org.apache.poi.hwpf.model.FieldsTables)1 DocumentEntry (org.apache.poi.poifs.filesystem.DocumentEntry)1 POIFSFileSystem (org.apache.poi.poifs.filesystem.POIFSFileSystem)1