Search in sources :

Example 11 with NPOIFSFileSystem

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

the class TestPOIDocumentScratchpad method testWriteReadProperties.

@Test
public void testWriteReadProperties() throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    // Write them out
    NPOIFSFileSystem outFS = new NPOIFSFileSystem();
    doc.writeProperties(outFS);
    outFS.writeFilesystem(baos);
    // Create a new version
    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    POIFSFileSystem inFS = new POIFSFileSystem(bais);
    // Check they're still there
    POIDocument ppt = new HPSFPropertiesOnlyDocument(inFS);
    ppt.readProperties();
    // Delegate test
    testReadPropertiesHelper(ppt);
    ppt.close();
    inFS.close();
}
Also used : NPOIFSFileSystem(org.apache.poi.poifs.filesystem.NPOIFSFileSystem) ByteArrayInputStream(java.io.ByteArrayInputStream) POIFSFileSystem(org.apache.poi.poifs.filesystem.POIFSFileSystem) NPOIFSFileSystem(org.apache.poi.poifs.filesystem.NPOIFSFileSystem) HPSFPropertiesOnlyDocument(org.apache.poi.hpsf.HPSFPropertiesOnlyDocument) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 12 with NPOIFSFileSystem

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

the class TestPublisherTextExtractor method testContents.

@Test
public void testContents() throws IOException {
    // Check this complicated file using POIFS
    InputStream sample = _samples.openResourceAsStream("Sample.pub");
    HPBFDocument docOPOIFS = new HPBFDocument(sample);
    PublisherTextExtractor ext = new PublisherTextExtractor(docOPOIFS);
    assertEquals(SAMPLE_TEXT, ext.getText());
    ext.close();
    docOPOIFS.close();
    sample.close();
    // And with NPOIFS
    sample = _samples.openResourceAsStream("Sample.pub");
    NPOIFSFileSystem fs = new NPOIFSFileSystem(sample);
    HPBFDocument docNPOIFS = new HPBFDocument(fs);
    ext = new PublisherTextExtractor(docNPOIFS);
    assertEquals(SAMPLE_TEXT, ext.getText());
    ext.close();
    docNPOIFS.close();
    fs.close();
    sample.close();
    // Now a simpler file
    InputStream simple = _samples.openResourceAsStream("Simple.pub");
    ext = new PublisherTextExtractor(simple);
    assertEquals(SIMPLE_TEXT, ext.getText());
    ext.close();
}
Also used : NPOIFSFileSystem(org.apache.poi.poifs.filesystem.NPOIFSFileSystem) InputStream(java.io.InputStream) HPBFDocument(org.apache.poi.hpbf.HPBFDocument) Test(org.junit.Test)

Example 13 with NPOIFSFileSystem

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

the class TestPOIFSChunkParser method testFindsMultipleRecipients.

@Test
public void testFindsMultipleRecipients() throws IOException, ChunkNotFoundException {
    NPOIFSFileSystem multiple = new NPOIFSFileSystem(samples.getFile("example_received_unicode.msg"), true);
    multiple.getRoot().getEntry("__recip_version1.0_#00000000");
    multiple.getRoot().getEntry("__recip_version1.0_#00000001");
    multiple.getRoot().getEntry("__recip_version1.0_#00000002");
    multiple.getRoot().getEntry("__recip_version1.0_#00000003");
    multiple.getRoot().getEntry("__recip_version1.0_#00000004");
    multiple.getRoot().getEntry("__recip_version1.0_#00000005");
    ChunkGroup[] groups = POIFSChunkParser.parse(multiple.getRoot());
    assertEquals(9, groups.length);
    assertTrue(groups[0] instanceof Chunks);
    assertTrue(groups[1] instanceof RecipientChunks);
    assertTrue(groups[2] instanceof RecipientChunks);
    assertTrue(groups[3] instanceof RecipientChunks);
    assertTrue(groups[4] instanceof RecipientChunks);
    assertTrue(groups[5] instanceof AttachmentChunks);
    assertTrue(groups[6] instanceof RecipientChunks);
    assertTrue(groups[7] instanceof RecipientChunks);
    assertTrue(groups[8] instanceof NameIdChunks);
    // In FS order initially
    RecipientChunks[] chunks = new RecipientChunks[] { (RecipientChunks) groups[1], (RecipientChunks) groups[2], (RecipientChunks) groups[3], (RecipientChunks) groups[4], (RecipientChunks) groups[6], (RecipientChunks) groups[7] };
    assertEquals(6, chunks.length);
    assertEquals(0, chunks[0].recipientNumber);
    assertEquals(2, chunks[1].recipientNumber);
    assertEquals(4, chunks[2].recipientNumber);
    assertEquals(5, chunks[3].recipientNumber);
    assertEquals(3, chunks[4].recipientNumber);
    assertEquals(1, chunks[5].recipientNumber);
    // Check
    assertEquals("'Ashutosh Dandavate'", chunks[0].getRecipientName());
    assertEquals("ashutosh.dandavate@alfresco.com", chunks[0].getRecipientEmailAddress());
    assertEquals("'Mike Farman'", chunks[1].getRecipientName());
    assertEquals("mikef@alfresco.com", chunks[1].getRecipientEmailAddress());
    assertEquals("nick.burch@alfresco.com", chunks[2].getRecipientName());
    assertEquals("nick.burch@alfresco.com", chunks[2].getRecipientEmailAddress());
    assertEquals("'Roy Wetherall'", chunks[3].getRecipientName());
    assertEquals("roy.wetherall@alfresco.com", chunks[3].getRecipientEmailAddress());
    assertEquals("nickb@alfresco.com", chunks[4].getRecipientName());
    assertEquals("nickb@alfresco.com", chunks[4].getRecipientEmailAddress());
    assertEquals("'Paul Holmes-Higgin'", chunks[5].getRecipientName());
    assertEquals("paul.hh@alfresco.com", chunks[5].getRecipientEmailAddress());
    // Now sort, and re-check
    Arrays.sort(chunks, new RecipientChunksSorter());
    assertEquals("'Ashutosh Dandavate'", chunks[0].getRecipientName());
    assertEquals("ashutosh.dandavate@alfresco.com", chunks[0].getRecipientEmailAddress());
    assertEquals("'Paul Holmes-Higgin'", chunks[1].getRecipientName());
    assertEquals("paul.hh@alfresco.com", chunks[1].getRecipientEmailAddress());
    assertEquals("'Mike Farman'", chunks[2].getRecipientName());
    assertEquals("mikef@alfresco.com", chunks[2].getRecipientEmailAddress());
    assertEquals("nickb@alfresco.com", chunks[3].getRecipientName());
    assertEquals("nickb@alfresco.com", chunks[3].getRecipientEmailAddress());
    assertEquals("nick.burch@alfresco.com", chunks[4].getRecipientName());
    assertEquals("nick.burch@alfresco.com", chunks[4].getRecipientEmailAddress());
    assertEquals("'Roy Wetherall'", chunks[5].getRecipientName());
    assertEquals("roy.wetherall@alfresco.com", chunks[5].getRecipientEmailAddress());
    // Finally check on message
    MAPIMessage msg = new MAPIMessage(multiple);
    assertEquals(6, msg.getRecipientEmailAddressList().length);
    assertEquals(6, msg.getRecipientNamesList().length);
    assertEquals("'Ashutosh Dandavate'", msg.getRecipientNamesList()[0]);
    assertEquals("'Paul Holmes-Higgin'", msg.getRecipientNamesList()[1]);
    assertEquals("'Mike Farman'", msg.getRecipientNamesList()[2]);
    assertEquals("nickb@alfresco.com", msg.getRecipientNamesList()[3]);
    assertEquals("nick.burch@alfresco.com", msg.getRecipientNamesList()[4]);
    assertEquals("'Roy Wetherall'", msg.getRecipientNamesList()[5]);
    assertEquals("ashutosh.dandavate@alfresco.com", msg.getRecipientEmailAddressList()[0]);
    assertEquals("paul.hh@alfresco.com", msg.getRecipientEmailAddressList()[1]);
    assertEquals("mikef@alfresco.com", msg.getRecipientEmailAddressList()[2]);
    assertEquals("nickb@alfresco.com", msg.getRecipientEmailAddressList()[3]);
    assertEquals("nick.burch@alfresco.com", msg.getRecipientEmailAddressList()[4]);
    assertEquals("roy.wetherall@alfresco.com", msg.getRecipientEmailAddressList()[5]);
    msg.close();
    multiple.close();
}
Also used : MAPIMessage(org.apache.poi.hsmf.MAPIMessage) NPOIFSFileSystem(org.apache.poi.poifs.filesystem.NPOIFSFileSystem) ChunkGroup(org.apache.poi.hsmf.datatypes.ChunkGroup) Chunks(org.apache.poi.hsmf.datatypes.Chunks) RecipientChunks(org.apache.poi.hsmf.datatypes.RecipientChunks) NameIdChunks(org.apache.poi.hsmf.datatypes.NameIdChunks) AttachmentChunks(org.apache.poi.hsmf.datatypes.AttachmentChunks) RecipientChunks(org.apache.poi.hsmf.datatypes.RecipientChunks) NameIdChunks(org.apache.poi.hsmf.datatypes.NameIdChunks) RecipientChunksSorter(org.apache.poi.hsmf.datatypes.RecipientChunks.RecipientChunksSorter) AttachmentChunks(org.apache.poi.hsmf.datatypes.AttachmentChunks) Test(org.junit.Test)

Example 14 with NPOIFSFileSystem

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

the class TestPOIFSChunkParser method testOlk10SideProps.

/**
    * Bugzilla #51873 - Outlook 2002 files created with dragging and
    *  dropping files to the disk include a non-standard named streams
    *  such as "Olk10SideProps_0001"
    */
@Test
public void testOlk10SideProps() throws IOException, ChunkNotFoundException {
    NPOIFSFileSystem poifs = new NPOIFSFileSystem(samples.getFile("51873.msg"), true);
    MAPIMessage msg = new MAPIMessage(poifs);
    // Check core details came through
    assertEquals("bubba@bubbasmith.com", msg.getDisplayTo());
    assertEquals("Test with Olk10SideProps_ Chunk", msg.getSubject());
    msg.close();
    poifs.close();
}
Also used : MAPIMessage(org.apache.poi.hsmf.MAPIMessage) NPOIFSFileSystem(org.apache.poi.poifs.filesystem.NPOIFSFileSystem) Test(org.junit.Test)

Example 15 with NPOIFSFileSystem

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

the class TestPOIFSChunkParser method testFindsAttachments.

@Test
public void testFindsAttachments() throws IOException, ChunkNotFoundException {
    NPOIFSFileSystem with = new NPOIFSFileSystem(samples.getFile("attachment_test_msg.msg"), true);
    NPOIFSFileSystem without = new NPOIFSFileSystem(samples.getFile("quick.msg"), true);
    AttachmentChunks attachment;
    // Check raw details on the one with
    with.getRoot().getEntry("__attach_version1.0_#00000000");
    with.getRoot().getEntry("__attach_version1.0_#00000001");
    POIFSChunkParser.parse(with.getRoot());
    ChunkGroup[] groups = POIFSChunkParser.parse(with.getRoot());
    assertEquals(5, groups.length);
    assertTrue(groups[0] instanceof Chunks);
    assertTrue(groups[1] instanceof RecipientChunks);
    assertTrue(groups[2] instanceof AttachmentChunks);
    assertTrue(groups[3] instanceof AttachmentChunks);
    assertTrue(groups[4] instanceof NameIdChunks);
    attachment = (AttachmentChunks) groups[2];
    assertEquals("TEST-U~1.DOC", attachment.getAttachFileName().toString());
    assertEquals("test-unicode.doc", attachment.getAttachLongFileName().toString());
    assertEquals(24064, attachment.getAttachData().getValue().length);
    attachment = (AttachmentChunks) groups[3];
    assertEquals("pj1.txt", attachment.getAttachFileName().toString());
    assertEquals("pj1.txt", attachment.getAttachLongFileName().toString());
    assertEquals(89, attachment.getAttachData().getValue().length);
    // Check raw details on one without
    assertFalse(without.getRoot().hasEntry("__attach_version1.0_#00000000"));
    assertFalse(without.getRoot().hasEntry("__attach_version1.0_#00000001"));
    // One with, from the top
    MAPIMessage msgWith = new MAPIMessage(with);
    assertEquals(2, msgWith.getAttachmentFiles().length);
    attachment = msgWith.getAttachmentFiles()[0];
    assertEquals("TEST-U~1.DOC", attachment.getAttachFileName().toString());
    assertEquals("test-unicode.doc", attachment.getAttachLongFileName().toString());
    assertEquals(24064, attachment.getAttachData().getValue().length);
    attachment = msgWith.getAttachmentFiles()[1];
    assertEquals("pj1.txt", attachment.getAttachFileName().toString());
    assertEquals("pj1.txt", attachment.getAttachLongFileName().toString());
    assertEquals(89, attachment.getAttachData().getValue().length);
    // Plus check core details are there
    assertEquals("'nicolas1.23456@free.fr'", msgWith.getDisplayTo());
    assertEquals("Nicolas1 23456", msgWith.getDisplayFrom());
    assertEquals("test pièce jointe 1", msgWith.getSubject());
    // One without, from the top
    MAPIMessage msgWithout = new MAPIMessage(without);
    // No attachments
    assertEquals(0, msgWithout.getAttachmentFiles().length);
    // But has core details
    assertEquals("Kevin Roast", msgWithout.getDisplayTo());
    assertEquals("Kevin Roast", msgWithout.getDisplayFrom());
    assertEquals("Test the content transformer", msgWithout.getSubject());
    msgWithout.close();
    msgWith.close();
    without.close();
    with.close();
}
Also used : MAPIMessage(org.apache.poi.hsmf.MAPIMessage) NPOIFSFileSystem(org.apache.poi.poifs.filesystem.NPOIFSFileSystem) ChunkGroup(org.apache.poi.hsmf.datatypes.ChunkGroup) Chunks(org.apache.poi.hsmf.datatypes.Chunks) RecipientChunks(org.apache.poi.hsmf.datatypes.RecipientChunks) NameIdChunks(org.apache.poi.hsmf.datatypes.NameIdChunks) AttachmentChunks(org.apache.poi.hsmf.datatypes.AttachmentChunks) RecipientChunks(org.apache.poi.hsmf.datatypes.RecipientChunks) NameIdChunks(org.apache.poi.hsmf.datatypes.NameIdChunks) AttachmentChunks(org.apache.poi.hsmf.datatypes.AttachmentChunks) 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