poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ser...@apache.org
Subject svn commit: r1143734 - /poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/dev/HWPFLister.java
Date Thu, 07 Jul 2011 09:51:42 GMT
Author: sergey
Date: Thu Jul  7 09:51:42 2011
New Revision: 1143734

URL: http://svn.apache.org/viewvc?rev=1143734&view=rev
Log:
add ability to dump text pieces

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=1143734&r1=1143733&r2=1143734&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 Jul  7 09:51:42
2011
@@ -17,13 +17,17 @@
 
 package org.apache.poi.hwpf.dev;
 
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
 import java.io.FileInputStream;
+import java.io.IOException;
 import java.util.Arrays;
 
 import org.apache.poi.hwpf.HWPFDocument;
 import org.apache.poi.hwpf.HWPFDocumentCore;
 import org.apache.poi.hwpf.model.FileInformationBlock;
 import org.apache.poi.hwpf.model.PAPX;
+import org.apache.poi.hwpf.model.TextPiece;
 import org.apache.poi.hwpf.sprm.SprmIterator;
 import org.apache.poi.hwpf.sprm.SprmOperation;
 import org.apache.poi.hwpf.usermodel.Paragraph;
@@ -43,12 +47,18 @@ public final class HWPFLister
         if ( args.length == 0 )
         {
             System.err.println( "Use:" );
-            System.err.println( "   HWPFLister <filename> "
-                    + "[--papx] [--papxProperties] "
-                    + "[--paragraphs] [--paragraphsSprms] [--paragraphsText]" );
+            System.err
+                    .println( "\tHWPFLister <filename>\n"
+                            + "\t\t[--textPieces] [--textPiecesText]\n"
+                            + "\t\t[--papx] [--papxProperties]\n"
+                            + "\t\t[--paragraphs] [--paragraphsSprms] [--paragraphsText]\n"
+                            + "\t\t[--writereadback]\n" );
             System.exit( 1 );
         }
 
+        boolean outputTextPieces = false;
+        boolean outputTextPiecesText = false;
+
         boolean outputParagraphs = false;
         boolean outputParagraphsSprms = false;
         boolean outputParagraphsText = false;
@@ -56,8 +66,15 @@ public final class HWPFLister
         boolean outputPapx = false;
         boolean outputPapxProperties = false;
 
+        boolean writereadback = false;
+
         for ( String arg : Arrays.asList( args ).subList( 1, args.length ) )
         {
+            if ( "--textPieces".equals( arg ) )
+                outputTextPieces = true;
+            if ( "--textPiecesText".equals( arg ) )
+                outputTextPiecesText = true;
+
             if ( "--paragraphs".equals( arg ) )
                 outputParagraphs = true;
             if ( "--paragraphsSprms".equals( arg ) )
@@ -69,12 +86,24 @@ public final class HWPFLister
                 outputPapx = true;
             if ( "--papxProperties".equals( arg ) )
                 outputPapxProperties = true;
+
+            if ( "--writereadback".equals( arg ) )
+                writereadback = true;
         }
 
-        HWPFLister lister = new HWPFLister( new HWPFDocument(
-                new FileInputStream( args[0] ) ) );
+        HWPFDocument doc = new HWPFDocument( new FileInputStream( args[0] ) );
+        if ( writereadback )
+            doc = writeOutAndReadBack( doc );
+
+        HWPFLister lister = new HWPFLister( doc );
         lister.dumpFIB();
 
+        if ( outputTextPieces )
+        {
+            System.out.println( "== Text pieces ==" );
+            lister.dumpTextPieces( outputTextPiecesText );
+        }
+
         if ( outputParagraphs )
         {
             System.out.println( "== Paragraphs ==" );
@@ -89,6 +118,22 @@ public final class HWPFLister
         }
     }
 
+    private static HWPFDocument writeOutAndReadBack( HWPFDocument original )
+    {
+        try
+        {
+            ByteArrayOutputStream baos = new ByteArrayOutputStream( 4096 );
+            original.write( baos );
+            ByteArrayInputStream bais = new ByteArrayInputStream(
+                    baos.toByteArray() );
+            return new HWPFDocument( bais );
+        }
+        catch ( IOException e )
+        {
+            throw new RuntimeException( e );
+        }
+    }
+
     private final HWPFDocumentCore _doc;
 
     public HWPFLister( HWPFDocumentCore doc )
@@ -139,4 +184,17 @@ public final class HWPFLister
                 System.out.println( paragraph.text() );
         }
     }
+
+    public void dumpTextPieces( boolean withText )
+    {
+        for ( TextPiece textPiece : _doc.getTextTable().getTextPieces() )
+        {
+            System.out.println( textPiece );
+
+            if ( withText )
+            {
+                System.out.println( "\t" + textPiece.getStringBuffer() );
+            }
+        }
+    }
 }



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


Mime
View raw message