From 65c4aafe3eab8ddb886d965f59ae6c135dd3d782 Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Tue, 16 Jul 2019 21:00:49 +0000 Subject: [PATCH] [github-156] add setKeepNext to XWPFParagraph. Thanks to Thibaut Cuvelier. git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1863182 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/xwpf/usermodel/XWPFParagraph.java | 23 +++++++++++++++++++ .../poi/xwpf/usermodel/TestXWPFParagraph.java | 6 +++++ 2 files changed, 29 insertions(+) diff --git a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java index 6f4fb972a9..305626d9ce 100644 --- a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java +++ b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java @@ -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 diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFParagraph.java b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFParagraph.java index be2258bd56..197bb231e1 100644 --- a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFParagraph.java +++ b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFParagraph.java @@ -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()); -- 2.39.5