]> source.dussan.org Git - poi.git/commitdiff
[github-156] add setKeepNext to XWPFParagraph. Thanks to Thibaut Cuvelier.
authorPJ Fanning <fanningpj@apache.org>
Tue, 16 Jul 2019 21:00:49 +0000 (21:00 +0000)
committerPJ Fanning <fanningpj@apache.org>
Tue, 16 Jul 2019 21:00:49 +0000 (21:00 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1863182 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java
src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFParagraph.java

index 6f4fb972a9b13c00536470f98a1387e6b488b27d..305626d9ce3d6463ccaeee36a376f0af2798cdd7 100644 (file)
@@ -402,6 +402,29 @@ public class XWPFParagraph implements IBodyElement, IRunBody, ISDTContents, Para
         }
         return null;
     }
+    
+    /**
+     * Indicates whether this paragraph should be kept on the same page as the next one.
+     *
+     * @since POI 4.1.1
+     */
+    public boolean isKeepNext() {
+        if (getCTP() != null && getCTP().getPPr() != null && getCTP().getPPr().isSetKeepNext()) {
+            return getCTP().getPPr().getKeepNext().getVal() == STOnOff.ON;
+        }
+        return false;
+    }
+    
+    /**
+     * Sets this paragraph to be kept on the same page as the next one or not. 
+     *
+     * @since POI 4.1.1
+     */
+    public void setKeepNext(boolean keepNext) {
+        CTOnOff state = CTOnOff.Factory.newInstance();
+        state.setVal(keepNext ? STOnOff.ON : STOnOff.OFF);
+        getCTP().getPPr().setKeepNext(state);
+    }
 
     /**
      * Returns the text of the paragraph, but not of any objects in the
index be2258bd56452a10ead073076463e93ce977237a..197bb231e1072428419eeafd71a39d5a93e903ca 100644 (file)
@@ -467,6 +467,12 @@ public final class TestXWPFParagraph {
             p.setPageBreak(false);
             assertFalse(p.isPageBreak());
 
+            assertFalse(p.isKeepNext());
+            p.setKeepNext(true);
+            assertTrue(p.isKeepNext());
+            p.setKeepNext(false);
+            assertFalse(p.isKeepNext());
+
             assertEquals(-1, p.getSpacingAfter());
             p.setSpacingAfter(12);
             assertEquals(12, p.getSpacingAfter());