From 7341e677fbd49cbf691cbd6471b73252122a106b Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Wed, 12 Jun 2013 17:54:39 +0000 Subject: [PATCH] Patch from akhikhl from github pull #3 - Extract references from XWPF footnotes git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1492308 13f79535-47bb-0310-9956-ffa450edef68 --- .../java/org/apache/poi/xwpf/usermodel/XWPFRun.java | 7 +++++++ .../poi/xwpf/extractor/TestXWPFWordExtractor.java | 10 ++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRun.java b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRun.java index 282fca6d11..d6bc531bfd 100644 --- a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRun.java +++ b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRun.java @@ -52,6 +52,7 @@ import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTColor; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTDrawing; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTEmpty; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTFonts; +import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTFtnEdnRef; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTHpsMeasure; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTOnOff; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPTab; @@ -817,6 +818,12 @@ public class XWPFRun { text.append("\n"); } } + if (o instanceof CTFtnEdnRef) { + CTFtnEdnRef ftn = (CTFtnEdnRef)o; + String footnoteRef = ftn.getDomNode().getLocalName().equals("footnoteReference") ? + "[footnoteRef:" + ftn.getId().intValue() + "]" : "[endnoteRef:" + ftn.getId().intValue() + "]"; + text.append(footnoteRef); + } } c.dispose(); diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/extractor/TestXWPFWordExtractor.java b/src/ooxml/testcases/org/apache/poi/xwpf/extractor/TestXWPFWordExtractor.java index 46188f5ed8..34d20aae74 100644 --- a/src/ooxml/testcases/org/apache/poi/xwpf/extractor/TestXWPFWordExtractor.java +++ b/src/ooxml/testcases/org/apache/poi/xwpf/extractor/TestXWPFWordExtractor.java @@ -166,8 +166,9 @@ public class TestXWPFWordExtractor extends TestCase { public void testFootnotes() throws IOException { XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("footnotes.docx"); XWPFWordExtractor extractor = new XWPFWordExtractor(doc); - - assertTrue(extractor.getText().contains("snoska")); + String text = extractor.getText(); + assertTrue(text.contains("snoska")); + assertTrue(text.contains("Eto ochen prostoy[footnoteRef:1] text so snoskoy")); } @@ -190,8 +191,9 @@ public class TestXWPFWordExtractor extends TestCase { public void testEndnotes() throws IOException { XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("endnotes.docx"); XWPFWordExtractor extractor = new XWPFWordExtractor(doc); - - assertTrue(extractor.getText().contains("XXX")); + String text = extractor.getText(); + assertTrue(text.contains("XXX")); + assertTrue(text.contains("tilaka [endnoteRef:2]or 'tika'")); } public void testInsertedDeletedText() throws IOException {