Search in sources :

Example 16 with HWPFDocument

use of org.apache.poi.hwpf.HWPFDocument in project poi by apache.

the class TestPictures method testEquation.

@Test
public void testEquation() {
    HWPFDocument doc = HWPFTestDataSamples.openSampleFile("equation.doc");
    PicturesTable pictures = doc.getPicturesTable();
    final List<Picture> allPictures = pictures.getAllPictures();
    assertEquals(1, allPictures.size());
    Picture picture = allPictures.get(0);
    assertNotNull(picture);
    assertEquals(PictureType.EMF, picture.suggestPictureType());
    assertEquals(PictureType.EMF.getExtension(), picture.suggestFileExtension());
    assertEquals(PictureType.EMF.getMime(), picture.getMimeType());
    assertEquals("0.emf", picture.suggestFullFileName());
}
Also used : HWPFDocument(org.apache.poi.hwpf.HWPFDocument) PicturesTable(org.apache.poi.hwpf.model.PicturesTable) Test(org.junit.Test)

Example 17 with HWPFDocument

use of org.apache.poi.hwpf.HWPFDocument in project poi by apache.

the class TestBugs method test56880.

/**
     * java.lang.UnsupportedOperationException: Non-extended character 
     *  Pascal strings are not supported right now
     * 
     * Disabled pending a fix for the bug
     */
@Test
public void test56880() throws Exception {
    HWPFDocument doc = HWPFTestDataSamples.openSampleFile("56880.doc");
    assertEqualsIgnoreNewline("Check Request", doc.getRange().text());
}
Also used : HWPFDocument(org.apache.poi.hwpf.HWPFDocument) Test(org.junit.Test)

Example 18 with HWPFDocument

use of org.apache.poi.hwpf.HWPFDocument in project poi by apache.

the class TestBugs method getText.

private String getText(String samplefile) throws IOException {
    HWPFDocument doc = HWPFTestDataSamples.openSampleFile(samplefile);
    WordExtractor extractor = new WordExtractor(doc);
    try {
        return extractor.getText();
    } finally {
        extractor.close();
        doc.close();
    }
}
Also used : HWPFDocument(org.apache.poi.hwpf.HWPFDocument) WordExtractor(org.apache.poi.hwpf.extractor.WordExtractor)

Example 19 with HWPFDocument

use of org.apache.poi.hwpf.HWPFDocument in project poi by apache.

the class TestBugs method test44431.

/**
     * Bug 44331 - HWPFDocument.write destroys fields
     */
@SuppressWarnings("deprecation")
@Test
public void test44431() throws IOException {
    HWPFDocument doc1 = HWPFTestDataSamples.openSampleFile("Bug44431.doc");
    WordExtractor extractor1 = new WordExtractor(doc1);
    try {
        HWPFDocument doc2 = HWPFTestDataSamples.writeOutAndReadBack(doc1);
        WordExtractor extractor2 = new WordExtractor(doc2);
        try {
            assertEqualsIgnoreNewline(extractor1.getFooterText(), extractor2.getFooterText());
            assertEqualsIgnoreNewline(extractor1.getHeaderText(), extractor2.getHeaderText());
            assertEqualsIgnoreNewline(Arrays.toString(extractor1.getParagraphText()), Arrays.toString(extractor2.getParagraphText()));
            assertEqualsIgnoreNewline(extractor1.getText(), extractor2.getText());
        } finally {
            extractor2.close();
        }
    } finally {
        extractor1.close();
        doc1.close();
    }
}
Also used : HWPFDocument(org.apache.poi.hwpf.HWPFDocument) WordExtractor(org.apache.poi.hwpf.extractor.WordExtractor) Test(org.junit.Test)

Example 20 with HWPFDocument

use of org.apache.poi.hwpf.HWPFDocument in project poi by apache.

the class TestProblems method testSprmAIOOB.

/**
     * AIOOB for TableSprmUncompressor.unCompressTAPOperation
     */
@Test
public void testSprmAIOOB() throws IOException {
    HWPFDocument doc = HWPFTestDataSamples.openSampleFile("AIOOB-Tap.doc");
    StyleSheet styleSheet = doc.getStyleSheet();
    assertNotNull(styleSheet);
    Range r = doc.getRange();
    for (int x = 0; x < r.numSections(); x++) {
        Section s = r.getSection(x);
        for (int y = 0; y < s.numParagraphs(); y++) {
            Paragraph paragraph = s.getParagraph(y);
            assertNotNull(paragraph);
        }
    }
    doc.close();
}
Also used : HWPFDocument(org.apache.poi.hwpf.HWPFDocument) StyleSheet(org.apache.poi.hwpf.model.StyleSheet) Test(org.junit.Test)

Aggregations

HWPFDocument (org.apache.poi.hwpf.HWPFDocument)126 Test (org.junit.Test)66 InputStream (java.io.InputStream)15 FileInputStream (java.io.FileInputStream)10 Range (org.apache.poi.hwpf.usermodel.Range)9 ByteArrayInputStream (java.io.ByteArrayInputStream)8 HSLFSlideShow (org.apache.poi.hslf.usermodel.HSLFSlideShow)7 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)7 WordExtractor (org.apache.poi.hwpf.extractor.WordExtractor)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 PicturesTable (org.apache.poi.hwpf.model.PicturesTable)6 Bookmark (org.apache.poi.hwpf.usermodel.Bookmark)6 NPOIFSFileSystem (org.apache.poi.poifs.filesystem.NPOIFSFileSystem)6 File (java.io.File)4 FileOutputStream (java.io.FileOutputStream)4 Transformer (javax.xml.transform.Transformer)4 DOMSource (javax.xml.transform.dom.DOMSource)4 Picture (org.apache.poi.hwpf.usermodel.Picture)4 DirectoryNode (org.apache.poi.poifs.filesystem.DirectoryNode)4 POIFSFileSystem (org.apache.poi.poifs.filesystem.POIFSFileSystem)4