Skip to content

Commit

Permalink
fix for information loss on footnotes within XWPFRun.toString
Browse files Browse the repository at this point in the history
  • Loading branch information
akhikhl committed Jun 12, 2013
1 parent 09c79ff commit a6dfe98
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
7 changes: 7 additions & 0 deletions src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRun.java
Expand Up @@ -52,6 +52,7 @@ Licensed to the Apache Software Foundation (ASF) under one or more
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;
Expand Down Expand Up @@ -817,6 +818,12 @@ public String toString() {
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();
Expand Down
Expand Up @@ -166,8 +166,9 @@ public void testHeadersFooters() throws IOException {
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"));
}


Expand All @@ -190,8 +191,9 @@ public void testFormFootnotes() throws IOException {
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 {
Expand Down

0 comments on commit a6dfe98

Please sign in to comment.