Refactoring breaks
This commit is contained in:
parent
0680742212
commit
187f3d1eb4
2 changed files with 41 additions and 40 deletions
|
@ -240,18 +240,6 @@ public class Separator {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Node processPageBreak(Node currentNode, Node hnode, Integer pageNum) {
|
|
||||||
if (!needPagination()) {
|
|
||||||
return hnode;
|
|
||||||
}
|
|
||||||
if (pageOpened) {
|
|
||||||
hnode = closePage(hnode);
|
|
||||||
}
|
|
||||||
hnode = openPage(hnode, pageNum);
|
|
||||||
|
|
||||||
return hnode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isPageOpened() {
|
public boolean isPageOpened() {
|
||||||
return pageOpened;
|
return pageOpened;
|
||||||
}
|
}
|
||||||
|
@ -469,7 +457,7 @@ public class Separator {
|
||||||
private Node exitPageContainer(Node hnode) {
|
private Node exitPageContainer(Node hnode) {
|
||||||
String className = ((Element) hnode).getAttribute("class");
|
String className = ((Element) hnode).getAttribute("class");
|
||||||
if (!className.equals("pageContainer")) {
|
if (!className.equals("pageContainer")) {
|
||||||
System.out.println("Can't exit not my container!");
|
logger.error("Can't exit not my container!");
|
||||||
Debug.printNode(hnode);
|
Debug.printNode(hnode);
|
||||||
Debug.printStackTrace();
|
Debug.printStackTrace();
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
|
@ -519,12 +507,17 @@ public class Separator {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Node breaksOrOutline(Node currentNode, Node hnode, int pageNum) {
|
public Node breaksOrOutline(Node currentNode, Node hnode, int pageNum) {
|
||||||
Node outlineNode = getRealOntlineNode(currentNode);
|
|
||||||
Integer curLevel = getOutlineLevel(outlineNode);
|
|
||||||
String title = getOutlineTitle(outlineNode);
|
|
||||||
|
|
||||||
if (curLevel < 1 || title == null || title.isEmpty()) {
|
if (isBadOutlineNode(currentNode)) {
|
||||||
hnode = processPageBreak(currentNode, hnode, pageNum);
|
if (!needPagination()) {
|
||||||
|
return hnode;
|
||||||
|
}
|
||||||
|
if (pageOpened) {
|
||||||
|
hnode = closePage(hnode);
|
||||||
|
}
|
||||||
|
hnode = openPage(hnode, pageNum);
|
||||||
|
|
||||||
|
return hnode;
|
||||||
} else {
|
} else {
|
||||||
hnode = whatToDoWithOutlineNodeOnPage(currentNode, hnode, pageNum);
|
hnode = whatToDoWithOutlineNodeOnPage(currentNode, hnode, pageNum);
|
||||||
}
|
}
|
||||||
|
|
|
@ -110,7 +110,7 @@ public class TextParser extends Parser {
|
||||||
private String nextMasterPage = null;
|
private String nextMasterPage = null;
|
||||||
|
|
||||||
private boolean pagination = config.pagination();
|
private boolean pagination = config.pagination();
|
||||||
private boolean breakBeforeNextNode = false;
|
private boolean breakPageBeforeNextNode = false;
|
||||||
private boolean inTable = false;
|
private boolean inTable = false;
|
||||||
private boolean inList = false;
|
private boolean inList = false;
|
||||||
private boolean inFootnote = false;
|
private boolean inFootnote = false;
|
||||||
|
@ -121,7 +121,7 @@ public class TextParser extends Parser {
|
||||||
private String footnotesContext = null;
|
private String footnotesContext = null;
|
||||||
PageContainer pageContainer = null;
|
PageContainer pageContainer = null;
|
||||||
private boolean applyAnnotationMetadata;
|
private boolean applyAnnotationMetadata;
|
||||||
private boolean breakBeforeSectionHappened = false;
|
private boolean breakBeforeSectionInProcessFlag = false;
|
||||||
private StyleWithProperties lastSectionStyle;
|
private StyleWithProperties lastSectionStyle;
|
||||||
|
|
||||||
public TextParser(OfficeReader ofr, XhtmlConfig config, Converter converter) {
|
public TextParser(OfficeReader ofr, XhtmlConfig config, Converter converter) {
|
||||||
|
@ -263,7 +263,7 @@ public class TextParser extends Parser {
|
||||||
int nLen = nList.getLength();
|
int nLen = nList.getLength();
|
||||||
int i = 0;
|
int i = 0;
|
||||||
//hard Break after marker
|
//hard Break after marker
|
||||||
breakBeforeNextNode = false;
|
breakPageBeforeNextNode = false;
|
||||||
while (i < nLen) {
|
while (i < nLen) {
|
||||||
Node child = nList.item(i);
|
Node child = nList.item(i);
|
||||||
if (child.getNodeType() == Node.ELEMENT_NODE) {
|
if (child.getNodeType() == Node.ELEMENT_NODE) {
|
||||||
|
@ -273,7 +273,7 @@ public class TextParser extends Parser {
|
||||||
}
|
}
|
||||||
else if (nodeName.equals(TEXT_P)) {
|
else if (nodeName.equals(TEXT_P)) {
|
||||||
StyleWithProperties style = ofr.getParStyle(Misc.getAttribute(child,TEXT_STYLE_NAME));
|
StyleWithProperties style = ofr.getParStyle(Misc.getAttribute(child,TEXT_STYLE_NAME));
|
||||||
hnode = processPageBreaks(child, hnode,style);
|
hnode = processBreaks(child, hnode,style);
|
||||||
// is there a block element, we should use?
|
// is there a block element, we should use?
|
||||||
XhtmlStyleMap xpar = config.getXParStyleMap();
|
XhtmlStyleMap xpar = config.getXParStyleMap();
|
||||||
String sDisplayName = style!=null ? style.getDisplayName() : null;
|
String sDisplayName = style!=null ? style.getDisplayName() : null;
|
||||||
|
@ -319,7 +319,7 @@ public class TextParser extends Parser {
|
||||||
else if(nodeName.equals(TEXT_H)) {
|
else if(nodeName.equals(TEXT_H)) {
|
||||||
StyleWithProperties style = ofr.getParStyle(Misc.getAttribute(child,TEXT_STYLE_NAME));
|
StyleWithProperties style = ofr.getParStyle(Misc.getAttribute(child,TEXT_STYLE_NAME));
|
||||||
Node rememberNode = hnode;
|
Node rememberNode = hnode;
|
||||||
hnode = processPageBreaks(child, hnode, style);
|
hnode = processBreaks(child, hnode, style);
|
||||||
handleHeading((Element)child,(Element)hnode,rememberNode!=hnode);
|
handleHeading((Element)child,(Element)hnode,rememberNode!=hnode);
|
||||||
}
|
}
|
||||||
else if (nodeName.equals(TEXT_LIST) || // oasis
|
else if (nodeName.equals(TEXT_LIST) || // oasis
|
||||||
|
@ -327,7 +327,7 @@ public class TextParser extends Parser {
|
||||||
nodeName.equals(TEXT_ORDERED_LIST)) // old
|
nodeName.equals(TEXT_ORDERED_LIST)) // old
|
||||||
{
|
{
|
||||||
StyleWithProperties style = getFirstStylePageInfo(child);
|
StyleWithProperties style = getFirstStylePageInfo(child);
|
||||||
hnode = processPageBreaks(child, hnode,style);
|
hnode = processBreaks(child, hnode,style);
|
||||||
inList = true;
|
inList = true;
|
||||||
if (getListParser().listIsOnlyHeadings(child)) {
|
if (getListParser().listIsOnlyHeadings(child)) {
|
||||||
hnode = getListParser().handleFakeList(child,nLevel+1,styleName,hnode);
|
hnode = getListParser().handleFakeList(child,nLevel+1,styleName,hnode);
|
||||||
|
@ -339,7 +339,7 @@ public class TextParser extends Parser {
|
||||||
}
|
}
|
||||||
else if (nodeName.equals(TABLE_TABLE)) {
|
else if (nodeName.equals(TABLE_TABLE)) {
|
||||||
StyleWithProperties style = ofr.getTableStyle(Misc.getAttribute(child, TABLE_STYLE_NAME));
|
StyleWithProperties style = ofr.getTableStyle(Misc.getAttribute(child, TABLE_STYLE_NAME));
|
||||||
hnode = processPageBreaks(child, hnode,style);
|
hnode = processBreaks(child, hnode,style);
|
||||||
inTable = true;
|
inTable = true;
|
||||||
getTableParser().handleTable(child,hnode);
|
getTableParser().handleTable(child,hnode);
|
||||||
inTable = false;
|
inTable = false;
|
||||||
|
@ -349,7 +349,7 @@ public class TextParser extends Parser {
|
||||||
}
|
}
|
||||||
else if (nodeName.equals(TEXT_SECTION)) {
|
else if (nodeName.equals(TEXT_SECTION)) {
|
||||||
StyleWithProperties style = getFirstStylePageInfo(child);
|
StyleWithProperties style = getFirstStylePageInfo(child);
|
||||||
hnode = processPageBreaks(child, hnode,style);
|
hnode = processBreaks(child, hnode,style);
|
||||||
hnode = handleSection(child,hnode);
|
hnode = handleSection(child,hnode);
|
||||||
//Debug.prettyPrintXml(hnode.getOwnerDocument());
|
//Debug.prettyPrintXml(hnode.getOwnerDocument());
|
||||||
}
|
}
|
||||||
|
@ -377,7 +377,7 @@ public class TextParser extends Parser {
|
||||||
bibCv.handleIndex((Element)child,(Element)hnode);
|
bibCv.handleIndex((Element)child,(Element)hnode);
|
||||||
}
|
}
|
||||||
else if (nodeName.equals(TEXT_SOFT_PAGE_BREAK)) {
|
else if (nodeName.equals(TEXT_SOFT_PAGE_BREAK)) {
|
||||||
breakBeforeNextNode = true;
|
breakPageBeforeNextNode = true;
|
||||||
}
|
}
|
||||||
else if (nodeName.equals(OFFICE_ANNOTATION)) {
|
else if (nodeName.equals(OFFICE_ANNOTATION)) {
|
||||||
handleOfficeAnnotation(child,hnode);
|
handleOfficeAnnotation(child,hnode);
|
||||||
|
@ -1191,7 +1191,7 @@ public class TextParser extends Parser {
|
||||||
Misc.getPosInteger(node.getAttribute(TEXT_OUTLINE_LEVEL),0):
|
Misc.getPosInteger(node.getAttribute(TEXT_OUTLINE_LEVEL),0):
|
||||||
Misc.getPosInteger(node.getAttribute(TEXT_LEVEL),0);
|
Misc.getPosInteger(node.getAttribute(TEXT_LEVEL),0);
|
||||||
}
|
}
|
||||||
private Node processPageBreaks(Node currentNode, Node hnode, StyleWithProperties style){
|
private Node processBreaks(Node currentNode, Node hnode, StyleWithProperties style){
|
||||||
//Check for paragraph in current node in case currentNode is table
|
//Check for paragraph in current node in case currentNode is table
|
||||||
// If currentNode is table
|
// If currentNode is table
|
||||||
//check for first para inside
|
//check for first para inside
|
||||||
|
@ -1212,20 +1212,20 @@ public class TextParser extends Parser {
|
||||||
//Document wasn't started yet.
|
//Document wasn't started yet.
|
||||||
hnode = startDocument(hnode, style, newPageNumber);
|
hnode = startDocument(hnode, style, newPageNumber);
|
||||||
hnode = docSep.whatToDoWithOutlineNodeOnPage(currentNode, hnode, pageNum);
|
hnode = docSep.whatToDoWithOutlineNodeOnPage(currentNode, hnode, pageNum);
|
||||||
} else if (hasMasterPage(style) || hasBreakBefore(style) || breakBeforeNextNode) {
|
} else if (isPageBreakFound(style)) {
|
||||||
if (hasBreakBefore(style)) {
|
if (hasBreakBefore(style)) {
|
||||||
|
|
||||||
if (currentNode.getNodeName() == TEXT_SECTION) {
|
if (currentNode.getNodeName() == TEXT_SECTION) {
|
||||||
if (breakBeforeSectionHappened) {
|
if (breakBeforeSectionInProcessFlag) {
|
||||||
//skip one more section;
|
//skip one more section;
|
||||||
return hnode;
|
return hnode;
|
||||||
} else {
|
} else {
|
||||||
breakBeforeSectionHappened = true;
|
breakBeforeSectionInProcessFlag = true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
//assume in inner element, break happened, skip break.
|
//assume in inner element, break happened, skip break.
|
||||||
if (breakBeforeSectionHappened) {
|
if (breakBeforeSectionInProcessFlag) {
|
||||||
breakBeforeSectionHappened = false;
|
breakBeforeSectionInProcessFlag = false;
|
||||||
return hnode;
|
return hnode;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1238,15 +1238,23 @@ public class TextParser extends Parser {
|
||||||
hnode = docSep.whatToDoWithOutlineNodeOnPage(currentNode, hnode, pageNum);
|
hnode = docSep.whatToDoWithOutlineNodeOnPage(currentNode, hnode, pageNum);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (checkHardBreakAfter(style)) {
|
setBreakPageBeforeNextNode(style);
|
||||||
breakBeforeNextNode = true;
|
|
||||||
} else {
|
|
||||||
breakBeforeNextNode = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return hnode;
|
return hnode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setBreakPageBeforeNextNode(StyleWithProperties style) {
|
||||||
|
if (isNewHardPageBreakAfter(style)) {
|
||||||
|
breakPageBeforeNextNode = true;
|
||||||
|
} else {
|
||||||
|
breakPageBeforeNextNode = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isPageBreakFound(StyleWithProperties style) {
|
||||||
|
return hasMasterPage(style) || hasBreakBefore(style) || breakPageBeforeNextNode;
|
||||||
|
}
|
||||||
|
|
||||||
private boolean wasProcessedWithSection(Node currentNode, StyleWithProperties style) {
|
private boolean wasProcessedWithSection(Node currentNode, StyleWithProperties style) {
|
||||||
if (!currentNode.getNodeName().equals(TEXT_SECTION)) {
|
if (!currentNode.getNodeName().equals(TEXT_SECTION)) {
|
||||||
if (lastSectionStyle != null && lastSectionStyle == style) {
|
if (lastSectionStyle != null && lastSectionStyle == style) {
|
||||||
|
@ -1286,7 +1294,7 @@ public class TextParser extends Parser {
|
||||||
// Print new header
|
// Print new header
|
||||||
addHeader(hnode);
|
addHeader(hnode);
|
||||||
//hnode = enterPageContainer(hnode);
|
//hnode = enterPageContainer(hnode);
|
||||||
breakBeforeNextNode = false;
|
breakPageBeforeNextNode = false;
|
||||||
return hnode;
|
return hnode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1417,7 +1425,7 @@ public class TextParser extends Parser {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean checkHardBreakAfter(StyleWithProperties style) {
|
private boolean isNewHardPageBreakAfter(StyleWithProperties style) {
|
||||||
if (style != null && "page".equals(style.getProperty(FO_BREAK_AFTER))) {
|
if (style != null && "page".equals(style.getProperty(FO_BREAK_AFTER))) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue