Support for extraction of endnotes from docx files
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@795329 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
fa31a65d14
commit
656114c69a
@ -33,8 +33,9 @@
|
|||||||
|
|
||||||
<changes>
|
<changes>
|
||||||
<release version="3.5-beta7" date="2009-??-??">
|
<release version="3.5-beta7" date="2009-??-??">
|
||||||
<action dev="POI-DEVELOPERS" type="fix">45556 - Fixed ExtractorFactory to support .xltx and .dotx files</action>
|
<action dev="POI-DEVELOPERS" type="fix">47517 - Fixed ExtractorFactory to support .xltx and .dotx files</action>
|
||||||
<action dev="POI-DEVELOPERS" type="add">45556 - Support for extraction of footnotes from docx files</action>
|
<action dev="POI-DEVELOPERS" type="add">45556 - Support for extraction of footnotes from docx files</action>
|
||||||
|
<action dev="POI-DEVELOPERS" type="add">45555 - Support for extraction of endnotes from docx files</action>
|
||||||
<action dev="POI-DEVELOPERS" type="add">47520 - Initial support for custom XML mappings in XSSF</action>
|
<action dev="POI-DEVELOPERS" type="add">47520 - Initial support for custom XML mappings in XSSF</action>
|
||||||
<action dev="POI-DEVELOPERS" type="fix">47460 - Fixed NPE when retrieving core properties from a newly created workbook</action>
|
<action dev="POI-DEVELOPERS" type="fix">47460 - Fixed NPE when retrieving core properties from a newly created workbook</action>
|
||||||
<action dev="POI-DEVELOPERS" type="fix">47498 - Fixed HyperlinkRecord to properly handle URL monikers</action>
|
<action dev="POI-DEVELOPERS" type="fix">47498 - Fixed HyperlinkRecord to properly handle URL monikers</action>
|
||||||
|
@ -53,6 +53,7 @@ public class XWPFDocument extends POIXMLDocument {
|
|||||||
protected List<XWPFParagraph> paragraphs;
|
protected List<XWPFParagraph> paragraphs;
|
||||||
protected List<XWPFTable> tables;
|
protected List<XWPFTable> tables;
|
||||||
protected Map<Integer, XWPFFootnote> footnotes;
|
protected Map<Integer, XWPFFootnote> footnotes;
|
||||||
|
protected Map<Integer, XWPFFootnote> endnotes;
|
||||||
|
|
||||||
/** Handles the joy of different headers/footers for different pages */
|
/** Handles the joy of different headers/footers for different pages */
|
||||||
private XWPFHeaderFooterPolicy headerFooterPolicy;
|
private XWPFHeaderFooterPolicy headerFooterPolicy;
|
||||||
@ -81,6 +82,7 @@ public class XWPFDocument extends POIXMLDocument {
|
|||||||
paragraphs = new ArrayList<XWPFParagraph>();
|
paragraphs = new ArrayList<XWPFParagraph>();
|
||||||
tables= new ArrayList<XWPFTable>();
|
tables= new ArrayList<XWPFTable>();
|
||||||
footnotes = new HashMap<Integer, XWPFFootnote>();
|
footnotes = new HashMap<Integer, XWPFFootnote>();
|
||||||
|
endnotes = new HashMap<Integer, XWPFFootnote>();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
DocumentDocument doc = DocumentDocument.Factory.parse(getPackagePart().getInputStream());
|
DocumentDocument doc = DocumentDocument.Factory.parse(getPackagePart().getInputStream());
|
||||||
@ -143,6 +145,12 @@ public class XWPFDocument extends POIXMLDocument {
|
|||||||
for(CTFtnEdn ctFtnEdn : footnotesDocument.getFootnotes().getFootnoteArray()) {
|
for(CTFtnEdn ctFtnEdn : footnotesDocument.getFootnotes().getFootnoteArray()) {
|
||||||
footnotes.put(ctFtnEdn.getId().intValue(), new XWPFFootnote(this, ctFtnEdn));
|
footnotes.put(ctFtnEdn.getId().intValue(), new XWPFFootnote(this, ctFtnEdn));
|
||||||
}
|
}
|
||||||
|
} else if (relation.equals(XWPFRelation.ENDNOTE.getRelation())){
|
||||||
|
EndnotesDocument endnotesDocument = EndnotesDocument.Factory.parse(p.getPackagePart().getInputStream());
|
||||||
|
|
||||||
|
for(CTFtnEdn ctFtnEdn : endnotesDocument.getEndnotes().getEndnoteArray()) {
|
||||||
|
endnotes.put(ctFtnEdn.getId().intValue(), new XWPFFootnote(this, ctFtnEdn));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -218,6 +226,10 @@ public class XWPFDocument extends POIXMLDocument {
|
|||||||
return footnotes.get(id);
|
return footnotes.get(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public XWPFFootnote getEndnoteByID(int id) {
|
||||||
|
return endnotes.get(id);
|
||||||
|
}
|
||||||
|
|
||||||
public Collection<XWPFFootnote> getFootnotes() {
|
public Collection<XWPFFootnote> getFootnotes() {
|
||||||
return footnotes == null ? new ArrayList<XWPFFootnote>() : footnotes.values();
|
return footnotes == null ? new ArrayList<XWPFFootnote>() : footnotes.values();
|
||||||
}
|
}
|
||||||
|
@ -93,7 +93,10 @@ public class XWPFParagraph {
|
|||||||
if (o instanceof CTFtnEdnRef) {
|
if (o instanceof CTFtnEdnRef) {
|
||||||
CTFtnEdnRef ftn = (CTFtnEdnRef) o;
|
CTFtnEdnRef ftn = (CTFtnEdnRef) o;
|
||||||
footnoteText.append("[").append(ftn.getId()).append(": ");
|
footnoteText.append("[").append(ftn.getId()).append(": ");
|
||||||
XWPFFootnote footnote = document.getFootnoteByID(ftn.getId().intValue());
|
XWPFFootnote footnote =
|
||||||
|
ftn.getDomNode().getLocalName().equals("footnoteReference") ?
|
||||||
|
document.getFootnoteByID(ftn.getId().intValue()) :
|
||||||
|
document.getEndnoteByID(ftn.getId().intValue());
|
||||||
|
|
||||||
boolean first = true;
|
boolean first = true;
|
||||||
for (XWPFParagraph p : footnote.getParagraphs()) {
|
for (XWPFParagraph p : footnote.getParagraphs()) {
|
||||||
|
@ -112,6 +112,12 @@ public final class XWPFRelation extends POIXMLRelation {
|
|||||||
null,
|
null,
|
||||||
null
|
null
|
||||||
);
|
);
|
||||||
|
public static final XWPFRelation ENDNOTE = new XWPFRelation(
|
||||||
|
null,
|
||||||
|
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/endnotes",
|
||||||
|
null,
|
||||||
|
null
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
private XWPFRelation(String type, String rel, String defaultName, Class<? extends POIXMLDocumentPart> cls) {
|
private XWPFRelation(String type, String rel, String defaultName, Class<? extends POIXMLDocumentPart> cls) {
|
||||||
|
@ -185,7 +185,15 @@ public class TestXWPFWordExtractor extends TestCase {
|
|||||||
assertTrue("Unable to find expected word in text\n" + text, text.contains("test phrase"));
|
assertTrue("Unable to find expected word in text\n" + text, text.contains("test phrase"));
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO use the same logic as in HSSFTestDataSamples
|
public void testEndnotes() throws Exception {
|
||||||
|
XWPFDocument doc = open("endnotes.docx");
|
||||||
|
XWPFWordExtractor extractor = new XWPFWordExtractor(doc);
|
||||||
|
|
||||||
|
assertTrue(extractor.getText().contains("XXX"));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//TODO use the same logic for opening test files as in HSSFTestDataSamples
|
||||||
private XWPFDocument open(String sampleFileName) throws IOException {
|
private XWPFDocument open(String sampleFileName) throws IOException {
|
||||||
File file = new File(
|
File file = new File(
|
||||||
System.getProperty("HWPF.testdata.path"), sampleFileName);
|
System.getProperty("HWPF.testdata.path"), sampleFileName);
|
||||||
|
BIN
src/scratchpad/testcases/org/apache/poi/hwpf/data/endnotes.docx
Executable file
BIN
src/scratchpad/testcases/org/apache/poi/hwpf/data/endnotes.docx
Executable file
Binary file not shown.
Loading…
Reference in New Issue
Block a user