[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
This commit is contained in:
PJ Fanning 2019-07-16 21:00:49 +00:00
parent c7bcd70d54
commit 65c4aafe3e
2 changed files with 29 additions and 0 deletions

View 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

View 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());