Search in sources :

Example 56 with HWPFDocument

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

the class TestRevisionMarkAuthorTable method testEmptyDocument.

/**
    * Tests that an empty file doesn't have one
    */
public void testEmptyDocument() {
    HWPFDocument doc = HWPFTestDataSamples.openSampleFile("empty.doc");
    RevisionMarkAuthorTable rmt = doc.getRevisionMarkAuthorTable();
    assertNull(rmt);
}
Also used : HWPFDocument(org.apache.poi.hwpf.HWPFDocument)

Example 57 with HWPFDocument

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

the class TestRevisionMarkAuthorTable method testSimpleDocument.

/**
    * Tests that we can load a document with
    *  only simple entries in the table
    */
public void testSimpleDocument() {
    HWPFDocument doc = HWPFTestDataSamples.openSampleFile("two_images.doc");
    RevisionMarkAuthorTable rmt = doc.getRevisionMarkAuthorTable();
    assertNotNull(rmt);
    assertEquals(1, rmt.getSize());
    assertEquals("Unknown", rmt.getAuthor(0));
    assertEquals(null, rmt.getAuthor(1));
    assertEquals(null, rmt.getAuthor(2));
    assertEquals(null, rmt.getAuthor(3));
}
Also used : HWPFDocument(org.apache.poi.hwpf.HWPFDocument)

Example 58 with HWPFDocument

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

the class TestRevisionMarkAuthorTable method testMultipleAuthors.

/**
	 * Several authors, one of whom has no name
	 */
public void testMultipleAuthors() {
    HWPFDocument doc = HWPFTestDataSamples.openSampleFile("MarkAuthorsTable.doc");
    RevisionMarkAuthorTable rmt = doc.getRevisionMarkAuthorTable();
    assertNotNull(rmt);
    assertEquals(4, rmt.getSize());
    assertEquals("Unknown", rmt.getAuthor(0));
    assertEquals("BSanders", rmt.getAuthor(1));
    assertEquals(" ", rmt.getAuthor(2));
    assertEquals("Ryan Lauck", rmt.getAuthor(3));
    assertEquals(null, rmt.getAuthor(4));
    assertEquals(null, rmt.getAuthor(5));
    assertEquals(null, rmt.getAuthor(6));
}
Also used : HWPFDocument(org.apache.poi.hwpf.HWPFDocument)

Example 59 with HWPFDocument

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

the class AbstractWordUtilsTest method testBuildTableCellEdgesArray.

/**
     * Test case for {@link AbstractWordUtils#buildTableCellEdgesArray(Table)}
     */
public void testBuildTableCellEdgesArray() {
    HWPFDocument document = HWPFTestDataSamples.openSampleFile("table-merges.doc");
    final Range range = document.getRange();
    Table table = range.getTable(range.getParagraph(0));
    int[] result = AbstractWordUtils.buildTableCellEdgesArray(table);
    assertEquals(6, result.length);
    assertEquals(0000, result[0]);
    assertEquals(1062, result[1]);
    assertEquals(5738, result[2]);
    assertEquals(6872, result[3]);
    assertEquals(8148, result[4]);
    assertEquals(9302, result[5]);
}
Also used : HWPFDocument(org.apache.poi.hwpf.HWPFDocument) Table(org.apache.poi.hwpf.usermodel.Table) Range(org.apache.poi.hwpf.usermodel.Range)

Example 60 with HWPFDocument

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

the class TestHWPFWrite method testWriteNewFile.

/**
     * Write to a new file
     */
@Test
public void testWriteNewFile() throws IOException {
    HWPFDocument doc = HWPFTestDataSamples.openSampleFile("SampleDoc.doc");
    Range r = doc.getRange();
    assertEquals("I am a test document\r", r.getParagraph(0).text());
    File file = TempFile.createTempFile("TestDocument", ".doc");
    doc.write(file);
    doc.close();
    // Check reading from File and Stream
    doc = new HWPFDocument(new FileInputStream(file));
    r = doc.getRange();
    assertEquals("I am a test document\r", r.getParagraph(0).text());
    doc.close();
    doc = new HWPFDocument(new POIFSFileSystem(file));
    r = doc.getRange();
    assertEquals("I am a test document\r", r.getParagraph(0).text());
    doc.close();
}
Also used : HWPFDocument(org.apache.poi.hwpf.HWPFDocument) OPOIFSFileSystem(org.apache.poi.poifs.filesystem.OPOIFSFileSystem) POIFSFileSystem(org.apache.poi.poifs.filesystem.POIFSFileSystem) NPOIFSFileSystem(org.apache.poi.poifs.filesystem.NPOIFSFileSystem) TempFile(org.apache.poi.util.TempFile) File(java.io.File) FileInputStream(java.io.FileInputStream) 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