poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject svn commit: r1492312 - in /poi/trunk/src/ooxml: java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java testcases/org/apache/poi/xwpf/usermodel/TestXWPFNumbering.java
Date Wed, 12 Jun 2013 18:04:16 GMT
Author: nick
Date: Wed Jun 12 18:04:16 2013
New Revision: 1492312

URL: http://svn.apache.org/r1492312
Log:
Patch from akhikhl from github pull #4 - Expose from XWPFParagraph the number level and format,
if applied

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

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java?rev=1492312&r1=1492311&r2=1492312&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java Wed Jun 12 18:04:16
2013
@@ -25,11 +25,13 @@ import org.apache.poi.POIXMLDocumentPart
 import org.apache.poi.util.Internal;
 import org.apache.xmlbeans.XmlCursor;
 import org.apache.xmlbeans.XmlObject;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTAbstractNum;
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBorder;
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTFtnEdnRef;
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTHyperlink;
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTInd;
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTJc;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTLvl;
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTOnOff;
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP;
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPBdr;
@@ -217,6 +219,50 @@ public class XWPFParagraph implements IB
     }
     
     /**
+     * Returns Ilvl of the numeric style for this paragraph.
+     * Returns null if this paragraph does not have numeric style.
+     * @return Ilvl as BigInteger
+     */
+    public BigInteger getNumIlvl() {
+        if(paragraph.getPPr()!=null){
+            if(paragraph.getPPr().getNumPr()!=null){
+                if(paragraph.getPPr().getNumPr().getIlvl()!=null)
+                    return paragraph.getPPr().getNumPr().getIlvl().getVal();
+            }
+        }
+        return null;
+    }
+
+    /**
+     * Returns numbering format for this paragraph, eg bullet or
+     *  lowerLetter.
+     * Returns null if this paragraph does not have numeric style.
+     */
+    public String getNumFmt() {
+        BigInteger numID = getNumID();
+        XWPFNumbering numbering = document.getNumbering();
+        if(numID != null && numbering != null) {
+            XWPFNum num = numbering.getNum(numID);
+            if(num != null) {
+                BigInteger ilvl = getNumIlvl();
+                BigInteger abstractNumId = num.getCTNum().getAbstractNumId().getVal();
+                CTAbstractNum anum = numbering.getAbstractNum(abstractNumId).getAbstractNum();
+                CTLvl level = null;
+                for(int i = 0; i < anum.sizeOfLvlArray(); i++) {
+                    CTLvl lvl = anum.getLvlArray(i);
+                    if(lvl.getIlvl().equals(ilvl)) {
+                        level = lvl;
+                        break;
+                    }
+                }
+                if(level != null)
+                    return level.getNumFmt().getVal().toString();
+            }
+        }
+        return null;
+    }
+    
+    /**
      * setNumID of Paragraph
      * @param numPos
      */
@@ -1300,4 +1346,4 @@ public class XWPFParagraph implements IB
         return null;
     }
 
-}//end class
\ No newline at end of file
+}

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=1492312&r1=1492311&r2=1492312&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 Wed
Jun 12 18:04:16 2013
@@ -56,4 +56,22 @@ public class TestXWPFNumbering extends T
 		assertEquals(abstractNumId, compareAbstractNum);
 	}
 
+	public void testGetNumIlvl() throws IOException{
+		XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("Numbering.docx");
+		BigInteger numIlvl = BigInteger.valueOf(0);
+		assertEquals(numIlvl, doc.getParagraphs().get(0).getNumIlvl());
+		numIlvl = BigInteger.valueOf(1);
+      assertEquals(numIlvl, doc.getParagraphs().get(5).getNumIlvl());
+	}
+
+	public void testGetNumFmt() throws IOException{
+		XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("Numbering.docx");
+		assertEquals("bullet", doc.getParagraphs().get(0).getNumFmt());
+		assertEquals("bullet", doc.getParagraphs().get(1).getNumFmt());
+		assertEquals("bullet", doc.getParagraphs().get(2).getNumFmt());
+		assertEquals("bullet", doc.getParagraphs().get(3).getNumFmt());
+		assertEquals("decimal", doc.getParagraphs().get(4).getNumFmt());
+		assertEquals("lowerLetter", doc.getParagraphs().get(5).getNumFmt());
+		assertEquals("lowerRoman", doc.getParagraphs().get(6).getNumFmt());
+  }
 }



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


Mime
View raw message