poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From abea...@apache.org
Subject svn commit: r1875746 - in /poi/trunk/src/ooxml: java/org/apache/poi/xwpf/usermodel/XWPFTableCell.java testcases/org/apache/poi/xwpf/usermodel/TestXWPFTableCell.java
Date Fri, 27 Mar 2020 03:13:37 GMT
Author: abearez
Date: Fri Mar 27 03:13:37 2020
New Revision: 1875746

URL: http://svn.apache.org/viewvc?rev=1875746&view=rev
Log:
XWPFTableCell does not process bodyElements when handle paragraph

Modified:
    poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTableCell.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFTableCell.java

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTableCell.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTableCell.java?rev=1875746&r1=1875745&r2=1875746&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTableCell.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTableCell.java Fri Mar 27 03:13:37
2020
@@ -160,6 +160,7 @@ public class XWPFTableCell implements IB
      */
     public void addParagraph(XWPFParagraph p) {
         paragraphs.add(p);
+        bodyElements.add(p);
     }
 
     /**
@@ -168,8 +169,10 @@ public class XWPFTableCell implements IB
      * @param pos The position in the list of paragraphs, 0-based
      */
     public void removeParagraph(int pos) {
+        XWPFParagraph removedParagraph = paragraphs.get(pos);
         paragraphs.remove(pos);
         ctTc.removeP(pos);
+        bodyElements.remove(removedParagraph);
     }
 
     /**

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFTableCell.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFTableCell.java?rev=1875746&r1=1875745&r2=1875746&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFTableCell.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFTableCell.java Fri
Mar 27 03:13:37 2020
@@ -151,6 +151,58 @@ public class TestXWPFTableCell {
     }
 
     @Test
+    public void testAddParagraph() throws Exception {
+        XWPFDocument doc = new XWPFDocument();
+        XWPFTable table = doc.createTable();
+        XWPFTableRow tr = table.createRow();
+        XWPFTableCell cell = tr.addNewTableCell();
+
+        // cell have at least one paragraph by default
+        assertEquals(1, cell.getParagraphs().size());
+        assertEquals(1, cell.getBodyElements().size());
+        assertEquals(cell.getParagraphArray(0), cell.getBodyElements().get(0));
+
+        XWPFParagraph p = cell.addParagraph();
+        assertEquals(2, cell.getParagraphs().size());
+        assertEquals(2, cell.getBodyElements().size());
+        assertEquals(p, cell.getParagraphArray(1));
+        assertEquals(cell.getParagraphArray(1), cell.getBodyElements().get(1));
+
+        doc.close();
+    }
+
+    @Test
+    public void testRemoveParagraph() throws Exception {
+        XWPFDocument doc = new XWPFDocument();
+        XWPFTable table = doc.createTable();
+        XWPFTableRow tr = table.createRow();
+        XWPFTableCell cell = tr.addNewTableCell();
+
+        // cell have at least one paragraph by default
+        XWPFParagraph p0 = cell.getParagraphArray(0);
+        XWPFParagraph p1 = cell.addParagraph();
+        cell.addParagraph();
+
+        // remove 3rd
+        cell.removeParagraph(2);
+        assertEquals(2, cell.getParagraphs().size());
+        assertEquals(2, cell.getBodyElements().size());
+        assertEquals(p0, cell.getParagraphArray(0));
+        assertEquals(p1, cell.getParagraphArray(1));
+        assertEquals(p0, cell.getBodyElements().get(0));
+        assertEquals(p1, cell.getBodyElements().get(1));
+
+        // remove 2nd
+        cell.removeParagraph(1);
+        assertEquals(1, cell.getParagraphs().size());
+        assertEquals(1, cell.getBodyElements().size());
+        assertEquals(p0, cell.getParagraphArray(0));
+        assertEquals(p0, cell.getBodyElements().get(0));
+
+        doc.close();
+    }
+
+    @Test
     public void testBug63624() throws Exception {
         XWPFDocument doc = new XWPFDocument();
         XWPFTable table = doc.createTable(1, 1);



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message