View | Details | Raw Unified | Return to bug 51351
Collapse All | Expand All

(-)src/org/apache/poi/hwpf/extractor/AbstractToFoExtractor.java (-7 / +5 lines)
Lines 102-114 Link Here
102
        return simplePageMaster;
102
        return simplePageMaster;
103
    }
103
    }
104
104
105
    protected Element addTable( Element flow )
106
    {
107
        final Element table = document.createElementNS( NS_XSLFO, "fo:table" );
108
        flow.appendChild( table );
109
        return table;
110
    }
111
112
    protected Element createBasicLinkExternal( String externalDestination )
105
    protected Element createBasicLinkExternal( String externalDestination )
113
    {
106
    {
114
        final Element basicLink = document.createElementNS( NS_XSLFO,
107
        final Element basicLink = document.createElementNS( NS_XSLFO,
Lines 173-178 Link Here
173
        return result;
166
        return result;
174
    }
167
    }
175
168
169
    protected Element createTable()
170
    {
171
        return document.createElementNS( NS_XSLFO, "fo:table" );
172
    }
173
176
    protected Element createTableBody()
174
    protected Element createTableBody()
177
    {
175
    {
178
        return document.createElementNS( NS_XSLFO, "fo:table-body" );
176
        return document.createElementNS( NS_XSLFO, "fo:table-body" );
(-)src/org/apache/poi/hwpf/extractor/WordToFoExtractor.java (-8 / +23 lines)
Lines 560-573 Link Here
560
560
561
            if ( currentListInfo != 0 )
561
            if ( currentListInfo != 0 )
562
            {
562
            {
563
                final ListFormatOverride listFormatOverride = listTables
563
                if ( listTables != null )
564
                        .getOverride( paragraph.getIlfo() );
564
                {
565
                    final ListFormatOverride listFormatOverride = listTables
566
                            .getOverride( paragraph.getIlfo() );
565
567
566
                String label = WordToFoUtils.getBulletText( listTables,
568
                    String label = WordToFoUtils.getBulletText( listTables,
567
                        paragraph, listFormatOverride.getLsid() );
569
                            paragraph, listFormatOverride.getLsid() );
568
570
569
                processParagraph( hwpfDocument, flow, currentTableLevel,
571
                    processParagraph( hwpfDocument, flow, currentTableLevel,
570
                        paragraph, label );
572
                            paragraph, label );
573
                }
574
                else
575
                {
576
                    logger.log( POILogger.WARN,
577
                            "Paragraph #" + paragraph.getStartOffset() + "-"
578
                                    + paragraph.getEndOffset()
579
                                    + " has reference to list structure #"
580
                                    + currentListInfo
581
                                    + ", but listTables not defined in file" );
582
583
                    processParagraph( hwpfDocument, flow, currentTableLevel,
584
                            paragraph, WordToFoUtils.EMPTY );
585
                }
571
            }
586
            }
572
            else
587
            else
573
            {
588
            {
Lines 581-588 Link Here
581
    protected void processTable( HWPFDocument hwpfDocument, Element flow,
596
    protected void processTable( HWPFDocument hwpfDocument, Element flow,
582
            Table table, int thisTableLevel )
597
            Table table, int thisTableLevel )
583
    {
598
    {
584
        Element tableElement = addTable( flow );
585
586
        Element tableHeader = createTableHeader();
599
        Element tableHeader = createTableHeader();
587
        Element tableBody = createTableBody();
600
        Element tableBody = createTableBody();
588
601
Lines 681-686 Link Here
681
            }
694
            }
682
        }
695
        }
683
696
697
        final Element tableElement = createTable();
684
        if ( tableHeader.hasChildNodes() )
698
        if ( tableHeader.hasChildNodes() )
685
        {
699
        {
686
            tableElement.appendChild( tableHeader );
700
            tableElement.appendChild( tableHeader );
Lines 688-693 Link Here
688
        if ( tableBody.hasChildNodes() )
702
        if ( tableBody.hasChildNodes() )
689
        {
703
        {
690
            tableElement.appendChild( tableBody );
704
            tableElement.appendChild( tableBody );
705
            flow.appendChild( tableElement );
691
        }
706
        }
692
        else
707
        else
693
        {
708
        {
(-)testcases/org/apache/poi/hwpf/extractor/TestWordToFoExtractorSuite.java (+87 lines)
Line 0 Link Here
1
package org.apache.poi.hwpf.extractor;
2
3
import java.io.File;
4
import java.io.FileInputStream;
5
import java.io.FilenameFilter;
6
import java.io.StringWriter;
7
8
import javax.xml.parsers.DocumentBuilderFactory;
9
import javax.xml.transform.OutputKeys;
10
import javax.xml.transform.Transformer;
11
import javax.xml.transform.TransformerFactory;
12
import javax.xml.transform.dom.DOMSource;
13
import javax.xml.transform.stream.StreamResult;
14
15
import org.apache.poi.EncryptedDocumentException;
16
17
import org.apache.poi.hwpf.OldWordFileFormatException;
18
19
import junit.framework.Test;
20
import junit.framework.TestCase;
21
import junit.framework.TestSuite;
22
import org.apache.poi.POIDataSamples;
23
import org.apache.poi.hwpf.HWPFDocument;
24
25
public class TestWordToFoExtractorSuite
26
{
27
    public static Test suite()
28
    {
29
        TestSuite suite = new TestSuite();
30
31
        File directory = POIDataSamples.getDocumentInstance().getFile(
32
                "../document" );
33
        for ( final File child : directory.listFiles( new FilenameFilter()
34
        {
35
            public boolean accept( File dir, String name )
36
            {
37
                return name.endsWith( ".doc" );
38
            }
39
        } ) )
40
        {
41
            final String name = child.getName();
42
            suite.addTest( new TestCase( name )
43
            {
44
                public void runTest() throws Exception
45
                {
46
                    test( child );
47
                }
48
            } );
49
        }
50
51
        return suite;
52
    }
53
54
    protected static void test( File child ) throws Exception
55
    {
56
        HWPFDocument hwpfDocument;
57
        FileInputStream fileInputStream = new FileInputStream( child );
58
        try
59
        {
60
            hwpfDocument = new HWPFDocument( fileInputStream );
61
        }
62
        catch ( Exception exc )
63
        {
64
            // unable to parse file -- not WordToFoExtractor fault
65
            return;
66
        }
67
        finally
68
        {
69
            fileInputStream.close();
70
        }
71
72
        WordToFoExtractor wordToFoExtractor = new WordToFoExtractor(
73
                DocumentBuilderFactory.newInstance().newDocumentBuilder()
74
                        .newDocument() );
75
        wordToFoExtractor.processDocument( hwpfDocument );
76
77
        StringWriter stringWriter = new StringWriter();
78
79
        Transformer transformer = TransformerFactory.newInstance()
80
                .newTransformer();
81
        transformer.setOutputProperty( OutputKeys.INDENT, "yes" );
82
        transformer.transform(
83
                new DOMSource( wordToFoExtractor.getDocument() ),
84
                new StreamResult( stringWriter ) );
85
        // no exceptions
86
    }
87
}

Return to bug 51351