-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ASP-28550] Docx with un-accepted changes #72
base: trunk-airslate
Are you sure you want to change the base?
Changes from all commits
6620ad8
062a80e
e124225
0ab99ed
978a669
c23efe6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package org.apache.poi.xwpf.usermodel; | ||
|
||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTR; | ||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRunTrackChange; | ||
|
||
public class XWPFTrackChangeRun extends XWPFRun { | ||
private CTRunTrackChange trackChange; | ||
|
||
public XWPFTrackChangeRun(CTRunTrackChange trackChange, CTR r, IRunBody p) { | ||
super(r, p); | ||
this.trackChange = trackChange; | ||
} | ||
|
||
public CTRunTrackChange getTrackChange() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Тут и в методах ниже this не обяз. писать для доступа к проперти |
||
return trackChange; | ||
} | ||
|
||
public String getAuthor() { | ||
return trackChange.getAuthor(); | ||
} | ||
|
||
public void setAuthor(String author) { | ||
trackChange.setAuthor(author); | ||
} | ||
|
||
public java.util.Calendar getDate() { | ||
return trackChange.getDate(); | ||
} | ||
|
||
public void setDate(java.util.Calendar date) { | ||
trackChange.setDate(date); | ||
} | ||
|
||
public boolean isDel() { | ||
return trackChange.getDomNode().getLocalName().equals("del"); | ||
} | ||
|
||
public boolean isIns() { | ||
return trackChange.getDomNode().getLocalName().equals("ins"); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,12 +17,6 @@ Licensed to the Apache Software Foundation (ASF) under one or more | |
|
||
package org.apache.poi.xwpf.usermodel; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.io.IOException; | ||
import java.math.BigInteger; | ||
import java.util.List; | ||
|
@@ -34,21 +28,10 @@ Licensed to the Apache Software Foundation (ASF) under one or more | |
import org.openxmlformats.schemas.drawingml.x2006.picture.PicDocument; | ||
import org.openxmlformats.schemas.drawingml.x2006.picture.impl.PicDocumentImpl; | ||
import org.openxmlformats.schemas.officeDocument.x2006.sharedTypes.STOnOff1; | ||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBookmark; | ||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBorder; | ||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTInd; | ||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTJc; | ||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTOnOff; | ||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP; | ||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPBdr; | ||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPPr; | ||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTR; | ||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSpacing; | ||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTextAlignment; | ||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STBorder; | ||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STJc; | ||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STLineSpacingRule; | ||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STTextAlignment; | ||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.*; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
/** | ||
* Tests for XWPF Paragraphs | ||
|
@@ -74,6 +57,65 @@ void testHeaderParagraph() throws IOException { | |
} | ||
} | ||
|
||
@Test | ||
void testUnAcceptedChanges() throws IOException { | ||
try (XWPFDocument xml = XWPFTestDataSamples.openSampleDocument("UnAcceptedChangesTest.docx")) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Еще нужны тесты на remove аля Мб еще есть тесты в этом классе где мы вариантивно создаем разные раны - туда нужно тоже добавить новый ран |
||
List<XWPFParagraph> paragraphs = xml.getParagraphs(); | ||
XWPFRun delRun = paragraphs.get(0).getRuns().get(3); | ||
XWPFRun insRun = paragraphs.get(0).getRuns().get(4); | ||
|
||
assertTrue(delRun instanceof XWPFTrackChangeRun); | ||
assertTrue(insRun instanceof XWPFTrackChangeRun); | ||
assertTrue(paragraphs.get(0).getRuns().get(1) instanceof XWPFTrackChangeRun); | ||
|
||
assertEquals("2022-10-26T13:13:55Z", ((XWPFTrackChangeRun) delRun).getDate().toString()); | ||
assertEquals("Pavlo Vavilov", ((XWPFTrackChangeRun) delRun).getAuthor()); | ||
|
||
assertTrue(((XWPFTrackChangeRun) delRun).isDel()); | ||
assertTrue(((XWPFTrackChangeRun) insRun).isIns()); | ||
assertFalse(((XWPFTrackChangeRun) delRun).isIns()); | ||
assertFalse(((XWPFTrackChangeRun) insRun).isDel()); | ||
} | ||
} | ||
|
||
@Test | ||
void testIsInsCTP() throws IOException { | ||
try (XWPFDocument xml = XWPFTestDataSamples.openSampleDocument("UnAcceptedChangesTest.docx")) { | ||
List<XWPFParagraph> paragraphs = xml.getParagraphs(); | ||
boolean insCTP = paragraphs.get(5).isInsCTP(); | ||
assertTrue(insCTP); | ||
} | ||
} | ||
|
||
@Test | ||
void testIsInsParagraph() throws IOException { | ||
try (XWPFDocument xml = XWPFTestDataSamples.openSampleDocument("UnAcceptedChangesTest.docx")) { | ||
List<XWPFParagraph> paragraphs = xml.getParagraphs(); | ||
boolean insCTP = paragraphs.get(5).isInsParagraph(); | ||
assertFalse(insCTP); | ||
boolean insCTP2 = paragraphs.get(6).isInsParagraph(); | ||
assertTrue(insCTP2); | ||
} | ||
} | ||
|
||
@Test | ||
void testIsDelCTP() throws IOException { | ||
try (XWPFDocument xml = XWPFTestDataSamples.openSampleDocument("UnAcceptedChangesTest.docx")) { | ||
List<XWPFParagraph> paragraphs = xml.getParagraphs(); | ||
boolean delCTP = paragraphs.get(3).isDelCTP(); | ||
assertTrue(delCTP); | ||
} | ||
} | ||
|
||
@Test | ||
void testIsDelParagraph() throws IOException { | ||
try (XWPFDocument xml = XWPFTestDataSamples.openSampleDocument("UnAcceptedChangesTest.docx")) { | ||
List<XWPFParagraph> paragraphs = xml.getParagraphs(); | ||
boolean delCTP = paragraphs.get(3).isDelParagraph(); | ||
assertTrue(delCTP); | ||
} | ||
} | ||
|
||
/** | ||
* Check that we get the right paragraphs from the document | ||
*/ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
раз уж мы тут вносим измнения, то может добавим сюда вот эти вот методы?
https://github.com/pdffiller/dadadocs-scripting-template-engine/pull/475/files#diff-52316947a9ce35960fd4534be4ce3cd1b30dc8d78081839e75a67628a04ce86dR26