poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ser...@apache.org
Subject svn commit: r1142872 - in /poi/trunk/src/scratchpad: src/org/apache/poi/hwpf/converter/ testcases/org/apache/poi/hwpf/converter/
Date Tue, 05 Jul 2011 01:44:30 GMT
Author: sergey
Date: Tue Jul  5 01:44:29 2011
New Revision: 1142872

URL: http://svn.apache.org/viewvc?rev=1142872&view=rev
Log:
simplify table converting; fix bug that prevents table from AIOOB-Tap.doc to be converted

Modified:
    poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/converter/AbstractWordConverter.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToFoConverter.java
    poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToHtmlConverter.java
    poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/converter/TestWordToHtmlConverter.java

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/converter/AbstractWordConverter.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/converter/AbstractWordConverter.java?rev=1142872&r1=1142871&r2=1142872&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/converter/AbstractWordConverter.java
(original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/converter/AbstractWordConverter.java
Tue Jul  5 01:44:29 2011
@@ -16,9 +16,7 @@
 ==================================================================== */
 package org.apache.poi.hwpf.converter;
 
-import java.util.HashMap;
 import java.util.List;
-import java.util.Map;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
@@ -32,7 +30,6 @@ import org.apache.poi.hwpf.usermodel.Pic
 import org.apache.poi.hwpf.usermodel.Range;
 import org.apache.poi.hwpf.usermodel.Section;
 import org.apache.poi.hwpf.usermodel.Table;
-import org.apache.poi.hwpf.usermodel.TableIterator;
 import org.apache.poi.util.POILogFactory;
 import org.apache.poi.util.POILogger;
 import org.w3c.dom.Document;
@@ -233,14 +230,6 @@ public abstract class AbstractWordConver
     protected void processSectionParagraphes( HWPFDocumentCore wordDocument,
             Element flow, Range range, int currentTableLevel )
     {
-        final Map<Integer, Table> allTables = new HashMap<Integer, Table>();
-        for ( TableIterator tableIterator = AbstractWordUtils.newTableIterator(
-                range, currentTableLevel + 1 ); tableIterator.hasNext(); )
-        {
-            Table next = tableIterator.next();
-            allTables.put( Integer.valueOf( next.getStartOffset() ), next );
-        }
-
         final ListTables listTables = wordDocument.getListTables();
         int currentListInfo = 0;
 
@@ -249,18 +238,14 @@ public abstract class AbstractWordConver
         {
             Paragraph paragraph = range.getParagraph( p );
 
-            if ( allTables.containsKey( Integer.valueOf( paragraph
-                    .getStartOffset() ) ) )
-            {
-                Table table = allTables.get( Integer.valueOf( paragraph
-                        .getStartOffset() ) );
-                processTable( wordDocument, flow, table, currentTableLevel + 1 );
-                continue;
-            }
-
             if ( paragraph.isInTable()
                     && paragraph.getTableLevel() != currentTableLevel )
             {
+                Table table = range.getTable( paragraph );
+                processTable( wordDocument, flow, table );
+
+                p += table.numParagraphs();
+                p--;
                 continue;
             }
 
@@ -311,7 +296,7 @@ public abstract class AbstractWordConver
     }
 
     protected abstract void processTable( HWPFDocumentCore wordDocument,
-            Element flow, Table table, int newTableLevel );
+            Element flow, Table table );
 
     protected int tryField( HWPFDocumentCore wordDocument, Paragraph paragraph,
             int currentTableLevel, List<CharacterRun> characterRuns,

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToFoConverter.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToFoConverter.java?rev=1142872&r1=1142871&r2=1142872&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToFoConverter.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToFoConverter.java Tue
Jul  5 01:44:29 2011
@@ -18,9 +18,7 @@ package org.apache.poi.hwpf.converter;
 
 import java.io.File;
 import java.io.FileWriter;
-import java.util.HashMap;
 import java.util.List;
-import java.util.Map;
 import java.util.Stack;
 
 import javax.xml.parsers.DocumentBuilderFactory;
@@ -32,17 +30,13 @@ import javax.xml.transform.stream.Stream
 
 import org.apache.poi.hwpf.HWPFDocument;
 import org.apache.poi.hwpf.HWPFDocumentCore;
-import org.apache.poi.hwpf.model.ListFormatOverride;
-import org.apache.poi.hwpf.model.ListTables;
 import org.apache.poi.hwpf.usermodel.CharacterRun;
 import org.apache.poi.hwpf.usermodel.Paragraph;
 import org.apache.poi.hwpf.usermodel.Picture;
-import org.apache.poi.hwpf.usermodel.Range;
 import org.apache.poi.hwpf.usermodel.Section;
 import org.apache.poi.hwpf.usermodel.SectionProperties;
 import org.apache.poi.hwpf.usermodel.Table;
 import org.apache.poi.hwpf.usermodel.TableCell;
-import org.apache.poi.hwpf.usermodel.TableIterator;
 import org.apache.poi.hwpf.usermodel.TableRow;
 import org.apache.poi.util.POILogFactory;
 import org.apache.poi.util.POILogger;
@@ -374,85 +368,11 @@ public class WordToFoConverter extends A
         Element flow = foDocumentFacade.addFlowToPageSequence( pageSequence,
                 "xsl-region-body" );
 
-        processSectionParagraphes( wordDocument, flow, section, 0 );
-    }
-
-    protected void processSectionParagraphes( HWPFDocument wordDocument,
-            Element flow, Range range, int currentTableLevel )
-    {
-        final Map<Integer, Table> allTables = new HashMap<Integer, Table>();
-        for ( TableIterator tableIterator = WordToFoUtils.newTableIterator(
-                range, currentTableLevel + 1 ); tableIterator.hasNext(); )
-        {
-            Table next = tableIterator.next();
-            allTables.put( Integer.valueOf( next.getStartOffset() ), next );
-        }
-
-        final ListTables listTables = wordDocument.getListTables();
-        int currentListInfo = 0;
-
-        final int paragraphs = range.numParagraphs();
-        for ( int p = 0; p < paragraphs; p++ )
-        {
-            Paragraph paragraph = range.getParagraph( p );
-
-            if ( allTables.containsKey( Integer.valueOf( paragraph
-                    .getStartOffset() ) ) )
-            {
-                Table table = allTables.get( Integer.valueOf( paragraph
-                        .getStartOffset() ) );
-                processTable( wordDocument, flow, table, currentTableLevel + 1 );
-                continue;
-            }
-
-            if ( paragraph.isInTable()
-                    && paragraph.getTableLevel() != currentTableLevel )
-            {
-                continue;
-            }
-
-            if ( paragraph.getIlfo() != currentListInfo )
-            {
-                currentListInfo = paragraph.getIlfo();
-            }
-
-            if ( currentListInfo != 0 )
-            {
-                if ( listTables != null )
-                {
-                    final ListFormatOverride listFormatOverride = listTables
-                            .getOverride( paragraph.getIlfo() );
-
-                    String label = WordToFoUtils.getBulletText( listTables,
-                            paragraph, listFormatOverride.getLsid() );
-
-                    processParagraph( wordDocument, 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( wordDocument, flow, currentTableLevel,
-                            paragraph, WordToFoUtils.EMPTY );
-                }
-            }
-            else
-            {
-                processParagraph( wordDocument, flow, currentTableLevel,
-                        paragraph, WordToFoUtils.EMPTY );
-            }
-        }
-
+        processSectionParagraphes( wordDocument, flow, section, Integer.MIN_VALUE );
     }
 
     protected void processTable( HWPFDocumentCore wordDocument, Element flow,
-            Table table, int thisTableLevel )
+            Table table )
     {
         Element tableHeader = foDocumentFacade.createTableHeader();
         Element tableBody = foDocumentFacade.createTableBody();
@@ -532,7 +452,7 @@ public class WordToFoConverter extends A
                 }
 
                 processSectionParagraphes( wordDocument, tableCellElement,
-                        tableCell, thisTableLevel );
+                        tableCell, table.getTableLevel() );
 
                 if ( !tableCellElement.hasChildNodes() )
                 {

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToHtmlConverter.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToHtmlConverter.java?rev=1142872&r1=1142871&r2=1142872&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToHtmlConverter.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/converter/WordToHtmlConverter.java Tue
Jul  5 01:44:29 2011
@@ -326,7 +326,7 @@ public class WordToHtmlConverter extends
         div.setAttribute( "style", getSectionStyle( section ) );
         htmlDocumentFacade.body.appendChild( div );
 
-        processSectionParagraphes( wordDocument, div, section, 0 );
+        processSectionParagraphes( wordDocument, div, section, Integer.MIN_VALUE );
     }
 
     @Override
@@ -337,11 +337,11 @@ public class WordToHtmlConverter extends
                 getSectionStyle( section ) );
 
         processSectionParagraphes( wordDocument, htmlDocumentFacade.body,
-                section, 0 );
+                section, Integer.MIN_VALUE );
     }
 
     protected void processTable( HWPFDocumentCore hwpfDocument, Element flow,
-            Table table, int thisTableLevel )
+            Table table )
     {
         Element tableHeader = htmlDocumentFacade.createTableHeader();
         Element tableBody = htmlDocumentFacade.createTableBody();
@@ -429,7 +429,7 @@ public class WordToHtmlConverter extends
                 }
 
                 processSectionParagraphes( hwpfDocument, tableCellElement,
-                        tableCell, thisTableLevel );
+                        tableCell, table.getTableLevel() );
 
                 if ( !tableCellElement.hasChildNodes() )
                 {

Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/converter/TestWordToHtmlConverter.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/converter/TestWordToHtmlConverter.java?rev=1142872&r1=1142871&r2=1142872&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/converter/TestWordToHtmlConverter.java
(original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/converter/TestWordToHtmlConverter.java
Tue Jul  5 01:44:29 2011
@@ -77,6 +77,13 @@ public class TestWordToHtmlConverter ext
                 .contains( "<!--Image link to '0.emf' can be here-->" ) );
     }
 
+    public void testAIOOBTap() throws Exception
+    {
+        String result = getHtmlText( "AIOOB-Tap.doc" );
+
+        assertTrue( result.substring( 0, 2000 ).contains( "<table>" ) );
+    }
+
     public void testHyperlink() throws Exception
     {
         String result = getHtmlText( "hyperlink.doc" );



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


Mime
View raw message