diff --git a/src/main/java/w2phtml/xhtml/ODFPageSplitter.java b/src/main/java/w2phtml/xhtml/ODFPageSplitter.java index cf06cae..9485036 100644 --- a/src/main/java/w2phtml/xhtml/ODFPageSplitter.java +++ b/src/main/java/w2phtml/xhtml/ODFPageSplitter.java @@ -48,27 +48,18 @@ public class ODFPageSplitter { style = ofr.getTableStyle(Misc.getAttribute(child, TABLE_STYLE_NAME)); } } else if (nodeName.equals(TEXT_LIST)) { - if (handleList(childFirstPart, child)){ - onode.insertBefore(childFirstPart, child); - } - - } else if (nodeName.equals(TEXT_ALPHABETICAL_INDEX)) { - Node indexFirstPart = splitABIndex(child); - if (indexFirstPart != null) { - onode.insertBefore(indexFirstPart, child); - } + handleList(child); } else if (nodeName.equals(TEXT_ILLUSTRATION_INDEX)) { - Node indexFirstPart = splitTextIllustrationIndex(child); - if (indexFirstPart != null) { - onode.insertBefore(indexFirstPart, child); - } - }else if (nodeName.equals(TEXT_SECTION)) { + splitTextIllustrationIndex(child); + } else if (nodeName.equals(TEXT_ALPHABETICAL_INDEX)) { + splitABIndex(child); + } else if (nodeName.equals(TEXT_SECTION)) { Node sectionFirstPart = handleSection(child); if (sectionFirstPart != null) { onode.insertBefore(sectionFirstPart, child); style = ofr.getSectionStyle(Misc.getAttribute(child, TEXT_SECTION)); } - } else if (nodeName.equals(TEXT_TABLE_OF_CONTENT)){ + } else if (nodeName.equals(TEXT_TABLE_OF_CONTENT)){ //HACK containsSPB(childFirstPart); i++; @@ -78,7 +69,6 @@ public class ODFPageSplitter { i++; continue; } else { - System.out.println("In ODFPageSplitter unknown node found. Error, exiting."); Debug.printNode(child); System.exit(1); @@ -107,25 +97,8 @@ public class ODFPageSplitter { //Debug.printNode(onode); return onode; } - private static Node splitTextIllustrationIndex(Node illustrationIndex) { - Node illustrationIndexFirstPart = illustrationIndex.cloneNode(false); - NodeList childs = illustrationIndex.getChildNodes(); - int i = 0; - while (childs.getLength() > i) { - Node child = childs.item(i); - String childName = child.getNodeName(); - if (childName.equals(TEXT_ILLUSTRATION_INDEX_SOURCE)) { - illustrationIndexFirstPart.appendChild(child.cloneNode(true)); - } else - if (childName.equals(TEXT_INDEX_BODY)) { - Node indexBodyFirstPart = splitTextIndexBody(child); - illustrationIndexFirstPart.appendChild(indexBodyFirstPart); - } - i++; - } - return illustrationIndexFirstPart; - } - private static Node splitABIndex(Node abIndex) { + private static void splitABIndex(Node abIndex) { + Node parent = abIndex.getParentNode(); Node abIndexFirstPart = abIndex.cloneNode(false); NodeList childs = abIndex.getChildNodes(); int i = 0; @@ -141,8 +114,33 @@ public class ODFPageSplitter { } i++; } - return abIndexFirstPart; + if (abIndexFirstPart != null) { + parent.insertBefore(abIndexFirstPart, abIndex); + } } + + private static void splitTextIllustrationIndex(Node illustrationIndex) { + Node parent = illustrationIndex.getParentNode(); + Node illustrationIndexFirstPart = illustrationIndex.cloneNode(false); + NodeList childs = illustrationIndex.getChildNodes(); + int i = 0; + while (childs.getLength() > i) { + Node child = childs.item(i); + String childName = child.getNodeName(); + if (childName.equals(TEXT_ILLUSTRATION_INDEX_SOURCE)) { + illustrationIndexFirstPart.appendChild(child.cloneNode(true)); + } else + if (childName.equals(TEXT_INDEX_BODY)) { + Node indexBodyFirstPart = splitTextIndexBody(child); + illustrationIndexFirstPart.appendChild(indexBodyFirstPart); + } + i++; + } + if (illustrationIndexFirstPart != null) { + parent.insertBefore(illustrationIndexFirstPart, illustrationIndex); + } + } + private static Node splitTextIndexBody(Node indexBody) { Node indexBodyFirstPart = indexBody.cloneNode(false); NodeList childs = indexBody.getChildNodes(); @@ -168,8 +166,9 @@ public class ODFPageSplitter { } return indexBodyFirstPart; } - private static boolean handleList(Node listFirstPart, Node list){ - + private static boolean handleList(Node list){ + Node parent = list.getParentNode(); + Node listFirstPart = list.cloneNode(false); NodeList listNodes = list.getChildNodes(); int i = 0; boolean dataMoved = false; @@ -225,6 +224,10 @@ public class ODFPageSplitter { } } } + if (dataMoved) { + parent.insertBefore(listFirstPart, list); + } + return dataMoved; } //If SPB before first item - return false, remove SPB @@ -245,8 +248,7 @@ public class ODFPageSplitter { //Remove SPB.Return result listItem.removeChild(listItemChild); } else if (nodeName.equals(TEXT_LIST)) { - if (handleList(listItemChildFirstPart, listItemChild)){ - listItemFirstPart.appendChild(listItemChildFirstPart); + if (handleList(listItemChild)){ dataMoved=true; } @@ -520,11 +522,10 @@ public class ODFPageSplitter { dataMoved=true; } } else if (nodeName.equals(TEXT_LIST)) { - Node listFirstPart = cellChildNode.cloneNode(false); - if (handleList(listFirstPart, cellChildNode)){ - cellFirstPart.appendChild(listFirstPart); - dataMoved=true; - } + Node listFirstPart = cellChildNode.cloneNode(false); + if (handleList(cellChildNode)){ + dataMoved=true; + } } break; } else { @@ -583,8 +584,7 @@ public class ODFPageSplitter { dataMoved=true; } } else if (nodeName.equals(TEXT_LIST)) { - if (handleList(childFirstPart, child)){ - sectionFirstPart.appendChild(childFirstPart); + if (handleList(child)){ dataMoved=true; } }