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

(-)src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java (-20 / +19 lines)
Lines 21-46 Link Here
21
21
22
import org.apache.xmlbeans.XmlCursor;
22
import org.apache.xmlbeans.XmlCursor;
23
import org.apache.xmlbeans.XmlObject;
23
import org.apache.xmlbeans.XmlObject;
24
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBorder;
24
import org.openxmlformats.schemas.wordprocessingml.x2006.main.*;
25
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTInd;
26
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTJc;
27
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTOnOff;
28
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP;
29
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPBdr;
30
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPPr;
31
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPTab;
32
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPicture;
33
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTR;
34
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSdtContentRun;
35
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSdtRun;
36
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSpacing;
37
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTText;
38
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTextAlignment;
39
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STBorder;
40
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STJc;
41
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STLineSpacingRule;
42
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STOnOff;
43
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STTextAlignment;
44
import org.w3c.dom.NodeList;
25
import org.w3c.dom.NodeList;
45
import org.w3c.dom.Text;
26
import org.w3c.dom.Text;
46
27
Lines 107-112 Link Here
107
		    if (o instanceof CTPTab) {
88
		    if (o instanceof CTPTab) {
108
			text.append("\t");
89
			text.append("\t");
109
		    }
90
		    }
91
                    if (o instanceof CTFtnEdnRef) {
92
                        CTFtnEdnRef ftn = (CTFtnEdnRef) o;
93
                        text.append("[").append(ftn.getId()).append(": ");
94
                        XWPFFootnote footnote = document.getFootnoteByID(ftn.getId());
95
96
                        boolean first = true;
97
98
                        for (XWPFParagraph p : footnote.getParagraphs()) {
99
                            if (!first) {
100
                                text.append("\n");
101
                                first = false;
102
                            }
103
104
                            text.append(p.getText());
105
                        }
106
107
                        text.append("]");
108
                    }
110
		}
109
		}
111
110
112
		// Loop over pictures inside our
111
		// Loop over pictures inside our
(-)src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRelation.java (+6 lines)
Lines 88-93 Link Here
88
            null,
88
            null,
89
            null
89
            null
90
    );
90
    );
91
    public static final XWPFRelation FOOTNOTE = new XWPFRelation(
92
            null,
93
            "http://schemas.openxmlformats.org/officeDocument/2006/relationships/footnotes",
94
            null,
95
            null
96
    );
91
97
92
98
93
    private XWPFRelation(String type, String rel, String defaultName, Class<? extends POIXMLDocumentPart> cls) {
99
    private XWPFRelation(String type, String rel, String defaultName, Class<? extends POIXMLDocumentPart> cls) {
(-)src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java (-10 / +24 lines)
Lines 19-24 Link Here
19
import java.io.IOException;
19
import java.io.IOException;
20
import java.io.OutputStream;
20
import java.io.OutputStream;
21
import java.util.*;
21
import java.util.*;
22
import java.math.BigInteger;
22
23
23
import org.apache.poi.POIXMLDocument;
24
import org.apache.poi.POIXMLDocument;
24
import org.apache.poi.POIXMLException;
25
import org.apache.poi.POIXMLException;
Lines 30-44 Link Here
30
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
31
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
31
import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
32
import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
32
import org.apache.poi.openxml4j.opc.*;
33
import org.apache.poi.openxml4j.opc.*;
33
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBody;
34
import org.openxmlformats.schemas.wordprocessingml.x2006.main.*;
34
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTComment;
35
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTDocument1;
36
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP;
37
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTStyles;
38
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl;
39
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CommentsDocument;
40
import org.openxmlformats.schemas.wordprocessingml.x2006.main.DocumentDocument;
41
import org.openxmlformats.schemas.wordprocessingml.x2006.main.StylesDocument;
42
35
43
import javax.xml.namespace.QName;
36
import javax.xml.namespace.QName;
44
37
Lines 60-65 Link Here
60
    protected List<XWPFHyperlink> hyperlinks;
53
    protected List<XWPFHyperlink> hyperlinks;
61
    protected List<XWPFParagraph> paragraphs;
54
    protected List<XWPFParagraph> paragraphs;
62
    protected List<XWPFTable> tables;
55
    protected List<XWPFTable> tables;
56
    protected Map<BigInteger, XWPFFootnote> footnotes;
63
57
64
    /** Handles the joy of different headers/footers for different pages */
58
    /** Handles the joy of different headers/footers for different pages */
65
    private XWPFHeaderFooterPolicy headerFooterPolicy;
59
    private XWPFHeaderFooterPolicy headerFooterPolicy;
Lines 87-92 Link Here
87
        comments = new ArrayList<XWPFComment>();
81
        comments = new ArrayList<XWPFComment>();
88
        paragraphs = new ArrayList<XWPFParagraph>();
82
        paragraphs = new ArrayList<XWPFParagraph>();
89
        tables= new ArrayList<XWPFTable>();
83
        tables= new ArrayList<XWPFTable>();
84
        footnotes = new HashMap<BigInteger, XWPFFootnote>();
90
85
91
        try {
86
        try {
92
            DocumentDocument doc = DocumentDocument.Factory.parse(getPackagePart().getInputStream());
87
            DocumentDocument doc = DocumentDocument.Factory.parse(getPackagePart().getInputStream());
Lines 94-99 Link Here
94
89
95
            CTBody body = ctDocument.getBody();
90
            CTBody body = ctDocument.getBody();
96
91
92
            initFootnotes();
93
97
            // filling paragraph list
94
            // filling paragraph list
98
            for (CTP p : body.getPArray())	{
95
            for (CTP p : body.getPArray())	{
99
                paragraphs.add(new XWPFParagraph(p, this));
96
                paragraphs.add(new XWPFParagraph(p, this));
Lines 118-124 Link Here
118
            }
115
            }
119
116
120
            initHyperlinks();
117
            initHyperlinks();
121
122
        } catch (XmlException e) {
118
        } catch (XmlException e) {
123
            throw new POIXMLException(e);
119
            throw new POIXMLException(e);
124
        }
120
        }
Lines 139-144 Link Here
139
        }
135
        }
140
    }
136
    }
141
137
138
    private void initFootnotes() throws XmlException, IOException {
139
        for(POIXMLDocumentPart p : getRelations()){
140
            String relation = p.getPackageRelationship().getRelationshipType();
141
            if(relation.equals(XWPFRelation.FOOTNOTE.getRelation())){
142
                FootnotesDocument footnotesDocument = FootnotesDocument.Factory.parse(p.getPackagePart().getInputStream());
143
144
                for(CTFtnEdn ctFtnEdn : footnotesDocument.getFootnotes().getFootnoteArray()) {
145
                    footnotes.put(ctFtnEdn.getId(), new XWPFFootnote(this, ctFtnEdn));
146
                }
147
            }
148
        }
149
    }
150
142
    /**
151
    /**
143
     * Create a new SpreadsheetML package and setup the default minimal content
152
     * Create a new SpreadsheetML package and setup the default minimal content
144
     */
153
     */
Lines 205-210 Link Here
205
214
206
        return null;
215
        return null;
207
    }
216
    }
217
218
    public XWPFFootnote getFootnoteByID(BigInteger id) {
219
        return footnotes.get(id);
220
    }
221
208
    public XWPFHyperlink[] getHyperlinks() {
222
    public XWPFHyperlink[] getHyperlinks() {
209
        return hyperlinks.toArray(
223
        return hyperlinks.toArray(
210
                new XWPFHyperlink[hyperlinks.size()]
224
                new XWPFHyperlink[hyperlinks.size()]
(-)src/ooxml/java/org/apache/poi/xwpf/model/XWPFHyperlinkDecorator.java (-1 / +1 lines)
Lines 19-25 Link Here
19
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTHyperlink;
19
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTHyperlink;
20
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTR;
20
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTR;
21
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTText;
21
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTText;
22
import org.apache.poi.xwpf.usermodel.XWPFParagraph;;
22
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
23
23
24
/**
24
/**
25
 * Decorator class for XWPFParagraph allowing to add hyperlinks 
25
 * Decorator class for XWPFParagraph allowing to add hyperlinks 
(-)src/ooxml/testcases/org/apache/poi/xwpf/extractor/TestXWPFWordExtractor.java (-1 / +22 lines)
Lines 54-59 Link Here
54
	private XWPFDocument xmlE;
54
	private XWPFDocument xmlE;
55
	private File fileE;
55
	private File fileE;
56
56
57
        /**
58
         * File with footnotes
59
        */
60
        private XWPFDocument xmlFootnotes;
61
        private File fileFootnotes;
62
57
	protected void setUp() throws Exception {
63
	protected void setUp() throws Exception {
58
		super.setUp();
64
		super.setUp();
59
		
65
		
Lines 77-93 Link Here
77
				System.getProperty("HWPF.testdata.path") +
83
				System.getProperty("HWPF.testdata.path") +
78
				File.separator + "TestDocument.docx"
84
				File.separator + "TestDocument.docx"
79
		);
85
		);
86
                fileFootnotes = new File(
87
                                System.getProperty("HWPF.testdata.path") +
88
                                File.separator + "snoska.docx"
89
                );
90
80
		assertTrue(fileA.exists());
91
		assertTrue(fileA.exists());
81
		assertTrue(fileB.exists());
92
		assertTrue(fileB.exists());
82
		assertTrue(fileC.exists());
93
		assertTrue(fileC.exists());
83
		assertTrue(fileD.exists());
94
		assertTrue(fileD.exists());
84
		assertTrue(fileE.exists());
95
		assertTrue(fileE.exists());
85
		
96
                assertTrue(fileFootnotes.exists());
97
86
		xmlA = new XWPFDocument(POIXMLDocument.openPackage(fileA.toString()));
98
		xmlA = new XWPFDocument(POIXMLDocument.openPackage(fileA.toString()));
87
		xmlB = new XWPFDocument(POIXMLDocument.openPackage(fileB.toString()));
99
		xmlB = new XWPFDocument(POIXMLDocument.openPackage(fileB.toString()));
88
		xmlC = new XWPFDocument(POIXMLDocument.openPackage(fileC.toString()));
100
		xmlC = new XWPFDocument(POIXMLDocument.openPackage(fileC.toString()));
89
		xmlD = new XWPFDocument(POIXMLDocument.openPackage(fileD.toString()));
101
		xmlD = new XWPFDocument(POIXMLDocument.openPackage(fileD.toString()));
90
		xmlE = new XWPFDocument(POIXMLDocument.openPackage(fileE.toString()));
102
		xmlE = new XWPFDocument(POIXMLDocument.openPackage(fileE.toString()));
103
                xmlFootnotes = new XWPFDocument(POIXMLDocument.openPackage(fileFootnotes.toString()));
91
	}
104
	}
92
105
93
	/**
106
	/**
Lines 225-228 Link Here
225
				extractor.getText()
238
				extractor.getText()
226
		);
239
		);
227
	}
240
	}
241
242
        public void testFootnotes() throws Exception {
243
                XWPFWordExtractor extractor =
244
                        new XWPFWordExtractor(xmlFootnotes);
245
                extractor.getText();
246
247
                assertTrue(extractor.getText().contains("snoska"));
248
        }
228
}
249
}

Return to bug 45556