Package org.apache.poi.poifs.macros
Class VBAMacroReader
- java.lang.Object
-
- org.apache.poi.poifs.macros.VBAMacroReader
-
- All Implemented Interfaces:
Closeable
,AutoCloseable
public class VBAMacroReader extends Object implements Closeable
Finds all VBA Macros in an office file (OLE2/POIFS and OOXML/OPC), and returns them.
NOTE: This does not read macros from .ppt files. See org.apache.poi.hslf.usermodel.TestBugs.getMacrosFromHSLF() in the scratchpad module for an example of how to do this. Patches that make macro extraction from .ppt more elegant are welcomed!
- Since:
- 3.15-beta2
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
VBAMacroReader.ModuleImpl
protected static class
VBAMacroReader.ModuleMap
-
Field Summary
Fields Modifier and Type Field Description protected static String
VBA_PROJECT_OOXML
protected static String
VBA_PROJECT_POIFS
-
Constructor Summary
Constructors Constructor Description VBAMacroReader(File file)
VBAMacroReader(InputStream rstream)
VBAMacroReader(POIFSFileSystem fs)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
protected void
findMacros(DirectoryNode dir, VBAMacroReader.ModuleMap modules)
Recursively traverses directory structure rooted atdir
.protected void
findModuleNameMap(DirectoryNode node, Map<String,String> moduleNameMap, VBAMacroReader.ModuleMap modules)
protected void
findProjectProperties(DirectoryNode node, Map<String,String> moduleNameMap, VBAMacroReader.ModuleMap modules)
Map<String,Module>
readMacroModules()
Map<String,String>
readMacros()
Reads all macros from all modules of the opened office file.protected void
readMacros(DirectoryNode macroDir, VBAMacroReader.ModuleMap modules)
Reads VBA Project modules from a VBA Project directory located atmacroDir
intomodules
.protected void
readNameMapRecords(InputStream is, Map<String,String> moduleNames, Charset charset)
protected void
readProjectProperties(DocumentInputStream dis, Map<String,String> moduleNameMap, VBAMacroReader.ModuleMap modules)
-
-
-
Field Detail
-
VBA_PROJECT_OOXML
protected static final String VBA_PROJECT_OOXML
- See Also:
- Constant Field Values
-
VBA_PROJECT_POIFS
protected static final String VBA_PROJECT_POIFS
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
VBAMacroReader
public VBAMacroReader(InputStream rstream) throws IOException
- Throws:
IOException
-
VBAMacroReader
public VBAMacroReader(File file) throws IOException
- Throws:
IOException
-
VBAMacroReader
public VBAMacroReader(POIFSFileSystem fs)
-
-
Method Detail
-
close
public void close() throws IOException
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-
readMacroModules
public Map<String,Module> readMacroModules() throws IOException
- Throws:
IOException
-
readMacros
public Map<String,String> readMacros() throws IOException
Reads all macros from all modules of the opened office file.- Returns:
- All the macros and their contents
- Throws:
IOException
- Since:
- 3.15-beta2
-
findMacros
protected void findMacros(DirectoryNode dir, VBAMacroReader.ModuleMap modules) throws IOException
Recursively traverses directory structure rooted atdir
. For each macro module that is found, the module's name and code are added tomodules
.- Parameters:
dir
- The directory of entries to look atmodules
- The resulting map of modules- Throws:
IOException
- If reading the VBA module fails- Since:
- 3.15-beta2
-
readMacros
protected void readMacros(DirectoryNode macroDir, VBAMacroReader.ModuleMap modules) throws IOException
Reads VBA Project modules from a VBA Project directory located atmacroDir
intomodules
.- Throws:
IOException
- Since:
- 3.15-beta2
-
findProjectProperties
protected void findProjectProperties(DirectoryNode node, Map<String,String> moduleNameMap, VBAMacroReader.ModuleMap modules) throws IOException
- Throws:
IOException
-
findModuleNameMap
protected void findModuleNameMap(DirectoryNode node, Map<String,String> moduleNameMap, VBAMacroReader.ModuleMap modules) throws IOException
- Throws:
IOException
-
readNameMapRecords
protected void readNameMapRecords(InputStream is, Map<String,String> moduleNames, Charset charset) throws IOException
- Throws:
IOException
-
readProjectProperties
protected void readProjectProperties(DocumentInputStream dis, Map<String,String> moduleNameMap, VBAMacroReader.ModuleMap modules) throws IOException
- Throws:
IOException
-
-