Package org.apache.poi.poifs.macros
Class VBAMacroReader
- java.lang.Object
-
- org.apache.poi.poifs.macros.VBAMacroReader
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
public class VBAMacroReader extends java.lang.Object implements java.io.CloseableFinds 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 classVBAMacroReader.ModuleImplprotected static classVBAMacroReader.ModuleMap
-
Field Summary
Fields Modifier and Type Field Description protected static java.lang.StringVBA_PROJECT_OOXMLprotected static java.lang.StringVBA_PROJECT_POIFS
-
Constructor Summary
Constructors Constructor Description VBAMacroReader(java.io.File file)VBAMacroReader(java.io.InputStream rstream)VBAMacroReader(POIFSFileSystem fs)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()protected voidfindMacros(DirectoryNode dir, VBAMacroReader.ModuleMap modules)Recursively traverses directory structure rooted at dir.protected voidfindModuleNameMap(DirectoryNode node, java.util.Map<java.lang.String,java.lang.String> moduleNameMap, VBAMacroReader.ModuleMap modules)protected voidfindProjectProperties(DirectoryNode node, java.util.Map<java.lang.String,java.lang.String> moduleNameMap, VBAMacroReader.ModuleMap modules)java.util.Map<java.lang.String,Module>readMacroModules()java.util.Map<java.lang.String,java.lang.String>readMacros()Reads all macros from all modules of the opened office file.protected voidreadMacros(DirectoryNode macroDir, VBAMacroReader.ModuleMap modules)Reads VBA Project modules from a VBA Project directory located at macroDir into modules.protected voidreadNameMapRecords(java.io.InputStream is, java.util.Map<java.lang.String,java.lang.String> moduleNames, java.nio.charset.Charset charset)protected voidreadProjectProperties(DocumentInputStream dis, java.util.Map<java.lang.String,java.lang.String> moduleNameMap, VBAMacroReader.ModuleMap modules)
-
-
-
Field Detail
-
VBA_PROJECT_OOXML
protected static final java.lang.String VBA_PROJECT_OOXML
- See Also:
- Constant Field Values
-
VBA_PROJECT_POIFS
protected static final java.lang.String VBA_PROJECT_POIFS
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
VBAMacroReader
public VBAMacroReader(java.io.InputStream rstream) throws java.io.IOException- Throws:
java.io.IOException
-
VBAMacroReader
public VBAMacroReader(java.io.File file) throws java.io.IOException- Throws:
java.io.IOException
-
VBAMacroReader
public VBAMacroReader(POIFSFileSystem fs)
-
-
Method Detail
-
close
public void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Throws:
java.io.IOException
-
readMacroModules
public java.util.Map<java.lang.String,Module> readMacroModules() throws java.io.IOException
- Throws:
java.io.IOException
-
readMacros
public java.util.Map<java.lang.String,java.lang.String> readMacros() throws java.io.IOExceptionReads all macros from all modules of the opened office file.- Returns:
- All the macros and their contents
- Throws:
java.io.IOException- Since:
- 3.15-beta2
-
findMacros
protected void findMacros(DirectoryNode dir, VBAMacroReader.ModuleMap modules) throws java.io.IOException
Recursively traverses directory structure rooted at dir. For each macro module that is found, the module's name and code are added to modules.- Parameters:
dir- The directory of entries to look atmodules- The resulting map of modules- Throws:
java.io.IOException- If reading the VBA module fails- Since:
- 3.15-beta2
-
readMacros
protected void readMacros(DirectoryNode macroDir, VBAMacroReader.ModuleMap modules) throws java.io.IOException
Reads VBA Project modules from a VBA Project directory located at macroDir into modules.- Throws:
java.io.IOException- Since:
- 3.15-beta2
-
findProjectProperties
protected void findProjectProperties(DirectoryNode node, java.util.Map<java.lang.String,java.lang.String> moduleNameMap, VBAMacroReader.ModuleMap modules) throws java.io.IOException
- Throws:
java.io.IOException
-
findModuleNameMap
protected void findModuleNameMap(DirectoryNode node, java.util.Map<java.lang.String,java.lang.String> moduleNameMap, VBAMacroReader.ModuleMap modules) throws java.io.IOException
- Throws:
java.io.IOException
-
readNameMapRecords
protected void readNameMapRecords(java.io.InputStream is, java.util.Map<java.lang.String,java.lang.String> moduleNames, java.nio.charset.Charset charset) throws java.io.IOException- Throws:
java.io.IOException
-
readProjectProperties
protected void readProjectProperties(DocumentInputStream dis, java.util.Map<java.lang.String,java.lang.String> moduleNameMap, VBAMacroReader.ModuleMap modules) throws java.io.IOException
- Throws:
java.io.IOException
-
-