poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From abea...@apache.org
Subject svn commit: r1875747 - in /poi/trunk/src/ooxml: java/org/apache/poi/xwpf/usermodel/XWPFAbstractNum.java java/org/apache/poi/xwpf/usermodel/XWPFNumbering.java testcases/org/apache/poi/xwpf/usermodel/TestXWPFNumbering.java
Date Fri, 27 Mar 2020 03:13:41 GMT
Author: abearez
Date: Fri Mar 27 03:13:40 2020
New Revision: 1875747

URL: http://svn.apache.org/viewvc?rev=1875747&view=rev
Log:
XWPFNumbering.addAbstractNum will definitely throw an exception

Modified:
    poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFAbstractNum.java
    poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFNumbering.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFNumbering.java

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFAbstractNum.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFAbstractNum.java?rev=1875747&r1=1875746&r2=1875747&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFAbstractNum.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFAbstractNum.java Fri Mar 27
03:13:40 2020
@@ -57,4 +57,8 @@ public class XWPFAbstractNum {
         return ctAbstractNum;
     }
 
+    public void setCtAbstractNum(CTAbstractNum ctAbstractNum) {
+        this.ctAbstractNum = ctAbstractNum;
+    }
+
 }

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFNumbering.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFNumbering.java?rev=1875747&r1=1875746&r2=1875747&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFNumbering.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFNumbering.java Fri Mar 27 03:13:40
2020
@@ -23,6 +23,7 @@ import java.io.InputStream;
 import java.io.OutputStream;
 import java.math.BigInteger;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 
 import javax.xml.namespace.QName;
@@ -237,7 +238,7 @@ public class XWPFNumbering extends POIXM
         if (abstractNum.getAbstractNum() != null) { // Use the current CTAbstractNum if it
exists
             ctNumbering.addNewAbstractNum().set(abstractNum.getAbstractNum());
         } else {
-            ctNumbering.addNewAbstractNum();
+            abstractNum.setCtAbstractNum(ctNumbering.addNewAbstractNum());
             abstractNum.getAbstractNum().setAbstractNumId(BigInteger.valueOf(pos));
             ctNumbering.setAbstractNumArray(pos, abstractNum.getAbstractNum());
         }
@@ -283,5 +284,20 @@ public class XWPFNumbering extends POIXM
             return null;
         return num.getCTNum().getAbstractNumId().getVal();
     }
+
+    /**
+     * @return all abstractNums
+     */
+    public List<XWPFAbstractNum> getAbstractNums() {
+        return Collections.unmodifiableList(abstractNums);
+    }
+
+    /**
+     * @return all nums
+     */
+    public List<XWPFNum> getNums() {
+        return Collections.unmodifiableList(nums);
+    }
+
 }
 

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFNumbering.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFNumbering.java?rev=1875747&r1=1875746&r2=1875747&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFNumbering.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFNumbering.java Fri
Mar 27 03:13:40 2020
@@ -26,6 +26,7 @@ import java.math.BigInteger;
 
 import org.apache.poi.xwpf.XWPFTestDataSamples;
 import org.junit.Test;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTAbstractNum;
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTNum;
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTNumLvl;
 
@@ -61,6 +62,45 @@ public class TestXWPFNumbering {
         XWPFNum num = numbering.getNum(numId);
 
         BigInteger compareAbstractNum = num.getCTNum().getAbstractNumId().getVal();
+        assertEquals(abstractNumId, compareAbstractNum);
+    }
+
+    @Test
+    public void testAddAbstractNumIfAbstractNumNotEqualNull() throws IOException {
+        BigInteger abstractNumId = BigInteger.valueOf(1);
+        XWPFDocument docOut = new XWPFDocument();
+        XWPFNumbering numbering = docOut.createNumbering();
+
+        CTAbstractNum cTAbstractNum = CTAbstractNum.Factory.newInstance();
+        // must set the AbstractNumId, Otherwise fail
+        cTAbstractNum.setAbstractNumId(abstractNumId);
+        XWPFAbstractNum abstractNum = new XWPFAbstractNum(cTAbstractNum);
+        abstractNumId = numbering.addAbstractNum(abstractNum);
+        BigInteger numId = numbering.addNum(abstractNumId);
+
+        XWPFDocument docIn = XWPFTestDataSamples.writeOutAndReadBack(docOut);
+
+        numbering = docIn.getNumbering();
+        XWPFNum num = numbering.getNum(numId);
+        BigInteger compareAbstractNum = num.getCTNum().getAbstractNumId().getVal();
+        assertEquals(abstractNumId, compareAbstractNum);
+    }
+
+    @Test
+    public void testAddAbstractNumIfAbstractNumEqualNull() throws IOException {
+        XWPFDocument docOut = new XWPFDocument();
+        XWPFNumbering numbering = docOut.createNumbering();
+
+        XWPFAbstractNum abstractNum = new XWPFAbstractNum();
+        BigInteger abstractNumId = numbering.addAbstractNum(abstractNum);
+        BigInteger numId = numbering.addNum(abstractNumId);
+
+        XWPFDocument docIn = XWPFTestDataSamples.writeOutAndReadBack(docOut);
+
+        numbering = docIn.getNumbering();
+        XWPFNum num = numbering.getNum(numId);
+
+        BigInteger compareAbstractNum = num.getCTNum().getAbstractNumId().getVal();
         assertEquals(abstractNumId, compareAbstractNum);
     }
 



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


Mime
View raw message