Fix for prev commit

This commit is contained in:
Georgy Litvinov 2020-07-24 21:52:49 +02:00
parent 759d3302e7
commit ce0a5d5df9
2 changed files with 28 additions and 26 deletions

View file

@ -10,6 +10,7 @@ import org.w3c.dom.Element;
import org.w3c.dom.Node; import org.w3c.dom.Node;
import org.w3c.dom.NodeList; import org.w3c.dom.NodeList;
import pro.litvinovg.xml.Debug;
import w2phtml.office.OfficeReader; import w2phtml.office.OfficeReader;
public class ListSplitter extends BasicSplitter implements ISplitter { public class ListSplitter extends BasicSplitter implements ISplitter {
@ -30,36 +31,34 @@ public class ListSplitter extends BasicSplitter implements ISplitter {
boolean dataMoved = false; boolean dataMoved = false;
while (listNodes.getLength() > i) { while (listNodes.getLength() > i) {
Node child = listNodes.item(i); Node child = listNodes.item(i);
if(child.getNodeType() == Node.ELEMENT_NODE){ if (child.getNodeType() == Node.ELEMENT_NODE) {
String nodeName = child.getNodeName(); String nodeName = child.getNodeName();
if (nodeName.equals(TEXT_LIST_HEADER)) { if (nodeName.equals(TEXT_LIST_HEADER)) {
if(containsSPB(child)){ if (containsSPB(child)) {
//Remove inner SPB // Remove inner SPB
removeSPB(child); removeSPB(child);
//HACK :( // HACK :(
break; break;
} }
listFirstPart.appendChild(child.cloneNode(true)); listFirstPart.appendChild(child.cloneNode(true));
//Get next element // Get next element
i++; i++;
} else if (nodeName.equals(TEXT_LIST_ITEM)) { } else if (nodeName.equals(TEXT_LIST_ITEM)) {
if (containsSPB(child)){ if (containsSPB(child)) {
//remove SPB, move previous nodes to firstPart. // remove SPB, move previous nodes to firstPart.
if (factory.split(child)){ if (factory.split(child)) {
dataMoved = true; 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()); listFirstPart.appendChild(child.getPreviousSibling());
if (child.hasChildNodes()){ if (child.hasChildNodes()) {
hangingItem = child; hangingItem = child;
} else { } else {
list.removeChild(child); list.removeChild(child);
} }
} }
//Add text:continue-numbering="true" // Debug.printNode(child);
if (dataMoved){
((Element) list).setAttribute(TEXT_CONTINUE_NUMBERING, "true");
}
break; break;
} else { } else {
// Not with SPB yet, move node, set dataMoved=true // Not with SPB yet, move node, set dataMoved=true
@ -69,24 +68,28 @@ public class ListSplitter extends BasicSplitter implements ISplitter {
} else { } else {
System.out.println("Error. SPB in List child node " + nodeName); System.out.println("Error. SPB in List child node " + nodeName);
System.exit(1); System.exit(1);
} }
} }
} }
if (dataMoved) { if (dataMoved) {
((Element) list).setAttribute(TEXT_CONTINUE_NUMBERING, "true");
parent.insertBefore(listFirstPart, list); parent.insertBefore(listFirstPart, list);
parent.insertBefore(softPageBreak, list); parent.insertBefore(softPageBreak, list);
if (hangingItem != null) { if (hangingItem != null) {
i = 0; i = 0;
NodeList freeNodes = hangingItem.getChildNodes(); NodeList freeNodes = hangingItem.getChildNodes();
while (freeNodes.getLength() > 0 ) { while (freeNodes.getLength() > 0) {
Node freeNode = freeNodes.item(i); Node freeNode = freeNodes.item(i);
parent.insertBefore(freeNode, list); parent.insertBefore(freeNode, list);
} }
list.removeChild(hangingItem); list.removeChild(hangingItem);
} }
} else {
//If SPB right before list items
parent.insertBefore(softPageBreak, list);
} }
return dataMoved; return dataMoved;
} }

View file

@ -17,7 +17,6 @@ public class SplitFactory {
System.exit(1); System.exit(1);
} }
String nodeName = node.getNodeName(); String nodeName = node.getNodeName();
System.out.println(nodeName);
ISplitter splitter = null; ISplitter splitter = null;
if (nodeName.contentEquals(TEXT_SPAN)) { if (nodeName.contentEquals(TEXT_SPAN)) {
splitter = new SpanSplitter(officeReader, this); splitter = new SpanSplitter(officeReader, this);