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
This commit is contained in:
parent
d45f22ad8d
commit
aac4cf50a9
@ -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" );
|
||||
|
@ -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
|
||||
{
|
||||
|
@ -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
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user