diff --git a/src/main/java/writer2latex/xhtml/NoteConverter.java b/src/main/java/writer2latex/xhtml/NoteConverter.java index cbbbe48..39bbb05 100644 --- a/src/main/java/writer2latex/xhtml/NoteConverter.java +++ b/src/main/java/writer2latex/xhtml/NoteConverter.java @@ -93,10 +93,7 @@ class NoteConverter extends ConverterHelper { noteList = new ArrayList(); notes.put(section, noteList); } - noteList.add(onode); - System.out.println("add note to section " + section + " notelist size is " + noteList.size()); - } boolean hasNotes() { diff --git a/src/main/java/writer2latex/xhtml/PageSplitter.java b/src/main/java/writer2latex/xhtml/PageSplitter.java index e23e229..86df55e 100644 --- a/src/main/java/writer2latex/xhtml/PageSplitter.java +++ b/src/main/java/writer2latex/xhtml/PageSplitter.java @@ -50,10 +50,11 @@ public class PageSplitter { onode.insertBefore(childFirstPart, child); } } else if (nodeName.equals(TEXT_SECTION)) { - if (handleSection(childFirstPart, child)){ - onode.insertBefore(childFirstPart, child); - style = ofr.getSectionStyle(Misc.getAttribute(child, 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)){ //HACK containsSPB(childFirstPart); @@ -454,7 +455,10 @@ public class PageSplitter { } return dataMoved; } - private static boolean handleSection(Node sectionFirstPart, Node section) { + private static Node handleSection(Node section) { + setLastAttribute(section); + Node sectionFirstPart = section.cloneNode(false); + removeLastAttribute(sectionFirstPart); boolean dataMoved = false; // Node counter int i = 0; @@ -488,8 +492,9 @@ public class PageSplitter { dataMoved=true; } } else if (nodeName.equals(TEXT_SECTION)) { - if (handleSection(childFirstPart, child)){ - sectionFirstPart.appendChild(childFirstPart); + Node childSectionFirstPart = handleSection(child); + if (childSectionFirstPart != null){ + sectionFirstPart.appendChild(childSectionFirstPart); dataMoved=true; } } else if (nodeName.equals(TEXT_LIST)) { @@ -511,11 +516,23 @@ public class PageSplitter { } } - - return dataMoved; + if (dataMoved) { + return sectionFirstPart; + } + + return null; + } + private static void removeLastAttribute(Node section) { + Element sectionEl = (Element) section; + sectionEl.setAttribute("last", "false"); + } + private static void setLastAttribute(Node section) { + Element sectionEl = (Element) section; + sectionEl.setAttribute("last", "true"); + } private static Node handleParagraph(Node para) { //System.out.println("handlePara"); Node paraBefore = para.cloneNode(false); @@ -582,21 +599,17 @@ public class PageSplitter { NodeList childs = span.getChildNodes(); int i = 0; while (childs.getLength() > i) { - System.out.println("In WHILE HANDLE SPAN"); Node child = childs.item(i); if (child.getNodeType() == Node.ELEMENT_NODE) { if (containsSPB(child)) { if (child.getNodeName().equals(TEXT_NOTE)) { - System.out.println("handle TextNote in span"); splitSoftPageBreak(((Element)child).getElementsByTagName(TEXT_NOTE_BODY).item(0), officeReader); } else if (child.getNodeName().equals(TEXT_SPAN)){ handleSpan(child); } else { System.out.println("SPB INSIDE SPAN! HELP!"); - //Debug.printNode(child); } } - } i++; } diff --git a/src/main/java/writer2latex/xhtml/TextConverter.java b/src/main/java/writer2latex/xhtml/TextConverter.java index 0ff35ce..3bf6205 100644 --- a/src/main/java/writer2latex/xhtml/TextConverter.java +++ b/src/main/java/writer2latex/xhtml/TextConverter.java @@ -192,23 +192,6 @@ public class TextConverter extends ConverterHelper { bInToc = false; } - /*private Element exitPageContainer(Element hnode) { - System.out.println("exit page container"); - - String className = ((Element) hnode).getAttribute("class"); - if (!className.equals("pageContainer")) { - System.out.println("Can't exit not my container!"); - Debug.printNode(hnode); - for (StackTraceElement ste : Thread.currentThread().getStackTrace()) { - System.out.println(ste); - } - System.exit(1); - } - Element parentNode = (Element) hnode.getParentNode(); - System.out.println("parent node name " + parentNode.getNodeName()); - return parentNode; - } -*/ private void insertEndnotes(Element hnode, String section) { inEndnote = true; endCv.insertEndnotes(hnode,section); @@ -550,6 +533,9 @@ public class TextConverter extends ConverterHelper { // Unlike headings, paragraphs and spans, text:display is not attached to the style: String lastSection = currentSection; String sectionName = Misc.getAttribute(onode,TEXT_NAME); + String last = Misc.getAttribute(onode,"last"); + boolean isLast = false; + if (last != null && last.equals("true")) { isLast = true;} String savedStyle = docSep.getPageContainerStyle(); if (!bDisplayHiddenText && "none".equals(Misc.getAttribute(onode,TEXT_DISPLAY))) { return hnode; } @@ -559,8 +545,9 @@ public class TextConverter extends ConverterHelper { hnode = docSep.openPage(hnode, pageNum); hnode = traverseBlockText(onode, hnode); - System.out.println("sectionname " + sectionName); - insertEndnotes((Element) hnode, sectionName); + if (isLast) { + insertEndnotes((Element) hnode, sectionName); + } currentSection = lastSection; docSep.setPageContainerStyle(savedStyle); @@ -1795,17 +1782,6 @@ public class TextConverter extends ConverterHelper { return hnode; } - /*private Node enterPageContainer(Node hnode) { - System.out.println("enter page container " + hnode.getNodeName()); - if (hnode == null) { - System.out.println("hnode is null"); - } - Element container = converter.createElement("div"); - container.setAttribute("class", "pageContainer"); - hnode.appendChild(container); - return container; - }*/ - private void fitPageNumberToMasterPageStyle() { // TODO: READ master-page style @@ -1841,7 +1817,6 @@ public class TextConverter extends ConverterHelper { String sMasterPage = style.getMasterPageName(); if (sMasterPage != null && sMasterPage.length() > 0) { - // System.out.println("GETPAGEBREAK SUCCESS MASTERPAGE STYLE FOUND " + currentMasterPage); return true; } } @@ -1862,7 +1837,6 @@ public class TextConverter extends ConverterHelper { currentMasterPage = nextMasterPage; MasterPage masterPage = ofr.getFullMasterPage(currentMasterPage); nextMasterPage = masterPage.getProperty(STYLE_NEXT_STYLE_NAME); - // System.out.println("Next master page is " + nextMasterPage); } }