From ce0a5d5df947163f1dd25035a2849a69fbb45c55 Mon Sep 17 00:00:00 2001 From: Georgy Litvinov Date: Fri, 24 Jul 2020 21:52:49 +0200 Subject: [PATCH] Fix for prev commit --- .../w2phtml/pageSplitters/ListSplitter.java | 53 ++++++++++--------- .../w2phtml/pageSplitters/SplitFactory.java | 1 - 2 files changed, 28 insertions(+), 26 deletions(-) diff --git a/src/main/java/w2phtml/pageSplitters/ListSplitter.java b/src/main/java/w2phtml/pageSplitters/ListSplitter.java index d401c50..446f5d2 100644 --- a/src/main/java/w2phtml/pageSplitters/ListSplitter.java +++ b/src/main/java/w2phtml/pageSplitters/ListSplitter.java @@ -10,6 +10,7 @@ import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; +import pro.litvinovg.xml.Debug; import w2phtml.office.OfficeReader; public class ListSplitter extends BasicSplitter implements ISplitter { @@ -30,36 +31,34 @@ public class ListSplitter extends BasicSplitter implements ISplitter { boolean dataMoved = false; while (listNodes.getLength() > i) { Node child = listNodes.item(i); - if(child.getNodeType() == Node.ELEMENT_NODE){ + if (child.getNodeType() == Node.ELEMENT_NODE) { String nodeName = child.getNodeName(); if (nodeName.equals(TEXT_LIST_HEADER)) { - if(containsSPB(child)){ - //Remove inner SPB - removeSPB(child); - //HACK :( - break; - } + if (containsSPB(child)) { + // Remove inner SPB + removeSPB(child); + // HACK :( + break; + } listFirstPart.appendChild(child.cloneNode(true)); - //Get next element + // Get next element i++; } else if (nodeName.equals(TEXT_LIST_ITEM)) { - if (containsSPB(child)){ - - //remove SPB, move previous nodes to firstPart. - if (factory.split(child)){ + if (containsSPB(child)) { + + // remove SPB, move previous nodes to firstPart. + if (factory.split(child)) { dataMoved = true; - //Add first part of list item to previous list item + // Add first part of list item to previous list item listFirstPart.appendChild(child.getPreviousSibling()); - if (child.hasChildNodes()){ + if (child.hasChildNodes()) { hangingItem = child; } else { list.removeChild(child); } - } - //Add text:continue-numbering="true" - if (dataMoved){ - ((Element) list).setAttribute(TEXT_CONTINUE_NUMBERING, "true"); - } + } + // Debug.printNode(child); + break; } else { // Not with SPB yet, move node, set dataMoved=true @@ -69,24 +68,28 @@ public class ListSplitter extends BasicSplitter implements ISplitter { } else { System.out.println("Error. SPB in List child node " + nodeName); System.exit(1); - } - } + } + } } if (dataMoved) { + ((Element) list).setAttribute(TEXT_CONTINUE_NUMBERING, "true"); parent.insertBefore(listFirstPart, list); parent.insertBefore(softPageBreak, list); if (hangingItem != null) { i = 0; NodeList freeNodes = hangingItem.getChildNodes(); - while (freeNodes.getLength() > 0 ) { + while (freeNodes.getLength() > 0) { Node freeNode = freeNodes.item(i); parent.insertBefore(freeNode, list); } list.removeChild(hangingItem); - } - + } + + } else { + //If SPB right before list items + parent.insertBefore(softPageBreak, list); } - + return dataMoved; } diff --git a/src/main/java/w2phtml/pageSplitters/SplitFactory.java b/src/main/java/w2phtml/pageSplitters/SplitFactory.java index dbcec07..08cfbb1 100644 --- a/src/main/java/w2phtml/pageSplitters/SplitFactory.java +++ b/src/main/java/w2phtml/pageSplitters/SplitFactory.java @@ -17,7 +17,6 @@ public class SplitFactory { System.exit(1); } String nodeName = node.getNodeName(); - System.out.println(nodeName); ISplitter splitter = null; if (nodeName.contentEquals(TEXT_SPAN)) { splitter = new SpanSplitter(officeReader, this);