Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,17 @@ public XWPFSDTContent(CTSdtContentRun sdtRun, IBody part, IRunBody parent) {
} else if (o instanceof CTSdtRun) {
XWPFSDT c = new XWPFSDT(((CTSdtRun) o), part);
bodyElements.add(c);
} else if (o instanceof CTTrackChange) {
try (final XmlCursor trackChangeCursor = o.newCursor()) {
trackChangeCursor.selectPath("child::*");
while (trackChangeCursor.toNextSelection()) {
XmlObject trackChangeChild = trackChangeCursor.getObject();
if (trackChangeChild instanceof CTR){
XWPFRun run = new XWPFRun((CTR) trackChangeChild, parent);
bodyElements.add(run);
}
}
}
}
}
}
Expand Down Expand Up @@ -123,8 +134,12 @@ public String getText() {
text.append(((XWPFSDT) o).getContent().getText());
addNewLine = true;
} else if (o instanceof XWPFRun) {
text.append(o);
addNewLine = false;
XWPFRun xRun = (XWPFRun) o;
// don't include the text if reviewing is enabled and this is a deleted run
if (xRun.getCTR().getDelTextArray().length == 0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use isEmpty() instead of length == 0

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will make the corresponding changes here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but Here, it's an array, not a collection.

text.append(o);
addNewLine = false;
}
}
if (addNewLine && i < bodyElements.size() - 1) {
text.append("\n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,18 @@ void test62859() throws IOException {
}
}

@Test
void testTrackChangeInSDT() throws IOException {
try (XWPFDocument doc =XWPFTestDataSamples.openSampleDocument("trackChangeInSDT.docx")) {
List<IBodyElement> bodyElements = doc.getBodyElements();
IBodyElement bodyElement = bodyElements.get(0);
if (bodyElement instanceof XWPFParagraph) {
XWPFParagraph p = (XWPFParagraph) bodyElement;
assertEquals("not in track change insert in track change ", p.getText());
}
}
}

private List<XWPFAbstractSDT> extractAllSDTs(XWPFDocument doc) {
List<XWPFAbstractSDT> sdts = new ArrayList<>();

Expand Down
Binary file added test-data/document/trackChangeInSDT.docx
Binary file not shown.