aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYegor Kozlov <yegor@apache.org>2011-06-23 11:28:31 +0000
committerYegor Kozlov <yegor@apache.org>2011-06-23 11:28:31 +0000
commit54d885c7e4f2d015195d59433d9237cd874b8273 (patch)
treedac9ba9c809c4dc3fd3de28dd463095f5fbd81de
parentf0cc57338e79b12980b2972a478172c4d6aabd21 (diff)
downloadpoi-54d885c7e4f2d015195d59433d9237cd874b8273.tar.gz
poi-54d885c7e4f2d015195d59433d9237cd874b8273.zip
Bug 51351 - more progress with WordToFoExtractor: fix ListEntryNoListTable and MBD001D0B89 tests
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1138836 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--src/scratchpad/src/org/apache/poi/hwpf/extractor/AbstractToFoExtractor.java12
-rw-r--r--src/scratchpad/src/org/apache/poi/hwpf/extractor/WordToFoExtractor.java31
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hwpf/extractor/TestWordToFoExtractorSuite.java87
3 files changed, 115 insertions, 15 deletions
diff --git a/src/scratchpad/src/org/apache/poi/hwpf/extractor/AbstractToFoExtractor.java b/src/scratchpad/src/org/apache/poi/hwpf/extractor/AbstractToFoExtractor.java
index 4ac0eead72..19608d80a5 100644
--- a/src/scratchpad/src/org/apache/poi/hwpf/extractor/AbstractToFoExtractor.java
+++ b/src/scratchpad/src/org/apache/poi/hwpf/extractor/AbstractToFoExtractor.java
@@ -102,13 +102,6 @@ public abstract class AbstractToFoExtractor
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 AbstractToFoExtractor
return result;
}
+ protected Element createTable()
+ {
+ return document.createElementNS( NS_XSLFO, "fo:table" );
+ }
+
protected Element createTableBody()
{
return document.createElementNS( NS_XSLFO, "fo:table-body" );
diff --git a/src/scratchpad/src/org/apache/poi/hwpf/extractor/WordToFoExtractor.java b/src/scratchpad/src/org/apache/poi/hwpf/extractor/WordToFoExtractor.java
index b9022c916e..4189d7c32d 100644
--- a/src/scratchpad/src/org/apache/poi/hwpf/extractor/WordToFoExtractor.java
+++ b/src/scratchpad/src/org/apache/poi/hwpf/extractor/WordToFoExtractor.java
@@ -560,14 +560,29 @@ public class WordToFoExtractor extends AbstractToFoExtractor
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 AbstractToFoExtractor
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 AbstractToFoExtractor
}
}
+ final Element tableElement = createTable();
if ( tableHeader.hasChildNodes() )
{
tableElement.appendChild( tableHeader );
@@ -688,6 +702,7 @@ public class WordToFoExtractor extends AbstractToFoExtractor
if ( tableBody.hasChildNodes() )
{
tableElement.appendChild( tableBody );
+ flow.appendChild( tableElement );
}
else
{
diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/extractor/TestWordToFoExtractorSuite.java b/src/scratchpad/testcases/org/apache/poi/hwpf/extractor/TestWordToFoExtractorSuite.java
new file mode 100644
index 0000000000..2239d554bb
--- /dev/null
+++ b/src/scratchpad/testcases/org/apache/poi/hwpf/extractor/TestWordToFoExtractorSuite.java
@@ -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
+ }
+}