use of org.apache.poi.hwpf.HWPFDocument in project poi by apache.
the class TestWordExtractor method testExtractFromEmbeded.
/**
* Test that we can get data from two different embedded word documents
*/
@Test
public void testExtractFromEmbeded() throws IOException {
InputStream is = POIDataSamples.getSpreadSheetInstance().openResourceAsStream("excel_with_embeded.xls");
POIFSFileSystem fs = new POIFSFileSystem(is);
is.close();
DirectoryNode dirA = (DirectoryNode) fs.getRoot().getEntry("MBD0000A3B7");
DirectoryNode dirB = (DirectoryNode) fs.getRoot().getEntry("MBD0000A3B2");
// Should have WordDocument and 1Table
assertNotNull(dirA.getEntry("1Table"));
assertNotNull(dirA.getEntry("WordDocument"));
assertNotNull(dirB.getEntry("1Table"));
assertNotNull(dirB.getEntry("WordDocument"));
// Check each in turn
HWPFDocument docA = new HWPFDocument(dirA);
WordExtractor extractorA = new WordExtractor(docA);
assertNotNull(extractorA.getText());
assertTrue(extractorA.getText().length() > 20);
assertEqualsTrim("I am a sample document\r\nNot much on me\r\nI am document 1\r\n", extractorA.getText());
assertEquals("Sample Doc 1", extractorA.getSummaryInformation().getTitle());
assertEquals("Sample Test", extractorA.getSummaryInformation().getSubject());
HWPFDocument docB = new HWPFDocument(dirB);
WordExtractor extractorB = new WordExtractor(docB);
assertNotNull(extractorB.getText());
assertTrue(extractorB.getText().length() > 20);
assertEqualsTrim("I am another sample document\r\nNot much on me\r\nI am document 2\r\n", extractorB.getText());
assertEquals("Sample Doc 2", extractorB.getSummaryInformation().getTitle());
assertEquals("Another Sample Test", extractorB.getSummaryInformation().getSubject());
extractorA.close();
docA.close();
extractorB.close();
docB.close();
fs.close();
}
use of org.apache.poi.hwpf.HWPFDocument in project poi by apache.
the class TestWordExtractor method testFootnote.
@Test
public void testFootnote() throws IOException {
HWPFDocument doc = HWPFTestDataSamples.openSampleFile("footnote.doc");
WordExtractor extractor = new WordExtractor(doc);
assertExtractedContains(extractor.getFootnoteText(), "TestFootnote");
// msonfcArabic
assertEquals(0x00, doc.getRange().getSection(0).getFootnoteNumberingFormat());
// rncCont
assertEquals(0x00, doc.getRange().getSection(0).getFootnoteRestartQualifier());
assertEquals(0, doc.getRange().getSection(0).getFootnoteNumberingOffset());
assertEquals(1, doc.getFootnotes().getNotesCount());
extractor.close();
doc.close();
}
use of org.apache.poi.hwpf.HWPFDocument in project poi by apache.
the class TestLists method testIndentedText.
public void testIndentedText() {
HWPFDocument doc = HWPFTestDataSamples.openSampleFile("Lists.doc");
Range r = doc.getRange();
assertEquals(40, r.numParagraphs());
assertEquals("Finally we want some indents, to tell the difference\r", r.getParagraph(34).text());
assertEquals("Indented once\r", r.getParagraph(35).text());
assertEquals("Indented twice\r", r.getParagraph(36).text());
assertEquals("Indented three times\r", r.getParagraph(37).text());
assertEquals("The end!\r", r.getParagraph(38).text());
assertEquals(9, r.getParagraph(34).getLvl());
assertEquals(9, r.getParagraph(35).getLvl());
assertEquals(9, r.getParagraph(36).getLvl());
assertEquals(9, r.getParagraph(37).getLvl());
assertEquals(9, r.getParagraph(38).getLvl());
assertEquals(9, r.getParagraph(39).getLvl());
assertEquals(0, r.getParagraph(34).getIlvl());
assertEquals(0, r.getParagraph(35).getIlvl());
assertEquals(0, r.getParagraph(36).getIlvl());
assertEquals(0, r.getParagraph(37).getIlvl());
assertEquals(0, r.getParagraph(38).getIlvl());
assertEquals(0, r.getParagraph(39).getIlvl());
// TODO Test the indent
}
use of org.apache.poi.hwpf.HWPFDocument in project poi by apache.
the class TestBugs method test51671.
/**
* [RESOLVED FIXED] Bug 51671 - HWPFDocument.write based on NPOIFSFileSystem
* throws a NullPointerException
*/
@Test
public void test51671() throws Exception {
InputStream is = POIDataSamples.getDocumentInstance().openResourceAsStream("empty.doc");
NPOIFSFileSystem npoifsFileSystem = new NPOIFSFileSystem(is);
try {
HWPFDocument hwpfDocument = new HWPFDocument(npoifsFileSystem.getRoot());
hwpfDocument.write(new ByteArrayOutputStream());
hwpfDocument.close();
} finally {
npoifsFileSystem.close();
}
}
use of org.apache.poi.hwpf.HWPFDocument in project poi by apache.
the class TestLists method testBasics.
public void testBasics() {
HWPFDocument doc = HWPFTestDataSamples.openSampleFile("Lists.doc");
Range r = doc.getRange();
assertEquals(40, r.numParagraphs());
assertEquals("Heading Level 1\r", r.getParagraph(0).text());
assertEquals("This document has different lists in it for testing\r", r.getParagraph(1).text());
assertEquals("The end!\r", r.getParagraph(38).text());
assertEquals("\r", r.getParagraph(39).text());
assertEquals(0, r.getParagraph(0).getLvl());
assertEquals(9, r.getParagraph(1).getLvl());
assertEquals(9, r.getParagraph(38).getLvl());
assertEquals(9, r.getParagraph(39).getLvl());
}
Aggregations