Search in sources :

Example 71 with NPOIFSFileSystem

use of org.apache.poi.poifs.filesystem.NPOIFSFileSystem in project poi by apache.

the class TestOutlookTextExtractor method testSentWithMulipleRecipients.

/**
    * Test that we correctly handle multiple To+CC+BCC
    *  recipients in an email we sent.
    */
@Test
public void testSentWithMulipleRecipients() throws Exception {
    // To: 'Ashutosh Dandavate' <ashutosh.dandavate@alfresco.com>,
    //   'Paul Holmes-Higgin' <paul.hh@alfresco.com>,
    //   'Mike Farman' <mikef@alfresco.com>
    // Cc: nickb@alfresco.com, nick.burch@alfresco.com,
    //   'Roy Wetherall' <roy.wetherall@alfresco.com>
    // Bcc: 'David Caruana' <dave.caruana@alfresco.com>,
    //   'Vonka Jan' <roy.wetherall@alfresco.com>
    String[] files = new String[] { "example_sent_regular.msg", "example_sent_unicode.msg" };
    for (String file : files) {
        NPOIFSFileSystem poifs = new NPOIFSFileSystem(samples.getFile(file), true);
        MAPIMessage msg = new MAPIMessage(poifs);
        OutlookTextExtactor ext = new OutlookTextExtactor(msg);
        String text = ext.getText();
        assertContains(text, "From: Mike Farman\n");
        assertContains(text, "To: 'Ashutosh Dandavate' <ashutosh.dandavate@alfresco.com>; " + "'Paul Holmes-Higgin' <paul.hh@alfresco.com>; 'Mike Farman' <mikef@alfresco.com>\n");
        assertContains(text, "CC: 'nickb@alfresco.com' <nickb@alfresco.com>; " + "'nick.burch@alfresco.com' <nick.burch@alfresco.com>; 'Roy Wetherall' <roy.wetherall@alfresco.com>\n");
        assertContains(text, "BCC: 'David Caruana' <dave.caruana@alfresco.com>; " + "'Vonka Jan' <jan.vonka@alfresco.com>\n");
        assertContains(text, "Subject: This is a test message please ignore\n");
        assertContains(text, "Date:");
        assertContains(text, "The quick brown fox jumps over the lazy dog");
        ext.close();
        poifs.close();
    }
}
Also used : MAPIMessage(org.apache.poi.hsmf.MAPIMessage) NPOIFSFileSystem(org.apache.poi.poifs.filesystem.NPOIFSFileSystem) Test(org.junit.Test)

Example 72 with NPOIFSFileSystem

use of org.apache.poi.poifs.filesystem.NPOIFSFileSystem in project poi by apache.

the class TestOutlookTextExtractor method testWithAttachments.

/**
    * See also {@link org.apache.poi.extractor.TestExtractorFactory#testEmbeded()}
    */
public void testWithAttachments() throws Exception {
    NPOIFSFileSystem poifs = new NPOIFSFileSystem(samples.getFile("attachment_test_msg.msg"), true);
    MAPIMessage msg = new MAPIMessage(poifs);
    OutlookTextExtactor ext = new OutlookTextExtactor(msg);
    // Check the normal bits
    String text = ext.getText();
    assertContains(text, "From: Nicolas1");
    assertContains(text, "To: 'nicolas1.23456@free.fr'");
    assertNotContained(text, "CC:");
    assertNotContained(text, "BCC:");
    assertContains(text, "Subject: test");
    assertContains(text, "Date: Wed, 22 Apr");
    assertContains(text, "Attachment: test-unicode.doc\n");
    assertContains(text, "Attachment: pj1.txt\n");
    assertContains(text, "contenu");
    // Embeded bits are checked in
    //  TestExtractorFactory
    ext.close();
    poifs.close();
}
Also used : MAPIMessage(org.apache.poi.hsmf.MAPIMessage) NPOIFSFileSystem(org.apache.poi.poifs.filesystem.NPOIFSFileSystem)

Example 73 with NPOIFSFileSystem

use of org.apache.poi.poifs.filesystem.NPOIFSFileSystem in project poi by apache.

the class TestHSSFWorkbook method testWriteToNewFile.

@Test
public void testWriteToNewFile() throws Exception {
    // Open from a Stream
    HSSFWorkbook wb = new HSSFWorkbook(POIDataSamples.getSpreadSheetInstance().openResourceAsStream("SampleSS.xls"));
    // Save to a new temp file
    final File file = TempFile.createTempFile("TestHSSFWorkbook", ".xls");
    wb.write(file);
    wb.close();
    // Read and check
    wb = new HSSFWorkbook(new NPOIFSFileSystem(file));
    assertEquals(3, wb.getNumberOfSheets());
    wb.close();
}
Also used : NPOIFSFileSystem(org.apache.poi.poifs.filesystem.NPOIFSFileSystem) TempFile(org.apache.poi.util.TempFile) File(java.io.File) Test(org.junit.Test)

Example 74 with NPOIFSFileSystem

use of org.apache.poi.poifs.filesystem.NPOIFSFileSystem in project poi by apache.

the class TestHSSFWorkbook method wordDocEmbeddedInXls.

@Test
public void wordDocEmbeddedInXls() throws IOException {
    // Open the two filesystems
    DirectoryNode[] files = new DirectoryNode[2];
    POIFSFileSystem poifsFileSystem = new POIFSFileSystem(HSSFTestDataSamples.openSampleFileStream("WithEmbeddedObjects.xls"));
    try {
        files[0] = poifsFileSystem.getRoot();
        NPOIFSFileSystem npoifsFileSystem = new NPOIFSFileSystem(HSSFTestDataSamples.getSampleFile("WithEmbeddedObjects.xls"));
        try {
            files[1] = npoifsFileSystem.getRoot();
            // Check the embedded parts
            for (DirectoryNode root : files) {
                HSSFWorkbook hw = new HSSFWorkbook(root, true);
                List<HSSFObjectData> objects = hw.getAllEmbeddedObjects();
                boolean found = false;
                for (HSSFObjectData embeddedObject : objects) {
                    if (embeddedObject.hasDirectoryEntry()) {
                        DirectoryEntry dir = embeddedObject.getDirectory();
                        if (dir instanceof DirectoryNode) {
                            DirectoryNode dNode = (DirectoryNode) dir;
                            if (hasEntry(dNode, "WordDocument")) {
                                found = true;
                            }
                        }
                    }
                }
                assertTrue(found);
                hw.close();
            }
        } finally {
            npoifsFileSystem.close();
        }
    } finally {
        poifsFileSystem.close();
    }
}
Also used : NPOIFSFileSystem(org.apache.poi.poifs.filesystem.NPOIFSFileSystem) OPOIFSFileSystem(org.apache.poi.poifs.filesystem.OPOIFSFileSystem) POIFSFileSystem(org.apache.poi.poifs.filesystem.POIFSFileSystem) NPOIFSFileSystem(org.apache.poi.poifs.filesystem.NPOIFSFileSystem) DirectoryNode(org.apache.poi.poifs.filesystem.DirectoryNode) DirectoryEntry(org.apache.poi.poifs.filesystem.DirectoryEntry) Test(org.junit.Test)

Example 75 with NPOIFSFileSystem

use of org.apache.poi.poifs.filesystem.NPOIFSFileSystem in project poi by apache.

the class TestHSSFWorkbook method differentPOIFS.

/**
     * Tests that we can work with both {@link POIFSFileSystem}
     *  and {@link NPOIFSFileSystem}
     */
@Test
public void differentPOIFS() throws Exception {
    // Open the two filesystems
    DirectoryNode[] files = new DirectoryNode[2];
    POIFSFileSystem poifsFileSystem = new POIFSFileSystem(HSSFTestDataSamples.openSampleFileStream("Simple.xls"));
    try {
        files[0] = poifsFileSystem.getRoot();
        NPOIFSFileSystem npoifsFileSystem = new NPOIFSFileSystem(HSSFTestDataSamples.getSampleFile("Simple.xls"));
        try {
            files[1] = npoifsFileSystem.getRoot();
            // Open without preserving nodes 
            for (DirectoryNode dir : files) {
                HSSFWorkbook workbook = new HSSFWorkbook(dir, false);
                HSSFSheet sheet = workbook.getSheetAt(0);
                HSSFCell cell = sheet.getRow(0).getCell(0);
                assertEquals("replaceMe", cell.getRichStringCellValue().getString());
                workbook.close();
            }
            // Now re-check with preserving
            for (DirectoryNode dir : files) {
                HSSFWorkbook workbook = new HSSFWorkbook(dir, true);
                HSSFSheet sheet = workbook.getSheetAt(0);
                HSSFCell cell = sheet.getRow(0).getCell(0);
                assertEquals("replaceMe", cell.getRichStringCellValue().getString());
                workbook.close();
            }
        } finally {
            npoifsFileSystem.close();
        }
    } finally {
        poifsFileSystem.close();
    }
}
Also used : NPOIFSFileSystem(org.apache.poi.poifs.filesystem.NPOIFSFileSystem) OPOIFSFileSystem(org.apache.poi.poifs.filesystem.OPOIFSFileSystem) POIFSFileSystem(org.apache.poi.poifs.filesystem.POIFSFileSystem) NPOIFSFileSystem(org.apache.poi.poifs.filesystem.NPOIFSFileSystem) DirectoryNode(org.apache.poi.poifs.filesystem.DirectoryNode) Test(org.junit.Test)

Aggregations

NPOIFSFileSystem (org.apache.poi.poifs.filesystem.NPOIFSFileSystem)101 Test (org.junit.Test)57 File (java.io.File)35 InputStream (java.io.InputStream)26 ByteArrayInputStream (java.io.ByteArrayInputStream)19 ByteArrayOutputStream (java.io.ByteArrayOutputStream)14 MAPIMessage (org.apache.poi.hsmf.MAPIMessage)14 FileOutputStream (java.io.FileOutputStream)12 TempFile (org.apache.poi.util.TempFile)12 FileInputStream (java.io.FileInputStream)11 OPOIFSFileSystem (org.apache.poi.poifs.filesystem.OPOIFSFileSystem)10 POIFSFileSystem (org.apache.poi.poifs.filesystem.POIFSFileSystem)10 DocumentSummaryInformation (org.apache.poi.hpsf.DocumentSummaryInformation)9 DirectoryNode (org.apache.poi.poifs.filesystem.DirectoryNode)9 IOException (java.io.IOException)8 OutputStream (java.io.OutputStream)8 SummaryInformation (org.apache.poi.hpsf.SummaryInformation)7 TikaInputStream (org.apache.tika.io.TikaInputStream)6 AgileDecryptor (org.apache.poi.poifs.crypt.agile.AgileDecryptor)5 DirectoryEntry (org.apache.poi.poifs.filesystem.DirectoryEntry)5