From 4c6cc14c952eb3288d0fff268f5be39c13041de9 Mon Sep 17 00:00:00 2001 From: Georgy Litvinov Date: Mon, 3 Oct 2016 12:43:29 +0300 Subject: [PATCH] Added Real TOC extraction --- .../writer2latex/xhtml/TextConverter.java | 35 ++++++++++++++++++- .../java/writer2latex/xhtml/XhtmlConfig.java | 2 +- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/source/java/writer2latex/xhtml/TextConverter.java b/source/java/writer2latex/xhtml/TextConverter.java index a427e30..24d7b5a 100644 --- a/source/java/writer2latex/xhtml/TextConverter.java +++ b/source/java/writer2latex/xhtml/TextConverter.java @@ -29,6 +29,9 @@ import java.util.Hashtable; import java.util.Stack; import org.w3c.dom.Node; import org.w3c.dom.NodeList; +import org.w3c.dom.ls.DOMImplementationLS; +import org.w3c.dom.ls.LSSerializer; +import org.w3c.dom.Document; import org.w3c.dom.Element; import writer2latex.util.Misc; @@ -144,6 +147,11 @@ public class TextConverter extends ConverterHelper { // Add cover image hnode = getDrawCv().insertCoverImage(hnode); + //Extract table:index-body content from TOC + if (!config.includeToc()){ + extractRealTOC(onode); + } + //Split pages onode = (Element) PageSplitter.splitSoftPageBreak(onode,ofr); // Convert content @@ -167,7 +175,32 @@ public class TextConverter extends ConverterHelper { bInToc = false; } - protected int getTocIndex() { return tocCv.getFileIndex(); } + private void extractRealTOC(Element onode) { + NodeList tocs = onode.getElementsByTagName(XMLString.TEXT_TABLE_OF_CONTENT); + int i = 0; + if (tocs == null){ + return; + } + System.out.println("extractRealTOC"); + while (i < tocs.getLength()){ + Node toc = tocs.item(i); + NodeList indexTitle = onode.getElementsByTagName(XMLString.TEXT_INDEX_TITLE); + if (indexTitle == null || indexTitle.item(0) == null){ + i++; + continue; + } + while (indexTitle.item(0).hasChildNodes()){ + Node child = indexTitle.item(0).getFirstChild(); + //Move childnodes before text:table-of-content + System.out.println("insertBefore"); + toc.getParentNode().insertBefore(child, toc); + } + i++; + } + return; + } + + protected int getTocIndex() { return tocCv.getFileIndex(); } protected int getAlphabeticalIndex() { return indexCv.getFileIndex(); } diff --git a/source/java/writer2latex/xhtml/XhtmlConfig.java b/source/java/writer2latex/xhtml/XhtmlConfig.java index e91855f..8c0dbe7 100644 --- a/source/java/writer2latex/xhtml/XhtmlConfig.java +++ b/source/java/writer2latex/xhtml/XhtmlConfig.java @@ -248,7 +248,7 @@ public class XhtmlConfig extends writer2latex.base.ConfigBase { } } }; - options[INCLUDE_TOC] = new BooleanOption("include_toc","true"); + options[INCLUDE_TOC] = new BooleanOption("include_toc","false"); options[INCLUDE_NCX] = new BooleanOption("include_ncx","true"); options[SPLIT_LEVEL] = new IntegerOption("split_level","0") { @Override public void setString(String sValue) {