diff options
Diffstat (limited to 'poi-ooxml')
-rw-r--r-- | poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFSDTCell.java | 10 | ||||
-rw-r--r-- | poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFSDTContentCell.java | 26 |
2 files changed, 32 insertions, 4 deletions
diff --git a/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFSDTCell.java b/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFSDTCell.java index 5589287263..294831b9a7 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFSDTCell.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFSDTCell.java @@ -29,9 +29,11 @@ import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSdtCell; */ public class XWPFSDTCell extends XWPFAbstractSDT implements ICell { private final XWPFSDTContentCell cellContent; + private final CTSdtCell sdtCell; public XWPFSDTCell(CTSdtCell sdtCell, XWPFTableRow xwpfTableRow, IBody part) { super(sdtCell.getSdtPr(), part); + this.sdtCell = sdtCell; cellContent = new XWPFSDTContentCell(sdtCell.getSdtContent(), xwpfTableRow, part); } @@ -40,4 +42,12 @@ public class XWPFSDTCell extends XWPFAbstractSDT implements ICell { return cellContent; } + /** + * Return the underlying XML bean. + * @return the underlying CTSdtCell bean. + * @since POI 5.4.2 + */ + public CTSdtCell getCTSdtCell() { + return sdtCell; + } } diff --git a/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFSDTContentCell.java b/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFSDTContentCell.java index d43e24fc43..576e84b064 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFSDTContentCell.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFSDTContentCell.java @@ -40,14 +40,19 @@ public class XWPFSDTContentCell implements ISDTContent { //private List<ICell> cells = new ArrayList<ICell>(). - private String text = ""; + private final CTSdtContentCell sdtContentCell; + private String text; public XWPFSDTContentCell(CTSdtContentCell sdtContentCell, XWPFTableRow xwpfTableRow, IBody part) { super(); + this.sdtContentCell = sdtContentCell; + } + + private String extractTextFromSdtContentCell() { //sdtContentCell is allowed to be null: minOccurs="0" maxOccurs="1" if (sdtContentCell == null) { - return; + return ""; } StringBuilder sb = new StringBuilder(); try (final XmlCursor cursor = sdtContentCell.newCursor()) { @@ -87,7 +92,7 @@ public class XWPFSDTContentCell implements ISDTContent { depth--; } } - text = sb.toString(); + return sb.toString(); } } @@ -103,12 +108,25 @@ public class XWPFSDTContentCell implements ISDTContent { return false; } - + @Override public String getText() { + if (text == null) { + text = extractTextFromSdtContentCell(); + } return text; } + @Override public String toString() { return getText(); } + + /** + * Return the underlying XML bean. + * @return the underlying CTSdtContentCell bean. + * @since POI 5.4.2 + */ + public CTSdtContentCell getCTSdtContentCell() { + return sdtContentCell; + } } |