Search in sources :

Example 1 with VBAInfoAtom

use of org.apache.poi.hslf.record.VBAInfoAtom 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;
}
Also used : VBAInfoContainer(org.apache.poi.hslf.record.VBAInfoContainer) NPOIFSFileSystem(org.apache.poi.poifs.filesystem.NPOIFSFileSystem) VBAInfoAtom(org.apache.poi.hslf.record.VBAInfoAtom) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) VBAMacroReader(org.apache.poi.poifs.macros.VBAMacroReader) DocInfoListContainer(org.apache.poi.hslf.record.DocInfoListContainer) FileInputStream(java.io.FileInputStream)

Aggregations

FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 DocInfoListContainer (org.apache.poi.hslf.record.DocInfoListContainer)1 VBAInfoAtom (org.apache.poi.hslf.record.VBAInfoAtom)1 VBAInfoContainer (org.apache.poi.hslf.record.VBAInfoContainer)1 NPOIFSFileSystem (org.apache.poi.poifs.filesystem.NPOIFSFileSystem)1 VBAMacroReader (org.apache.poi.poifs.macros.VBAMacroReader)1