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

(-)a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java (+12 lines)
Lines 54-59 public class XWPFDocument extends POIXMLDocument { Link Here
54
    protected List<XWPFParagraph> paragraphs;
54
    protected List<XWPFParagraph> paragraphs;
55
    protected List<XWPFTable> tables;
55
    protected List<XWPFTable> tables;
56
    protected Map<BigInteger, XWPFFootnote> footnotes;
56
    protected Map<BigInteger, XWPFFootnote> footnotes;
57
    protected Map<BigInteger, XWPFFootnote> endnotes;
57
58
58
    /** Handles the joy of different headers/footers for different pages */
59
    /** Handles the joy of different headers/footers for different pages */
59
    private XWPFHeaderFooterPolicy headerFooterPolicy;
60
    private XWPFHeaderFooterPolicy headerFooterPolicy;
Lines 82-87 public class XWPFDocument extends POIXMLDocument { Link Here
82
        paragraphs = new ArrayList<XWPFParagraph>();
83
        paragraphs = new ArrayList<XWPFParagraph>();
83
        tables= new ArrayList<XWPFTable>();
84
        tables= new ArrayList<XWPFTable>();
84
        footnotes = new HashMap<BigInteger, XWPFFootnote>();
85
        footnotes = new HashMap<BigInteger, XWPFFootnote>();
86
        endnotes = new HashMap<BigInteger, XWPFFootnote>();
85
87
86
        try {
88
        try {
87
            DocumentDocument doc = DocumentDocument.Factory.parse(getPackagePart().getInputStream());
89
            DocumentDocument doc = DocumentDocument.Factory.parse(getPackagePart().getInputStream());
Lines 144-149 public class XWPFDocument extends POIXMLDocument { Link Here
144
                for(CTFtnEdn ctFtnEdn : footnotesDocument.getFootnotes().getFootnoteArray()) {
146
                for(CTFtnEdn ctFtnEdn : footnotesDocument.getFootnotes().getFootnoteArray()) {
145
                    footnotes.put(ctFtnEdn.getId(), new XWPFFootnote(this, ctFtnEdn));
147
                    footnotes.put(ctFtnEdn.getId(), new XWPFFootnote(this, ctFtnEdn));
146
                }
148
                }
149
            } else if (relation.equals(XWPFRelation.ENDNOTE.getRelation())){
150
                EndnotesDocument endnotesDocument = EndnotesDocument.Factory.parse(p.getPackagePart().getInputStream());
151
152
                for(CTFtnEdn ctFtnEdn : endnotesDocument.getEndnotes().getEndnoteArray()) {
153
                    endnotes.put(ctFtnEdn.getId(), new XWPFFootnote(this, ctFtnEdn));
154
                }
147
            }
155
            }
148
        }
156
        }
149
    }
157
    }
Lines 219-224 public class XWPFDocument extends POIXMLDocument { Link Here
219
        return footnotes.get(id);
227
        return footnotes.get(id);
220
    }
228
    }
221
229
230
    public XWPFFootnote getEndnoteByID(BigInteger id) {
231
        return endnotes.get(id);
232
    }
233
222
    public XWPFHyperlink[] getHyperlinks() {
234
    public XWPFHyperlink[] getHyperlinks() {
223
        return hyperlinks.toArray(
235
        return hyperlinks.toArray(
224
                new XWPFHyperlink[hyperlinks.size()]
236
                new XWPFHyperlink[hyperlinks.size()]
(-)a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java (-1 / +2 lines)
Lines 91-97 public class XWPFParagraph { Link Here
91
                    if (o instanceof CTFtnEdnRef) {
91
                    if (o instanceof CTFtnEdnRef) {
92
                        CTFtnEdnRef ftn = (CTFtnEdnRef) o;
92
                        CTFtnEdnRef ftn = (CTFtnEdnRef) o;
93
                        text.append("[").append(ftn.getId()).append(": ");
93
                        text.append("[").append(ftn.getId()).append(": ");
94
                        XWPFFootnote footnote = document.getFootnoteByID(ftn.getId());
94
                        XWPFFootnote footnote = 
95
                                ftn.getDomNode().getLocalName().equals("footnoteReference")?document.getFootnoteByID(ftn.getId()):document.getEndnoteByID(ftn.getId());
95
96
96
                        boolean first = true;
97
                        boolean first = true;
97
98
(-)a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRelation.java (-1 / +6 lines)
Lines 112-118 public final class XWPFRelation extends POIXMLRelation { Link Here
112
            null,
112
            null,
113
            null
113
            null
114
    );
114
    );
115
115
    public static final XWPFRelation ENDNOTE = new XWPFRelation(
116
            null,
117
            "http://schemas.openxmlformats.org/officeDocument/2006/relationships/endnotes",
118
            null,
119
            null
120
    );
116
121
117
    private XWPFRelation(String type, String rel, String defaultName, Class<? extends POIXMLDocumentPart> cls) {
122
    private XWPFRelation(String type, String rel, String defaultName, Class<? extends POIXMLDocumentPart> cls) {
118
        super(type, rel, defaultName, cls);
123
        super(type, rel, defaultName, cls);
(-)a/src/ooxml/testcases/org/apache/poi/xwpf/extractor/TestXWPFWordExtractor.java (+20 lines)
Lines 66-71 public class TestXWPFWordExtractor extends TestCase { Link Here
66
        private XWPFDocument xmlFootnotes2;
66
        private XWPFDocument xmlFootnotes2;
67
        private File fileFootnotes2;
67
        private File fileFootnotes2;
68
68
69
        /**
70
         * File with endnotes
71
        */
72
        private XWPFDocument xmlEndnotes;
73
        private File fileEndnotes;
74
69
	protected void setUp() throws Exception {
75
	protected void setUp() throws Exception {
70
		super.setUp();
76
		super.setUp();
71
		
77
		
Lines 97-102 public class TestXWPFWordExtractor extends TestCase { Link Here
97
                                System.getProperty("HWPF.testdata.path") +
103
                                System.getProperty("HWPF.testdata.path") +
98
                                File.separator + "Table.docx"
104
                                File.separator + "Table.docx"
99
                );
105
                );
106
                fileEndnotes = new File(
107
                                System.getProperty("HWPF.testdata.path") +
108
                                File.separator + "A Nepalese name for Tilaka.docx"
109
                );
100
110
101
		assertTrue(fileA.exists());
111
		assertTrue(fileA.exists());
102
		assertTrue(fileB.exists());
112
		assertTrue(fileB.exists());
Lines 105-110 public class TestXWPFWordExtractor extends TestCase { Link Here
105
		assertTrue(fileE.exists());
115
		assertTrue(fileE.exists());
106
                assertTrue(fileFootnotes.exists());
116
                assertTrue(fileFootnotes.exists());
107
                assertTrue(fileFootnotes2.exists());
117
                assertTrue(fileFootnotes2.exists());
118
                assertTrue(fileEndnotes.exists());
108
119
109
		xmlA = new XWPFDocument(POIXMLDocument.openPackage(fileA.toString()));
120
		xmlA = new XWPFDocument(POIXMLDocument.openPackage(fileA.toString()));
110
		xmlB = new XWPFDocument(POIXMLDocument.openPackage(fileB.toString()));
121
		xmlB = new XWPFDocument(POIXMLDocument.openPackage(fileB.toString()));
Lines 113-118 public class TestXWPFWordExtractor extends TestCase { Link Here
113
		xmlE = new XWPFDocument(POIXMLDocument.openPackage(fileE.toString()));
124
		xmlE = new XWPFDocument(POIXMLDocument.openPackage(fileE.toString()));
114
                xmlFootnotes = new XWPFDocument(POIXMLDocument.openPackage(fileFootnotes.toString()));
125
                xmlFootnotes = new XWPFDocument(POIXMLDocument.openPackage(fileFootnotes.toString()));
115
                xmlFootnotes2 = new XWPFDocument(POIXMLDocument.openPackage(fileFootnotes2.toString()));
126
                xmlFootnotes2 = new XWPFDocument(POIXMLDocument.openPackage(fileFootnotes2.toString()));
127
                xmlEndnotes = new XWPFDocument(POIXMLDocument.openPackage(fileEndnotes.toString()));
116
	}
128
	}
117
129
118
	/**
130
	/**
Lines 267-270 public class TestXWPFWordExtractor extends TestCase { Link Here
267
                assertTrue(extractor.getText().contains("snoska"));
279
                assertTrue(extractor.getText().contains("snoska"));
268
        }
280
        }
269
281
282
        public void testEndnotes() throws Exception {
283
                XWPFWordExtractor extractor =
284
                        new XWPFWordExtractor(xmlEndnotes);
285
                extractor.getText();
286
287
                assertTrue(extractor.getText().contains("XXX"));
288
        }
289
270
}
290
}

Return to bug 45556