diff --git a/src/main/java/w2phtml/xhtml/content/Separator.java b/src/main/java/w2phtml/xhtml/content/Separator.java index 9847daf..9f16b64 100644 --- a/src/main/java/w2phtml/xhtml/content/Separator.java +++ b/src/main/java/w2phtml/xhtml/content/Separator.java @@ -10,8 +10,9 @@ import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; -import pro.litvinovg.xml.Debug; import w2phtml.office.XMLString; +import pro.litvinovg.xml.Debug; +import static w2phtml.office.XMLString.*; import w2phtml.xhtml.Converter; import w2phtml.xhtml.XhtmlConfig; @@ -55,19 +56,25 @@ public class Separator { } public Node processOutlineLevel(Node currentNode, Node hnode, int pageNum) { - // Get outline level - String sLevel = getAttribute(currentNode, XMLString.TEXT_OUTLINE_LEVEL); - if (sLevel == null || sLevel.isEmpty()) { + Node outlineNode = null; + if (currentNode.getNodeName().contentEquals(TABLE_TABLE)) { + outlineNode = getOulineNodeFromTable(currentNode); + } else { + outlineNode = currentNode; + } + + Integer curLevel = getOutlineLevel(outlineNode); + if (curLevel < 1) { return hnode; } - String title = getTitle(currentNode); + + String title = getOutlineTitle(outlineNode); if (title == null || title.isEmpty()) { return hnode; } - int curLevel = Integer.parseInt(sLevel); - + if (noSplitNeeded(pageNum, curLevel)) { System.out.println("No split needed"); return hnode; @@ -97,7 +104,7 @@ public class Separator { } if (greenstoneSeparation) { openCommentHeading(hnode, title); - addToCommentStack(sLevel); + addToCommentStack(curLevel.toString()); } if (pagination) { @@ -107,6 +114,46 @@ public class Separator { return hnode; } + private int getOutlineLevel(Node currentNode) { + String levelAttr = getAttribute(currentNode, XMLString.TEXT_OUTLINE_LEVEL); + if (levelAttr == null || levelAttr.isEmpty()) { + return 0; + } else { + return Integer.parseInt(levelAttr); + } + } + + private Node getOulineNodeFromTable(Node currentNode) { + NodeList tableNodes = currentNode.getChildNodes(); + int i = 0; + while (i < tableNodes.getLength()) { + Node tableNode = tableNodes.item(i++); + if (tableNode.getNodeName().contentEquals(TABLE_TABLE_ROW)) { + NodeList rowNodes = tableNode.getChildNodes(); + int j = 0; + while (j < rowNodes.getLength()) { + Node rowNode = rowNodes.item(j++); + if (rowNode.getNodeName().contentEquals(TABLE_TABLE_CELL)) { + NodeList cellNodes = rowNode.getChildNodes(); + int k = 0; + while (k < cellNodes.getLength()) { + Node cellNode = cellNodes.item(k++); + String levelAttr = getAttribute(cellNode, XMLString.TEXT_OUTLINE_LEVEL); + if (levelAttr != null && !levelAttr.isEmpty()) { + String title = getOutlineTitle(cellNode); + if (!title.isEmpty()) { + return cellNode; + } + } + + } + } + } + } + } + return currentNode; + } + private void setContentName(Node hnode, String title) { ((Element) hnode).setAttribute("name", title); @@ -290,7 +337,7 @@ public class Separator { return result; } - public static String getTitle(Node currentNode) { + public static String getOutlineTitle(Node currentNode) { Node content = currentNode.cloneNode(true); String title = null; NodeList lineBreaks = ((Element) content).getElementsByTagName(XMLString.TEXT_LINE_BREAK); @@ -304,6 +351,8 @@ public class Separator { return title; } + + private static void deleteCommentsIn(Node content) { NodeList notes = ((Element) content).getElementsByTagName(XMLString.OFFICE_ANNOTATION); int j = 0; @@ -437,9 +486,22 @@ public class Separator { } } - private static String openPageCommentText(Integer pageNum) { - String comment = "
\n\n" + pageNum + "\n" + pageNum + "\n"+COMMENT_END; - return comment; + public Node breaksOrOutline(Node currentNode, Node hnode, int pageNum) { + Node outlineNode = null; + if (currentNode.getNodeName().contentEquals(TABLE_TABLE)) { + outlineNode = getOulineNodeFromTable(currentNode); + } else { + outlineNode = currentNode; + } + Integer curLevel = getOutlineLevel(outlineNode); + String title = getOutlineTitle(outlineNode); + + if (curLevel < 1 || title == null || title.isEmpty()) { + hnode = processPageBreak(currentNode, hnode, pageNum); + } else { + hnode = processOutlineLevel(currentNode, hnode, pageNum); + } + return hnode; } } diff --git a/src/main/java/w2phtml/xhtml/content/TextParser.java b/src/main/java/w2phtml/xhtml/content/TextParser.java index a7d12a4..5bc31b0 100644 --- a/src/main/java/w2phtml/xhtml/content/TextParser.java +++ b/src/main/java/w2phtml/xhtml/content/TextParser.java @@ -32,6 +32,7 @@ import java.util.Set; import org.w3c.dom.Node; import org.w3c.dom.NodeList; +import pro.litvinovg.xml.Debug; import w2phtml.office.FontDeclaration; import w2phtml.office.ListCounter; import w2phtml.office.ListStyle; @@ -166,6 +167,7 @@ public class TextParser extends Parser { if (pagination) { onode = (Element) ODFPageSplitter.splitText(onode,ofr); + //Debug.printNode(onode); } hnode = (Element)traverseBlockText(onode,hnode); @@ -1207,12 +1209,8 @@ public class TextParser extends Parser { pageNum++; fitPageNumberToMasterPageStyle(); } - if (hasOutlineLevel(currentNode)) { - hnode = docSep.processOutlineLevel(currentNode, hnode, pageNum); - } else { - hnode = docSep.processPageBreak(currentNode, hnode, pageNum); - - } + hnode = docSep.breaksOrOutline(currentNode, hnode, pageNum); + // Print new header addHeader(hnode); @@ -1433,18 +1431,7 @@ public class TextParser extends Parser { inFooter = false; return node; } - private boolean hasOutlineLevel(Node node) { - if (Misc.isElement(node) - && Misc.getAttribute(node, TEXT_OUTLINE_LEVEL) != null - && !Misc.getAttribute(node, TEXT_OUTLINE_LEVEL).isEmpty()) { - String title = Separator.getTitle(node).trim(); - if (title == null || title.isEmpty()) { - return false; - } - return true; - } - return false; - } + public void handleOfficeAnnotation(Node onode, Node hnode) { if (applyAnnotationMetadata) { parseAnnotationMetadata(onode);