diff --git a/source/java/writer2latex/xhtml/PageSplitter.java b/source/java/writer2latex/xhtml/PageSplitter.java index 3012fc4..147f55b 100644 --- a/source/java/writer2latex/xhtml/PageSplitter.java +++ b/source/java/writer2latex/xhtml/PageSplitter.java @@ -27,7 +27,7 @@ public class PageSplitter { Node child = nodes.item(i); //Necessary check if node is an Element - if ((child.getNodeType() == Node.ELEMENT_NODE) && checkSoftPageBreak(child, false)){ + if ((child.getNodeType() == Node.ELEMENT_NODE) && containsSPB(child)){ String nodeName = child.getNodeName(); //DEBUG //System.out.println("----------CURRENT NODE IS-------" + nodeName); @@ -58,7 +58,7 @@ public class PageSplitter { } } else if (nodeName.equals(XMLString.TEXT_TABLE_OF_CONTENT)){ //HACK - checkSoftPageBreak(childFirstPart, false); + containsSPB(childFirstPart); i++; continue; } else if (nodeName.equals(XMLString.TEXT_SOFT_PAGE_BREAK)){ @@ -100,8 +100,9 @@ public class PageSplitter { if(listChild.getNodeType() == Node.ELEMENT_NODE){ String nodeName = listChild.getNodeName(); if (nodeName.equals(XMLString.TEXT_LIST_HEADER)) { - if(checkSoftPageBreak(listChild, true)){ + if(containsSPB(listChild)){ //Remove inner SPB + removeSPB(listChild); //HACK :( break; } @@ -111,7 +112,7 @@ public class PageSplitter { } else if (nodeName.equals(XMLString.TEXT_LIST_ITEM)) { - if (checkSoftPageBreak(listChild, false)){ + if (containsSPB(listChild)){ Node listItemFirstPart = listChild.cloneNode(false); //remove SPB, move previous nodes to firstPart. if (handleListItem(listItemFirstPart,listChild)){ @@ -159,7 +160,7 @@ public class PageSplitter { if(listItemChild.getNodeType() == Node.ELEMENT_NODE){ //Node name String nodeName = listItemChild.getNodeName(); - if (checkSoftPageBreak(listItemChild, false)){ + if (containsSPB(listItemChild)){ Node listItemChildFirstPart = listItemChild.cloneNode(false); //Break if SPB if (nodeName.equals(XMLString.TEXT_SOFT_PAGE_BREAK)) { @@ -221,7 +222,7 @@ public class PageSplitter { //Node name String tableChildNodeName = tableChildNode.getNodeName(); //System.out.println("Table child node " + tableChildNodeName); - if (checkSoftPageBreak(tableChildNode, false)){ + if (containsSPB(tableChildNode)){ Node tableChildFirstPart = tableChildNode.cloneNode(false); if (tableChildNodeName.equals(XMLString.TEXT_SOFT_PAGE_BREAK)) { // remove inner soft page break node @@ -247,7 +248,7 @@ public class PageSplitter { || tableChildNodeName.equals(XMLString.TABLE_TABLE_HEADER_ROWS) || tableChildNodeName.equals(XMLString.TABLE_TABLE_HEADER_COLUMNS)) { //Remove Soft Page Break - checkSoftPageBreak(tableChildNode, true); + removeSPB(tableChildNode); } break; @@ -284,7 +285,7 @@ public class PageSplitter { String nodeName = tableRowGroupChildNode.getNodeName(); - if (checkSoftPageBreak(tableRowGroupChildNode, false)){ + if (containsSPB(tableRowGroupChildNode)){ Node tableRowGroupChildFirstPart = tableRowGroupChildNode.cloneNode(false); if (nodeName.equals(XMLString.TEXT_SOFT_PAGE_BREAK)){ // remove inner soft page break node @@ -342,7 +343,7 @@ public class PageSplitter { String nodeName = tableRowsChildNode.getNodeName(); - if (checkSoftPageBreak(tableRowsChildNode, false)){ + if (containsSPB(tableRowsChildNode)){ Node tableRowGroupChildFirstPart = tableRowsChildNode.cloneNode(false); if (nodeName.equals(XMLString.TEXT_SOFT_PAGE_BREAK)){ // remove inner soft page break node @@ -380,7 +381,7 @@ public class PageSplitter { String nodeName = tableRowChildNode.getNodeName(); - if (checkSoftPageBreak(tableRowChildNode, false)){ + if (containsSPB(tableRowChildNode)){ Node tableRowGroupChildFirstPart = tableRowChildNode.cloneNode(false); if (nodeName.equals(XMLString.TABLE_TABLE_CELL)){ if (handleCell(tableRowGroupChildFirstPart, tableRowChildNode)){ @@ -429,7 +430,7 @@ public class PageSplitter { Node cellChildNode = cellChildNodes.item(0); if ((cellChildNode.getNodeType() == Node.ELEMENT_NODE)) { String nodeName = cellChildNode.getNodeName(); - if (checkSoftPageBreak(cellChildNode, false)){ + if (containsSPB(cellChildNode)){ Node cellChildFirstPart = cellChildNode.cloneNode(false); if (nodeName.equals(XMLString.TEXT_SOFT_PAGE_BREAK)){ // remove inner soft page break node @@ -465,7 +466,7 @@ public class PageSplitter { Node sectionChildNode = sectionChildNodes.item(0); if ((sectionChildNode.getNodeType() == Node.ELEMENT_NODE)) { String nodeName = sectionChildNode.getNodeName(); - if (checkSoftPageBreak(sectionChildNode, false)){ + if (containsSPB(sectionChildNode)){ Node sectionChildFirstPart = sectionChildNode.cloneNode(false); if (nodeName.equals(XMLString.TEXT_SOFT_PAGE_BREAK)){ // remove inner soft page break node @@ -480,7 +481,7 @@ public class PageSplitter { } else if (nodeName.equals(XMLString.TEXT_TABLE_OF_CONTENT)) { //HACK - checkSoftPageBreak(sectionNode, true); + removeSPB(sectionNode); i++; continue; } @@ -511,7 +512,7 @@ public class PageSplitter { String nodeName = paraChildNode.getNodeName(); //System.out.println(nodeName); //SPB FOUND - if (checkSoftPageBreak(paraChildNode, false)){ + if (containsSPB(paraChildNode)){ if (nodeName.equals(XMLString.TEXT_SOFT_PAGE_BREAK)){ @@ -564,11 +565,6 @@ public class PageSplitter { * Check if last node in paraFirstPart is text and last char is a letter * If both true - add */ - - - - - } else { System.out.println("ERROR: SPB INSIDE Paragraph Element in inner element " + nodeName); //checkSoftPageBreak(internalNode, true); @@ -594,13 +590,27 @@ public class PageSplitter { return dataMoved; } // Returns true if soft-page-break found. Removes it if removeFound = true - private static boolean checkSoftPageBreak(Node node, boolean removeFound) { + private static void removeSPB(Node node) { if (node.getNodeType() == Node.ELEMENT_NODE) { if (node.getNodeName().equals(XMLString.TEXT_SOFT_PAGE_BREAK)) { - if (removeFound) { - Node parent = node.getParentNode(); - parent.removeChild(node); + Node parent = node.getParentNode(); + parent.removeChild(node); + return; + } + if (node.hasChildNodes()) { + int currentNo = 0; + NodeList childNodes = node.getChildNodes(); + while (currentNo < childNodes.getLength()) { + Node childNode = childNodes.item(currentNo); + removeSPB(childNode); + currentNo++; } + } + } + } + private static boolean containsSPB(Node node) { + if (node.getNodeType() == Node.ELEMENT_NODE) { + if (node.getNodeName().equals(XMLString.TEXT_SOFT_PAGE_BREAK)) { return true; } if (node.hasChildNodes()) { @@ -608,7 +618,7 @@ public class PageSplitter { NodeList childNodes = node.getChildNodes(); while (currentNo < childNodes.getLength()) { Node childNode = childNodes.item(currentNo); - if (checkSoftPageBreak(childNode, removeFound)) { + if (containsSPB(childNode)) { return true; } currentNo++;