org.apache.poi.poifs.macros
Class VBAMacroReader

java.lang.Object
  extended by org.apache.poi.poifs.macros.VBAMacroReader
All Implemented Interfaces:
java.io.Closeable

public class VBAMacroReader
extends java.lang.Object
implements java.io.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
protected static class VBAMacroReader.Module
           
protected static class VBAMacroReader.ModuleMap
           
 
Field Summary
protected static java.lang.String VBA_PROJECT_OOXML
           
protected static java.lang.String VBA_PROJECT_POIFS
           
 
Constructor Summary
VBAMacroReader(java.io.File file)
           
VBAMacroReader(java.io.InputStream rstream)
           
VBAMacroReader(NPOIFSFileSystem fs)
           
 
Method Summary
 void close()
           
protected  void findMacros(DirectoryNode dir, VBAMacroReader.ModuleMap modules)
          Recursively traverses directory structure rooted at dir.
 java.util.Map<java.lang.String,java.lang.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 at macroDir into modules.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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(NPOIFSFileSystem fs)
Method Detail

close

public void close()
           throws java.io.IOException
Specified by:
close in interface java.io.Closeable
Throws:
java.io.IOException

readMacros

public java.util.Map<java.lang.String,java.lang.String> readMacros()
                                                            throws java.io.IOException
Reads 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 at
modules - 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