use of org.apache.poi.hslf.record.VBAInfoContainer 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;
}
Aggregations