private void handlePageBreak(Paragraph origParagraph, String pos,
boolean continued) {
if (continued
&& this.textSelection.getTextNavigation().isHandlePageBreak())
return;
ParagraphProperties orgParaPty = origParagraph.getStyleHandler()
.getParagraphPropertiesForRead();
boolean handleBreak = false;
String posInPara = "middle";
if (continued && pos.equals("whole")) {
posInPara = "end";
} else if (continued && pos.endsWith("head")) {
posInPara = "middle";
} else if (continued && pos.endsWith("end")) {
posInPara = "end";
} else if (!continued && pos.endsWith("whole")) {
posInPara = "whole";
} else if (!continued && pos.endsWith("head")) {
posInPara = "head";
} else if (!continued && pos.endsWith("end")) {
posInPara = "end";
}
if (orgParaPty != null) {
String breakAttribute = orgParaPty.getBreakBefore();
if (breakAttribute != null) {
if (posInPara.equals("head") || posInPara.equals("whole")) {
getParagraphPropertiesForWrite().setBreak("before",
breakAttribute);
handleBreak = true;
}
}
breakAttribute = orgParaPty.getBreakAfter();
if (breakAttribute != null) {
if (posInPara.equals("end") || posInPara.equals("whole")) {
getParagraphPropertiesForWrite().setBreak("after",
breakAttribute);
handleBreak = true;
}
}
}
String masterStyle = origParagraph
.getStyleHandler()
.getStyleElementForRead()
.getOdfAttributeValue(
OdfName.newName(OdfDocumentNamespace.STYLE,
"master-page-name"));
if (masterStyle != null && !masterStyle.isEmpty()) {
if (posInPara.equals("head") || posInPara.equals("whole")) {
getParagraphStyleElementForWrite().setOdfAttributeValue(
OdfName.newName(OdfDocumentNamespace.STYLE,
"master-page-name"), masterStyle);
handleBreak = true;
try {
int pageNumber = orgParaPty.getPageNumber();
if (pos.equals("head")) {
paragraphContainer.getStyleHandler()
.getParagraphPropertiesForWrite()
.setPageNumber(pageNumber);
}