mirror of https://github.com/apache/poi.git
[bug-64561] XWPFSDTContent.getText() is empty for nested SDT elements
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1879223 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
f94dcd461e
commit
06cf5caa2d
|
@ -21,12 +21,7 @@ import java.util.List;
|
|||
|
||||
import org.apache.xmlbeans.XmlCursor;
|
||||
import org.apache.xmlbeans.XmlObject;
|
||||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP;
|
||||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTR;
|
||||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSdtBlock;
|
||||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSdtContentBlock;
|
||||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSdtContentRun;
|
||||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl;
|
||||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.*;
|
||||
|
||||
/**
|
||||
* Experimental class to offer rudimentary read-only processing of
|
||||
|
@ -50,11 +45,19 @@ public class XWPFSDTContent implements ISDTContent {
|
|||
if (sdtRun == null) {
|
||||
return;
|
||||
}
|
||||
for (CTR ctr : sdtRun.getRArray()) {
|
||||
XWPFRun run = new XWPFRun(ctr, parent);
|
||||
// runs.add(run);
|
||||
bodyElements.add(run);
|
||||
XmlCursor cursor = sdtRun.newCursor();
|
||||
cursor.selectPath("./*");
|
||||
while (cursor.toNextSelection()) {
|
||||
XmlObject o = cursor.getObject();
|
||||
if (o instanceof CTR) {
|
||||
XWPFRun run = new XWPFRun((CTR) o, parent);
|
||||
bodyElements.add(run);
|
||||
} else if (o instanceof CTSdtRun) {
|
||||
XWPFSDT c = new XWPFSDT(((CTSdtRun) o), part);
|
||||
bodyElements.add(c);
|
||||
}
|
||||
}
|
||||
cursor.dispose();
|
||||
}
|
||||
|
||||
public XWPFSDTContent(CTSdtContentBlock block, IBody part, IRunBody parent) {
|
||||
|
|
|
@ -30,6 +30,17 @@ import org.junit.Test;
|
|||
|
||||
public final class TestXWPFSDT {
|
||||
|
||||
/**
|
||||
* Test text extraction from nested SDTs
|
||||
*/
|
||||
@Test
|
||||
public void testNestedSDTs() throws Exception {
|
||||
try (XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("Bug64561.docx")) {
|
||||
XWPFAbstractSDT sdt = extractAllSDTs(doc).get(0);
|
||||
assertEquals("extracted text", "Subject", sdt.getContent().getText());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test simple tag and title extraction from SDT
|
||||
*/
|
||||
|
|
Binary file not shown.
Loading…
Reference in New Issue