poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ser...@apache.org
Subject svn commit: r1156682 - /poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/dev/HWPFLister.java
Date Thu, 11 Aug 2011 17:16:08 GMT
Author: sergey
Date: Thu Aug 11 17:16:07 2011
New Revision: 1156682

URL: http://svn.apache.org/viewvc?rev=1156682&view=rev
Log:
dump OLE2 streams

Modified:
    poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/dev/HWPFLister.java

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/dev/HWPFLister.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/dev/HWPFLister.java?rev=1156682&r1=1156681&r2=1156682&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/dev/HWPFLister.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/dev/HWPFLister.java Thu Aug 11 17:16:07
2011
@@ -26,10 +26,12 @@ import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
+import java.util.Iterator;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 
+import org.apache.poi.POIDocument;
 import org.apache.poi.hwpf.HWPFDocument;
 import org.apache.poi.hwpf.HWPFDocumentCore;
 import org.apache.poi.hwpf.HWPFOldDocument;
@@ -53,6 +55,9 @@ import org.apache.poi.hwpf.usermodel.Par
 import org.apache.poi.hwpf.usermodel.Picture;
 import org.apache.poi.hwpf.usermodel.Range;
 import org.apache.poi.poifs.common.POIFSConstants;
+import org.apache.poi.poifs.filesystem.DirectoryEntry;
+import org.apache.poi.poifs.filesystem.DirectoryNode;
+import org.apache.poi.poifs.filesystem.Entry;
 import org.apache.poi.poifs.filesystem.POIFSFileSystem;
 import org.apache.poi.util.Beta;
 import org.apache.poi.util.IOUtils;
@@ -199,6 +204,9 @@ public final class HWPFLister
         HWPFLister listerOriginal = new HWPFLister( original );
         HWPFLister listerRebuilded = new HWPFLister( doc );
 
+        System.out.println( "== OLE streams ==" );
+        listerOriginal.dumpFileSystem();
+        
         System.out.println( "== FIB (original) ==" );
         listerOriginal.dumpFIB();
 
@@ -404,6 +412,41 @@ public final class HWPFLister
         System.out.println( ( (HWPFDocument) _doc ).getEscherRecordHolder() );
     }
 
+    public void dumpFileSystem() throws Exception
+    {
+        java.lang.reflect.Field field = POIDocument.class
+                .getDeclaredField( "directory" );
+        field.setAccessible( true );
+        DirectoryNode directoryNode = (DirectoryNode) field.get( _doc );
+
+        System.out.println( dumpFileSystem( directoryNode ) );
+    }
+
+    private String dumpFileSystem( DirectoryEntry directory )
+    {
+        StringBuilder result = new StringBuilder();
+        result.append( "+ " );
+        result.append( directory.getName() );
+        for ( Iterator<Entry> iterator = directory.getEntries(); iterator
+                .hasNext(); )
+        {
+            Entry entry = iterator.next();
+            String entryToString = "\n" + dumpFileSystem( entry );
+            entryToString = entryToString.replaceAll( "\n", "\n+---" );
+            result.append( entryToString );
+        }
+        result.append( "\n" );
+        return result.toString();
+    }
+
+    private String dumpFileSystem( Entry entry )
+    {
+        if ( entry instanceof DirectoryEntry )
+            return dumpFileSystem( (DirectoryEntry) entry );
+
+        return entry.getName();
+    }
+
     public void dumpFIB()
     {
         FileInformationBlock fib = _doc.getFileInformationBlock();



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message