diff --git a/source/java/writer2latex/xhtml/GreenstoneTags.java b/source/java/writer2latex/xhtml/GreenstoneTags.java index ca5445f..f0706f4 100644 --- a/source/java/writer2latex/xhtml/GreenstoneTags.java +++ b/source/java/writer2latex/xhtml/GreenstoneTags.java @@ -5,6 +5,7 @@ import java.util.LinkedList; import org.w3c.dom.Document; +import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; @@ -15,8 +16,13 @@ import writer2latex.util.Misc; //LinkedList stringList = new LinkedList(); public class GreenstoneTags { + private static final String NONE = "none"; + private static final String SECTIONS = "sections"; + private static final String DIV = "div"; + + private static LinkedList headerStack = new LinkedList(); - private static boolean pageSectionOpened = false; + private static boolean pageOpened = false; //headings none private static String headingTags = "headings"; //sections div none @@ -25,7 +31,7 @@ public class GreenstoneTags { protected static Node processHeading(Node currentNode, Node hnode, int pageNum) { - if (headingTags.equals("none")){ + if (headingTags.equals(NONE)){ return hnode; } @@ -33,10 +39,8 @@ public class GreenstoneTags { //If this heading contain outline-level if (sLevel != null && !sLevel.isEmpty()) { int nLevel = Integer.parseInt(sLevel); - // Close page section if opened - if (pageSectionOpened) { - closeSection(hnode); - pageSectionOpened = false; + if (pageOpened) { + hnode = closePage(hnode); } closeHeadingSections(hnode, nLevel); @@ -54,11 +58,8 @@ public class GreenstoneTags { && nextNode.getNodeName().equals(XMLString.TEXT_H) && Misc.getAttribute(nextNode, XMLString.TEXT_OUTLINE_LEVEL) != null && !Misc.getAttribute(nextNode, XMLString.TEXT_OUTLINE_LEVEL).isEmpty() - ) - && headingTags.equals("headings-pages") - ) { - //Open page section - openPageSection(hnode, pageNum); + )) { + hnode = openPage(hnode, pageNum); } } @@ -67,7 +68,7 @@ public class GreenstoneTags { } protected static Node processPageBreak(Node currentNode, Node hnode, Integer pageNum){ - if (headingTags.equals("none") || headingTags.equals("headings")){ + if (pageTags.equals(NONE)){ return hnode; } @@ -79,15 +80,10 @@ public class GreenstoneTags { && !headerStack.isEmpty() || pageTags.equals("sections") ) { - if (pageSectionOpened) { - closeSection(hnode); - pageSectionOpened = false; - - } - if (pageNum != null) { - openPageSection(hnode, pageNum); - + if (pageOpened) { + hnode = closePage(hnode); } + hnode = openPage(hnode, pageNum); } return hnode; } @@ -95,30 +91,48 @@ public class GreenstoneTags { protected static Node StartDocument(Node hnode, String title, String heading, String pages, int pageNum){ headingTags = heading; pageTags = pages; - if (headingTags.equals("none")){ + + if (headingTags.equals(NONE) && pageTags.equals(NONE)){ return hnode; } - //Create main document section - openSection(hnode, title); - if (pageTags.equals("sections")){ - //Open page section - openPageSection(hnode, pageNum); + if(headingTags.equals(SECTIONS)){ + //Create global section + openSection(hnode, title); } + hnode = openPage(hnode, pageNum); return hnode; } //Method to close open tags at the end of the document protected static Node endDocument(Node hnode){ - if (headingTags.equals("none")){ + if (headingTags.equals(NONE) && pageTags.equals(NONE)){ return hnode; } - if (pageSectionOpened){ - closeSection(hnode); - pageSectionOpened = false; + if (pageOpened){ + hnode = closePage(hnode); } - closeSection(hnode); - //Clean stack, close all sections - closeHeadingSections(hnode, 0); + if (headingTags.equals(SECTIONS)){ + closeHeadingSections(hnode, 0); + //Close global section + closeSection(hnode); + } + + return hnode; + } + + private static Node openPageDiv(Node hnode,int pageNum){ + Document doc = hnode.getOwnerDocument(); + Element openBlock = (Element) doc.createElement("div"); + openBlock.setAttribute("class", "pageNum"); + openBlock.setAttribute("page", Integer.toString(pageNum)); + // insert open section comment before header node + hnode.appendChild((Node)openBlock); + hnode = openBlock; + return openBlock; + } + + private static Node exitPageDiv(Node hnode){ + hnode = hnode.getParentNode(); return hnode; } @@ -155,7 +169,6 @@ public class GreenstoneTags { Node openSection = doc.createComment(commentText); // insert open section comment before header node hnode.appendChild(openSection); - pageSectionOpened = true; } private static void openSection(Node hnode, String title){ Document doc = hnode.getOwnerDocument(); @@ -185,9 +198,28 @@ public class GreenstoneTags { if (headerStack.isEmpty()) { break; } - } - } + private static Node closePage(Node hnode){ + if (pageTags.equals(SECTIONS)){ + closeSection(hnode); + } + else if (pageTags.equals(DIV)){ + hnode = exitPageDiv(hnode); + } + pageOpened = false; + return hnode; + } + private static Node openPage(Node hnode, Integer pageNum){ + if (pageTags.equals(SECTIONS)){ + openPageSection(hnode, pageNum); + } + else if (pageTags.equals(DIV)){ + hnode = openPageDiv(hnode, pageNum); + } + pageOpened = true; + return hnode; + } + } \ No newline at end of file diff --git a/source/java/writer2latex/xhtml/XhtmlConfig.java b/source/java/writer2latex/xhtml/XhtmlConfig.java index 5b8ec84..e91855f 100644 --- a/source/java/writer2latex/xhtml/XhtmlConfig.java +++ b/source/java/writer2latex/xhtml/XhtmlConfig.java @@ -294,7 +294,7 @@ public class XhtmlConfig extends writer2latex.base.ConfigBase { options[DIRECTORY_ICON] = new Option("directory_icon",""); options[DOCUMENT_ICON] = new Option("document_icon",""); options[HEADING_TAGS] = new Option("heading_tags","sections"); - options[PAGE_TAGS] = new Option("page_tags","sections"); + options[PAGE_TAGS] = new Option("page_tags","div"); } protected void readInner(Element elm) {