You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ta...@apache.org on 2015/04/28 17:17:51 UTC

svn commit: r1676561 - in /poi/trunk/src/scratchpad: src/org/apache/poi/hwpf/model/ListLevel.java testcases/org/apache/poi/hwpf/usermodel/TestLists.java

Author: tallison
Date: Tue Apr 28 15:17:51 2015
New Revision: 1676561

URL: http://svn.apache.org/r1676561
Log:
POI-56998 add some getters to help with list numbering in hwpf

Modified:
    poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/ListLevel.java
    poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestLists.java

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/ListLevel.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/ListLevel.java?rev=1676561&r1=1676560&r2=1676561&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/ListLevel.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/model/ListLevel.java Tue Apr 28 15:17:51 2015
@@ -174,6 +174,41 @@ public final class ListLevel
         return _lvlf.getIxchFollow();
     }
 
+    /**
+     * An unsigned integer that specifies the first (most-significant) zero-based level after which the number sequence of this level does not restart. The number sequence of this level does restart after any level that is more significant than the specified level. This MUST be less than or equal to the zero-based level of the list to which this LVLF corresponds.
+     * <p>see [MS-DOC], v20140721, 2.9.150</p>
+     * 
+     * @return the first ({@code 0} is the most significant) level after which
+     * the numbering does not restart or {@code -1} if no restart is applicable
+     */
+    public short getRestart() {    	
+    	return _lvlf.isFNoRestart() ? _lvlf.getIlvlRestartLim() : -1;
+    }
+    
+    /**
+     * Determines if the number formatting shall be overridden by
+     * {@code msonfcArabic}; unless it originally was {@code msonfcArabicLZ}
+     * in which case it is preserved.
+     * <p>see [MS-DOC], v20140721, 2.9.150 and [MS-OSHARED], v20140721, 2.2.1.3</p>
+     * 
+     * @return {@code true} if the level numbering of this and all more
+     * significant levels must be overridden; {@code false} otherwise
+     */
+    public boolean isLegalNumbering() {
+    	return _lvlf.isFLegal();
+    }
+    
+    /**
+     * Array which specifies the character offsets of the level numbers in a
+     * level numbering string.
+     * <p>see [MS-DOC], v20140721, 2.9.150</p>
+     * 
+     * @return {@code 0}-terminated array, unless it is full 
+     */
+    public byte[] getLevelNumberingPlaceholderOffsets() {    	
+    	return _lvlf.getRgbxchNums();
+    }
+
     int read( final byte[] data, final int startOffset )
     {
         int offset = startOffset;

Modified: poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestLists.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestLists.java?rev=1676561&r1=1676560&r2=1676561&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestLists.java (original)
+++ poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/usermodel/TestLists.java Tue Apr 28 15:17:51 2015
@@ -23,6 +23,7 @@ import junit.framework.TestCase;
 
 import org.apache.poi.hwpf.HWPFDocument;
 import org.apache.poi.hwpf.HWPFTestDataSamples;
+import org.apache.poi.hwpf.model.ListLevel;
 
 /**
  * Tests for our handling of lists
@@ -207,4 +208,47 @@ public final class TestLists extends Tes
       assertEquals(1, r.getParagraph(22).getIlvl());
       assertEquals(0, r.getParagraph(23).getIlvl());
    }
+
+   public void testSpecificNumberedOrderedListFeatures() throws IOException {
+      HWPFDocument doc = HWPFTestDataSamples.openSampleFile("Lists.doc");
+
+      Range r = doc.getRange();
+      //these are in the numbered ordered list
+      //26 = OL 2
+      //27 = OL 2.1
+      //28 = OL 2.2
+      //29 = OL 2.2.1
+      for (int i = 26; i < 30; i++) {
+         Paragraph p = r.getParagraph(i);
+         assertTrue(p.isInList());
+         HWPFList list = p.getList();
+         ListLevel level = list.getLVL((char) p.getIlvl());
+         assertFalse(level.isLegalNumbering());
+         assertEquals(-1, level.getRestart());
+      }
+      Paragraph p = r.getParagraph(26);
+      HWPFList list = p.getList();
+      ListLevel level = list.getLVL((char) p.getIlvl());
+      byte[] lvl = level.getLevelNumberingPlaceholderOffsets();
+
+      assertEquals((byte)1, lvl[0]);
+      assertEquals((byte)0, lvl[1]);
+
+      p = r.getParagraph(27);
+      list = p.getList();
+      level = list.getLVL((char) p.getIlvl());
+      lvl = level.getLevelNumberingPlaceholderOffsets();
+      assertEquals((byte)1, lvl[0]);
+      assertEquals((byte)3, lvl[1]);
+
+      p = r.getParagraph(29);
+      list = p.getList();
+      level = list.getLVL((char) p.getIlvl());
+      lvl = level.getLevelNumberingPlaceholderOffsets();
+
+      assertEquals((byte)1, lvl[0]);
+      assertEquals((byte)3, lvl[1]);
+      assertEquals((byte)5, lvl[2]);
+   }
+
 }



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