From f7ac9d4aac801a50f07dfe77c36c3cc869db36f5 Mon Sep 17 00:00:00 2001 From: Georgy Litvinov Date: Sun, 21 Apr 2019 18:12:09 +0300 Subject: [PATCH] Refactoring --- .../writer2latex/xhtml/GreenstoneTags.java | 24 +++++++----- .../writer2latex/xhtml/TextConverter.java | 38 ++++++++----------- 2 files changed, 30 insertions(+), 32 deletions(-) diff --git a/src/main/java/writer2latex/xhtml/GreenstoneTags.java b/src/main/java/writer2latex/xhtml/GreenstoneTags.java index e0a8f9e..0a6fe9b 100644 --- a/src/main/java/writer2latex/xhtml/GreenstoneTags.java +++ b/src/main/java/writer2latex/xhtml/GreenstoneTags.java @@ -46,13 +46,16 @@ public class GreenstoneTags { } if (headingSeparation.equals(SECTIONS)){ - closeHeadingSections(hnode, nLevel); - - openHeadingComment(hnode, title); + closeCommentHeadings(hnode, nLevel); + } + //Place to split headings + + if (headingSeparation.equals(SECTIONS)){ + openCommentHeading(hnode, title); headerStack.offerFirst(Integer.parseInt(sLevel)); } if (!noPageSeparation() && !noHeadingSeparation()){ - hnode = openPage(hnode, pageNum); + hnode = openPage(hnode, pageNum); } return hnode; @@ -82,7 +85,7 @@ public class GreenstoneTags { } if(headingSeparation.equals(SECTIONS)){ //Create global section - openHeadingComment(hnode, title); + openCommentHeading(hnode, title); } hnode = openPage(hnode, pageNum); @@ -97,7 +100,7 @@ public class GreenstoneTags { hnode = closePage(hnode); } if (headingSeparation.equals(SECTIONS)){ - closeHeadingSections(hnode, 0); + closeCommentHeadings(hnode, 0); //Close global section addCloseComment(hnode); } @@ -107,10 +110,11 @@ public class GreenstoneTags { private static Node openPageDiv(Node node,int pageNum){ if (node == null){ + System.out.println("Error: node is null on openPageDiv"); return node; } Document doc = node.getOwnerDocument(); - Element openBlock = (Element) doc.createElement("div"); + Element openBlock = (Element) doc.createElement(DIV); openBlock.setAttribute("class", "pageNum"); openBlock.setAttribute("page", Integer.toString(pageNum)); // insert open section comment before header node @@ -121,7 +125,7 @@ public class GreenstoneTags { private static Node exitPageDiv(Node node){ - while ( !isRoot(node) && !isElement("div", node) ){ + while ( !isRoot(node) && !isElement(DIV, node) ){ node = node.getParentNode(); } Node result = node.getParentNode(); @@ -169,7 +173,7 @@ public class GreenstoneTags { hnode.appendChild(openSection); } - private static void openHeadingComment(Node hnode, String title){ + private static void openCommentHeading(Node hnode, String title){ Document doc = hnode.getOwnerDocument(); Node openSection = doc.createComment(openHeadingCommentText(title)); // insert open section comment before header node @@ -183,7 +187,7 @@ public class GreenstoneTags { node.appendChild(closeSection); } - private static void closeHeadingSections(Node hnode, int nLevel){ + private static void closeCommentHeadings(Node hnode, int nLevel){ if (headerStack.isEmpty()) { return; } diff --git a/src/main/java/writer2latex/xhtml/TextConverter.java b/src/main/java/writer2latex/xhtml/TextConverter.java index fd239f5..52c6bab 100644 --- a/src/main/java/writer2latex/xhtml/TextConverter.java +++ b/src/main/java/writer2latex/xhtml/TextConverter.java @@ -269,8 +269,8 @@ public class TextConverter extends ConverterHelper { } else if (nodeName.equals(XMLString.TEXT_P)) { StyleWithProperties style = ofr.getParStyle(Misc.getAttribute(child,XMLString.TEXT_STYLE_NAME)); - hnode = processPageBreaks(child, hnode,style); - hnode = maybeSplit(hnode, style); + hnode = processPageBreaks(child, hnode,style); + //hnode = maybeSplit(hnode, style); nCharacterCount+=OfficeReader.getCharacterCount(child); // is there a block element, we should use? XhtmlStyleMap xpar = config.getXParStyleMap(); @@ -412,11 +412,11 @@ public class TextConverter extends ConverterHelper { // TODO } else if (nodeName.equals(XMLString.TEXT_ALPHABETICAL_INDEX)) { - hnode = maybeSplit(hnode,null,1); + //hnode = maybeSplit(hnode,null,1); indexCv.handleIndex((Element)child,(Element)hnode); } else if (nodeName.equals(XMLString.TEXT_BIBLIOGRAPHY)) { - hnode = maybeSplit(hnode,null,1); + //hnode = maybeSplit(hnode,null,1); bibCv.handleIndex((Element)child,(Element)hnode); } else if (nodeName.equals(XMLString.TEXT_SOFT_PAGE_BREAK)) { @@ -1114,7 +1114,7 @@ public class TextConverter extends ConverterHelper { int nOutlineLevel = getOutlineLevel((Element)onode); Node rememberNode = hnode; StyleWithProperties style = ofr.getParStyle(Misc.getAttribute(child, XMLString.TEXT_STYLE_NAME)); - hnode = maybeSplit(hnode,style,nOutlineLevel); + //hnode = maybeSplit(hnode,style,nOutlineLevel); handleHeading((Element)child, (Element)hnode, rememberNode!=hnode, ofr.getListStyle(sStyleName), nLevel, bUnNumbered, bRestart, nStartValue); @@ -1668,21 +1668,10 @@ public class TextConverter extends ConverterHelper { //check for first para inside // Check it's master page, pageNumber, Page break before - if we already set MP - throw it away // And make a note to pass this paragraph next time you'll meet it. - if (inHeader) { - return hnode; - } - if (inFooter) { - return hnode; - } - if (inTable){ - return hnode; - } - if (inList){ - return hnode; - } - if (inFootnote){ + if (inHeader || inFooter || inTable || inList || inFootnote ) { return hnode; } + /* if (pageTags.equals("none")) { return hnode; }*/ @@ -1720,9 +1709,7 @@ public class TextConverter extends ConverterHelper { pageNum++; fitPageNumberToMasterPageStyle(); } - if (currentNode.getNodeType() == Node.ELEMENT_NODE - && Misc.getAttribute(currentNode, XMLString.TEXT_OUTLINE_LEVEL) != null - && !Misc.getAttribute(currentNode, XMLString.TEXT_OUTLINE_LEVEL).isEmpty()) { + if (hasOutlineLevel(currentNode)) { hnode = GreenstoneTags.processHeading(currentNode, hnode, pageNum); } else { hnode = GreenstoneTags.processPageBreak(currentNode, hnode, pageNum); @@ -1900,7 +1887,14 @@ public class TextConverter extends ConverterHelper { inFooter = false; return node; } - + private static boolean hasOutlineLevel(Node node) { + if (Misc.isElement(node) + && Misc.getAttribute(node, XMLString.TEXT_OUTLINE_LEVEL) != null + && !Misc.getAttribute(node, XMLString.TEXT_OUTLINE_LEVEL).isEmpty()) { + return true; + } + return false; + } }