poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ye...@apache.org
Subject svn commit: r1138836 - in /poi/trunk/src/scratchpad: src/org/apache/poi/hwpf/extractor/AbstractToFoExtractor.java src/org/apache/poi/hwpf/extractor/WordToFoExtractor.java testcases/org/apache/poi/hwpf/extractor/TestWordToFoExtractorSuite.java
Date Thu, 23 Jun 2011 11:28:31 GMT
Author: yegor
Date: Thu Jun 23 11:28:31 2011
New Revision: 1138836

URL: http://svn.apache.org/viewvc?rev=1138836&view=rev
Log:
Bug 51351 - more progress with WordToFoExtractor: fix ListEntryNoListTable and MBD001D0B89
tests

Added:
    poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/extractor/TestWordToFoExtractorSuite.java
Modified:
    poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/extractor/AbstractToFoExtractor.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/extractor/WordToFoExtractor.java

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/extractor/AbstractToFoExtractor.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/extractor/AbstractToFoExtractor.java?rev=1138836&r1=1138835&r2=1138836&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/extractor/AbstractToFoExtractor.java
(original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/extractor/AbstractToFoExtractor.java
Thu Jun 23 11:28:31 2011
@@ -102,13 +102,6 @@ public abstract class AbstractToFoExtrac
         return simplePageMaster;
     }
 
-    protected Element addTable( Element flow )
-    {
-        final Element table = document.createElementNS( NS_XSLFO, "fo:table" );
-        flow.appendChild( table );
-        return table;
-    }
-
     protected Element createBasicLinkExternal( String externalDestination )
     {
         final Element basicLink = document.createElementNS( NS_XSLFO,
@@ -173,6 +166,11 @@ public abstract class AbstractToFoExtrac
         return result;
     }
 
+    protected Element createTable()
+    {
+        return document.createElementNS( NS_XSLFO, "fo:table" );
+    }
+
     protected Element createTableBody()
     {
         return document.createElementNS( NS_XSLFO, "fo:table-body" );

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/extractor/WordToFoExtractor.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/extractor/WordToFoExtractor.java?rev=1138836&r1=1138835&r2=1138836&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/extractor/WordToFoExtractor.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/extractor/WordToFoExtractor.java Thu
Jun 23 11:28:31 2011
@@ -560,14 +560,29 @@ public class WordToFoExtractor extends A
 
             if ( currentListInfo != 0 )
             {
-                final ListFormatOverride listFormatOverride = listTables
-                        .getOverride( paragraph.getIlfo() );
+                if ( listTables != null )
+                {
+                    final ListFormatOverride listFormatOverride = listTables
+                            .getOverride( paragraph.getIlfo() );
 
-                String label = WordToFoUtils.getBulletText( listTables,
-                        paragraph, listFormatOverride.getLsid() );
+                    String label = WordToFoUtils.getBulletText( listTables,
+                            paragraph, listFormatOverride.getLsid() );
 
-                processParagraph( hwpfDocument, flow, currentTableLevel,
-                        paragraph, label );
+                    processParagraph( hwpfDocument, flow, currentTableLevel,
+                            paragraph, label );
+                }
+                else
+                {
+                    logger.log( POILogger.WARN,
+                            "Paragraph #" + paragraph.getStartOffset() + "-"
+                                    + paragraph.getEndOffset()
+                                    + " has reference to list structure #"
+                                    + currentListInfo
+                                    + ", but listTables not defined in file" );
+
+                    processParagraph( hwpfDocument, flow, currentTableLevel,
+                            paragraph, WordToFoUtils.EMPTY );
+                }
             }
             else
             {
@@ -581,8 +596,6 @@ public class WordToFoExtractor extends A
     protected void processTable( HWPFDocument hwpfDocument, Element flow,
             Table table, int thisTableLevel )
     {
-        Element tableElement = addTable( flow );
-
         Element tableHeader = createTableHeader();
         Element tableBody = createTableBody();
 
@@ -681,6 +694,7 @@ public class WordToFoExtractor extends A
             }
         }
 
+        final Element tableElement = createTable();
         if ( tableHeader.hasChildNodes() )
         {
             tableElement.appendChild( tableHeader );
@@ -688,6 +702,7 @@ public class WordToFoExtractor extends A
         if ( tableBody.hasChildNodes() )
         {
             tableElement.appendChild( tableBody );
+            flow.appendChild( tableElement );
         }
         else
         {

Added: poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/extractor/TestWordToFoExtractorSuite.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/extractor/TestWordToFoExtractorSuite.java?rev=1138836&view=auto
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/extractor/TestWordToFoExtractorSuite.java
(added)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/extractor/TestWordToFoExtractorSuite.java
Thu Jun 23 11:28:31 2011
@@ -0,0 +1,87 @@
+package org.apache.poi.hwpf.extractor;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FilenameFilter;
+import java.io.StringWriter;
+
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
+import org.apache.poi.EncryptedDocumentException;
+
+import org.apache.poi.hwpf.OldWordFileFormatException;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+import org.apache.poi.POIDataSamples;
+import org.apache.poi.hwpf.HWPFDocument;
+
+public class TestWordToFoExtractorSuite
+{
+    public static Test suite()
+    {
+        TestSuite suite = new TestSuite();
+
+        File directory = POIDataSamples.getDocumentInstance().getFile(
+                "../document" );
+        for ( final File child : directory.listFiles( new FilenameFilter()
+        {
+            public boolean accept( File dir, String name )
+            {
+                return name.endsWith( ".doc" );
+            }
+        } ) )
+        {
+            final String name = child.getName();
+            suite.addTest( new TestCase( name )
+            {
+                public void runTest() throws Exception
+                {
+                    test( child );
+                }
+            } );
+        }
+
+        return suite;
+    }
+
+    protected static void test( File child ) throws Exception
+    {
+        HWPFDocument hwpfDocument;
+        FileInputStream fileInputStream = new FileInputStream( child );
+        try
+        {
+            hwpfDocument = new HWPFDocument( fileInputStream );
+        }
+        catch ( Exception exc )
+        {
+            // unable to parse file -- not WordToFoExtractor fault
+            return;
+        }
+        finally
+        {
+            fileInputStream.close();
+        }
+
+        WordToFoExtractor wordToFoExtractor = new WordToFoExtractor(
+                DocumentBuilderFactory.newInstance().newDocumentBuilder()
+                        .newDocument() );
+        wordToFoExtractor.processDocument( hwpfDocument );
+
+        StringWriter stringWriter = new StringWriter();
+
+        Transformer transformer = TransformerFactory.newInstance()
+                .newTransformer();
+        transformer.setOutputProperty( OutputKeys.INDENT, "yes" );
+        transformer.transform(
+                new DOMSource( wordToFoExtractor.getDocument() ),
+                new StreamResult( stringWriter ) );
+        // no exceptions
+    }
+}



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


Mime
View raw message