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();
}
}
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();
}
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();
}
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();
}
}
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();
}
}
Aggregations