use of org.apache.poi.poifs.filesystem.NPOIFSFileSystem in project poi by apache.
the class TestBugs method getMacrosFromHSLF.
//It isn't pretty, but it works...
private Map<String, String> getMacrosFromHSLF(String fileName) throws IOException {
InputStream is = null;
NPOIFSFileSystem npoifs = null;
try {
is = new FileInputStream(POIDataSamples.getSlideShowInstance().getFile(fileName));
npoifs = new NPOIFSFileSystem(is);
//TODO: should we run the VBAMacroReader on this npoifs?
//TBD: We know that ppt typically don't store macros in the regular place,
//but _can_ they?
HSLFSlideShow ppt = new HSLFSlideShow(npoifs);
//get macro persist id
DocInfoListContainer list = (DocInfoListContainer) ppt.getDocumentRecord().findFirstOfType(RecordTypes.List.typeID);
VBAInfoContainer vbaInfo = (VBAInfoContainer) list.findFirstOfType(RecordTypes.VBAInfo.typeID);
VBAInfoAtom vbaAtom = (VBAInfoAtom) vbaInfo.findFirstOfType(RecordTypes.VBAInfoAtom.typeID);
long persistId = vbaAtom.getPersistIdRef();
for (HSLFObjectData objData : ppt.getEmbeddedObjects()) {
if (objData.getExOleObjStg().getPersistId() == persistId) {
VBAMacroReader mr = new VBAMacroReader(objData.getData());
try {
return mr.readMacros();
} finally {
mr.close();
}
}
}
ppt.close();
} finally {
IOUtils.closeQuietly(npoifs);
IOUtils.closeQuietly(is);
}
return null;
}
use of org.apache.poi.poifs.filesystem.NPOIFSFileSystem in project poi by apache.
the class TestRichTextRun method assertMatchesFileC.
/**
* Checks that the supplied slideshow still matches the bytes
* of slideshow c
*/
private static void assertMatchesFileC(HSLFSlideShow s) throws IOException {
// Grab the bytes of the file
NPOIFSFileSystem fs = new NPOIFSFileSystem(HSLFTestDataSamples.openSampleFileStream(filenameC));
InputStream is = fs.createDocumentInputStream(HSLFSlideShow.POWERPOINT_DOCUMENT);
byte[] raw_file = IOUtils.toByteArray(is);
is.close();
fs.close();
// Now write out the slideshow
ByteArrayOutputStream baos = new ByteArrayOutputStream();
s.write(baos);
fs = new NPOIFSFileSystem(new ByteArrayInputStream(baos.toByteArray()));
is = fs.createDocumentInputStream(HSLFSlideShow.POWERPOINT_DOCUMENT);
byte[] raw_ss = IOUtils.toByteArray(is);
is.close();
fs.close();
// different paragraph mask, because of sanitizing
raw_ss[169030] = 0x0a;
// Ensure they're the same
assertArrayEquals(raw_file, raw_ss);
}
use of org.apache.poi.poifs.filesystem.NPOIFSFileSystem in project poi by apache.
the class TestOutlookTextExtractor method testEncodings.
public void testEncodings() throws Exception {
NPOIFSFileSystem poifs = new NPOIFSFileSystem(samples.getFile("chinese-traditional.msg"), true);
MAPIMessage msg = new MAPIMessage(poifs);
OutlookTextExtactor ext = new OutlookTextExtactor(msg);
String text = ext.getText();
// Check the english bits
assertContains(text, "From: Tests Chang@FT");
assertContains(text, "tests.chang@fengttt.com");
// And check some chinese bits
assertContains(text, "(張毓倫)");
assertContains(text, "( MSG 格式測試 )");
ext.close();
poifs.close();
}
use of org.apache.poi.poifs.filesystem.NPOIFSFileSystem in project poi by apache.
the class TestOutlookTextExtractor method testWithAttachedMessage.
public void testWithAttachedMessage() throws Exception {
NPOIFSFileSystem poifs = new NPOIFSFileSystem(samples.getFile("58214_with_attachment.msg"), true);
MAPIMessage msg = new MAPIMessage(poifs);
OutlookTextExtactor ext = new OutlookTextExtactor(msg);
String text = ext.getText();
// Check we got bits from the main message
assertContains(text, "Master mail");
assertContains(text, "ante in lacinia euismod");
// But not the attached message
assertNotContained(text, "Test mail attachment");
assertNotContained(text, "Lorem ipsum dolor sit");
ext.close();
poifs.close();
}
use of org.apache.poi.poifs.filesystem.NPOIFSFileSystem in project poi by apache.
the class TestOutlookTextExtractor method testQuick.
@Test
public void testQuick() throws Exception {
NPOIFSFileSystem poifs = new NPOIFSFileSystem(samples.getFile("quick.msg"), true);
MAPIMessage msg = new MAPIMessage(poifs);
OutlookTextExtactor ext = new OutlookTextExtactor(msg);
String text = ext.getText();
assertContains(text, "From: Kevin Roast\n");
assertContains(text, "To: Kevin Roast <kevin.roast@alfresco.org>\n");
assertNotContained(text, "CC:");
assertNotContained(text, "BCC:");
assertNotContained(text, "Attachment:");
assertContains(text, "Subject: Test the content transformer\n");
Calendar cal = LocaleUtil.getLocaleCalendar(2007, 5, 14, 9, 42, 55);
SimpleDateFormat f = new SimpleDateFormat("E, d MMM yyyy HH:mm:ss Z", Locale.ROOT);
f.setTimeZone(LocaleUtil.getUserTimeZone());
String dateText = f.format(cal.getTime());
assertContains(text, "Date: " + dateText + "\n");
assertContains(text, "The quick brown fox jumps over the lazy dog");
ext.close();
poifs.close();
}
Aggregations