You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ce...@apache.org on 2020/01/01 19:22:31 UTC
svn commit: r1872187 - in /poi/trunk/src/ooxml:
java/org/apache/poi/xwpf/usermodel/XWPFNumbering.java
testcases/org/apache/poi/xwpf/usermodel/TestXWPFBugs.java
Author: centic
Date: Wed Jan 1 19:22:30 2020
New Revision: 1872187
URL: http://svn.apache.org/viewvc?rev=1872187&view=rev
Log:
Bug 63788: Remove AbstractNum by abstractNumId, not list index
Modified:
poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFNumbering.java
poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFBugs.java
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=1872187&r1=1872186&r2=1872187&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 Wed Jan 1 19:22:30 2020
@@ -49,14 +49,14 @@ public class XWPFNumbering extends POIXM
/**
* create a new styles object with an existing document
- *
+ *
* @since POI 3.14-Beta1
*/
public XWPFNumbering(PackagePart part) throws IOException, OpenXML4JException {
super(part);
isNew = true;
}
-
+
/**
* create a new XWPFNumbering object for use in a new document
*/
@@ -254,11 +254,15 @@ public class XWPFNumbering extends POIXM
* false if abstractNum with abstractNumID not exists
*/
public boolean removeAbstractNum(BigInteger abstractNumID) {
- if (abstractNumID.byteValue() < abstractNums.size()) {
- ctNumbering.removeAbstractNum(abstractNumID.byteValue());
- abstractNums.remove(abstractNumID.byteValue());
- return true;
+ for (XWPFAbstractNum abstractNum : abstractNums) {
+ BigInteger foundNumId = abstractNum.getAbstractNum().getAbstractNumId();
+ if(abstractNumID.equals(foundNumId)) {
+ ctNumbering.removeAbstractNum(foundNumId.byteValue());
+ abstractNums.remove(abstractNum);
+ return true;
+ }
}
+
return false;
}
Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFBugs.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFBugs.java?rev=1872187&r1=1872186&r2=1872187&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFBugs.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFBugs.java Wed Jan 1 19:22:30 2020
@@ -17,16 +17,21 @@
package org.apache.poi.xwpf.usermodel;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
+import java.math.BigInteger;
import org.apache.poi.util.Units;
import org.apache.poi.xwpf.XWPFTestDataSamples;
import org.apache.poi.xwpf.usermodel.XWPFRun.FontCharRange;
import org.junit.Test;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTAbstractNum;
public class TestXWPFBugs {
@Test
@@ -111,7 +116,7 @@ public class TestXWPFBugs {
assertEquals(p, same);
}
}
-
+
@Test
public void bug57495_convertPixelsToEMUs() {
int pixels = 100;
@@ -142,7 +147,7 @@ public class TestXWPFBugs {
}
}
}
-
+
/**
* Removing a run needs to take into account position of run if paragraph contains hyperlink runs
*/
@@ -174,4 +179,53 @@ public class TestXWPFBugs {
docBack.close();
}
}
+
+ @Test
+ public void test63788() throws IOException {
+ try (XWPFDocument doc = new XWPFDocument()) {
+
+ XWPFNumbering numbering = doc.createNumbering();
+
+ for (int i = 10; i >= 0; i--) {
+ addNumberingWithAbstractId(numbering, i); //add numbers in reverse order
+ }
+
+ for (int i = 0; i <= 10; i++) {
+ assertEquals(i, numbering.getAbstractNum(BigInteger.valueOf(i)).getAbstractNum().getAbstractNumId().longValue());
+ }
+
+ //attempt to remove item with numId 2
+ assertTrue(numbering.removeAbstractNum(BigInteger.valueOf(2)));
+
+ for (int i = 0; i <= 10; i++) {
+ XWPFAbstractNum abstractNum = numbering.getAbstractNum(BigInteger.valueOf(i));
+
+ // we removed id "2", so this one should be empty, all others not
+ if (i == 2) {
+ assertNull("Failed for " + i, abstractNum);
+ } else {
+ assertNotNull("Failed for " + i, abstractNum);
+ assertEquals(i, abstractNum.getAbstractNum().getAbstractNumId().longValue());
+ }
+ }
+
+ // removing the same again fails
+ assertFalse(numbering.removeAbstractNum(BigInteger.valueOf(2)));
+
+ // removing another one works
+ assertTrue(numbering.removeAbstractNum(BigInteger.valueOf(4)));
+ }
+ }
+
+ private static void addNumberingWithAbstractId(XWPFNumbering documentNumbering, int id){
+ // create a numbering scheme
+ CTAbstractNum cTAbstractNum = CTAbstractNum.Factory.newInstance();
+ // give the scheme an ID
+ cTAbstractNum.setAbstractNumId(BigInteger.valueOf(id));
+
+ XWPFAbstractNum abstractNum = new XWPFAbstractNum(cTAbstractNum);
+ BigInteger abstractNumID = documentNumbering.addAbstractNum(abstractNum);
+
+ documentNumbering.addNum(abstractNumID);
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org