diff --git a/src/main/java/writer2latex/xhtml/Debug.java b/src/main/java/pro/litvinovg/xml/Debug.java similarity index 72% rename from src/main/java/writer2latex/xhtml/Debug.java rename to src/main/java/pro/litvinovg/xml/Debug.java index 67bdd02..856725f 100644 --- a/src/main/java/writer2latex/xhtml/Debug.java +++ b/src/main/java/pro/litvinovg/xml/Debug.java @@ -1,4 +1,4 @@ -package writer2latex.xhtml; +package pro.litvinovg.xml; import org.w3c.dom.Document; @@ -9,15 +9,16 @@ import org.w3c.dom.ls.LSSerializer; public class Debug { public static void printNode(Node node){ - - Document document = node.getOwnerDocument(); DOMImplementationLS domImplLS = (DOMImplementationLS) document .getImplementation(); LSSerializer serializer = domImplLS.createLSSerializer(); String str = serializer.writeToString(node); System.out.println(str); - - + } + public static void printStackTrace() { + for (StackTraceElement ste : Thread.currentThread().getStackTrace()) { + System.out.println(ste); + } } } diff --git a/src/main/java/writer2latex/office/MasterPage.java b/src/main/java/writer2latex/office/MasterPage.java index 81aeaee..6d98986 100644 --- a/src/main/java/writer2latex/office/MasterPage.java +++ b/src/main/java/writer2latex/office/MasterPage.java @@ -26,8 +26,9 @@ package writer2latex.office; import org.w3c.dom.Node; + +import pro.litvinovg.xml.Debug; import writer2latex.util.Misc; -import writer2latex.xhtml.Debug; /**

Class representing a master page in OOo Writer

*/ public class MasterPage extends OfficeStyle { diff --git a/src/main/java/writer2latex/office/StyleWithProperties.java b/src/main/java/writer2latex/office/StyleWithProperties.java index 4e64364..aa8280f 100644 --- a/src/main/java/writer2latex/office/StyleWithProperties.java +++ b/src/main/java/writer2latex/office/StyleWithProperties.java @@ -26,11 +26,12 @@ package writer2latex.office; //import org.w3c.dom.Element; import org.w3c.dom.Node; + +import pro.litvinovg.xml.Debug; import writer2latex.util.Calc; //import org.w3c.dom.NamedNodeMap; //import java.util.Hashtable; import writer2latex.util.Misc; -import writer2latex.xhtml.Debug; /**

Class representing a style in OOo which contains a style:properties * element

diff --git a/src/main/java/writer2latex/xhtml/Converter.java b/src/main/java/writer2latex/xhtml/Converter.java index c3d2730..5c1efd1 100644 --- a/src/main/java/writer2latex/xhtml/Converter.java +++ b/src/main/java/writer2latex/xhtml/Converter.java @@ -58,6 +58,7 @@ import writer2latex.util.ExportNameCollection; import writer2latex.util.Misc; import writer2latex.xhtml.content.DrawParser; import writer2latex.xhtml.content.MathParser; +import writer2latex.xhtml.content.PageContainer; import writer2latex.xhtml.content.TableParser; import writer2latex.xhtml.content.TextParser; import writer2latex.xhtml.l10n.L10n; @@ -104,6 +105,7 @@ public class Converter extends BasicConverter { private XhtmlDocument htmlDoc; // current outfile private Document htmlDOM; // current DOM, usually within htmlDoc private boolean bNeedHeaderFooter = false; + public PageContainer pageContainer = null; //private int nTocFileIndex = -1; //private int nAlphabeticalIndex = -1; @@ -122,6 +124,8 @@ public class Converter extends BasicConverter { super(); config = new XhtmlConfig(); this.nType = nType; + pageContainer = new PageContainer(); + } // override methods to read templates, style sheets and resources diff --git a/src/main/java/writer2latex/xhtml/content/PageContainer.java b/src/main/java/writer2latex/xhtml/content/PageContainer.java new file mode 100644 index 0000000..33c8ffe --- /dev/null +++ b/src/main/java/writer2latex/xhtml/content/PageContainer.java @@ -0,0 +1,34 @@ +package writer2latex.xhtml.content; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import pro.litvinovg.xml.Debug; + +public class PageContainer { + + private List pageContanerStyles = null; + public PageContainer() { + pageContanerStyles = new ArrayList(Arrays.asList("")); + } + + public void setRootStyle(String style){ + pageContanerStyles.set(0, style); + } + public void addStyle(String style){ + pageContanerStyles.add(style); + } + public void removeStyle() { + int size = pageContanerStyles.size(); + if (size < 2) { + System.out.println("Tried to remove last container (page) style!"); + Debug.printStackTrace(); + System.exit(1); + } + pageContanerStyles.remove(size-1); + } + public String getCurrentStyle() { + return pageContanerStyles.get(pageContanerStyles.size()-1); + } +} diff --git a/src/main/java/writer2latex/xhtml/Separator.java b/src/main/java/writer2latex/xhtml/content/Separator.java similarity index 90% rename from src/main/java/writer2latex/xhtml/Separator.java rename to src/main/java/writer2latex/xhtml/content/Separator.java index 5febf3f..fced3af 100644 --- a/src/main/java/writer2latex/xhtml/Separator.java +++ b/src/main/java/writer2latex/xhtml/content/Separator.java @@ -1,16 +1,17 @@ -package writer2latex.xhtml; +package writer2latex.xhtml.content; -import java.util.ArrayList; -import java.util.Arrays; import java.util.LinkedList; -import java.util.List; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; +import pro.litvinovg.xml.Debug; import writer2latex.office.XMLString; +import writer2latex.xhtml.Converter; +import writer2latex.xhtml.XhtmlConfig; + import static writer2latex.util.Misc.*; @@ -35,7 +36,7 @@ public class Separator { private static Converter converter = null; private XhtmlConfig config = null; private Node prevPageNode = null; - private List pageContanerStyles = new ArrayList(Arrays.asList("")); + private PageContainer pageContainer = null; public Separator(XhtmlConfig config,Converter converter) { this.config = config; @@ -45,6 +46,7 @@ public class Separator { splitLevel = config.getXhtmlSplitLevel(); splitByPages = pageSeparation.equals(DIV) ? true : false; breakStyle = config.getPageBreakStyle(); + pageContainer = converter.pageContainer; } public Node processOutlineLevel(Node currentNode, Node hnode, int pageNum) { @@ -335,9 +337,7 @@ public class Separator { 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); - } + Debug.printStackTrace(); System.exit(1); } Element parentNode = (Element) hnode.getParentNode(); @@ -346,15 +346,13 @@ public class Separator { private Node enterPageContainer(Node hnode) { if (hnode == null) { System.out.println("Enter page container error. hnode is null"); - for (StackTraceElement ste : Thread.currentThread().getStackTrace()) { - System.out.println(ste); - } + Debug.printStackTrace(); System.exit(1); } Element container = converter.createElement("div"); container.setAttribute("class", "pageContainer"); - if (!getLastPageContainerStyle().isEmpty()) { - container.setAttribute("style", getLastPageContainerStyle()); + if (!pageContainer.getCurrentStyle().isEmpty()) { + container.setAttribute("style", pageContainer.getCurrentStyle()); } hnode.appendChild(container); return container; @@ -377,23 +375,7 @@ public class Separator { return comment; } - public void setPageContainerStyle(String style){ - pageContanerStyles.set(0, style); - } - public void addPageContainerStyle(String style){ - pageContanerStyles.add(style); - } - public void rmPageContainerStyle() { - int size = pageContanerStyles.size(); - if (size < 2) { - System.out.println("Tried to remove last container (page) style!"); - System.exit(1); - } - pageContanerStyles.remove(size-1); - } - private String getLastPageContainerStyle() { - return pageContanerStyles.get(pageContanerStyles.size()-1); - } + } \ No newline at end of file diff --git a/src/main/java/writer2latex/xhtml/content/TextParser.java b/src/main/java/writer2latex/xhtml/content/TextParser.java index e44c541..35995f7 100644 --- a/src/main/java/writer2latex/xhtml/content/TextParser.java +++ b/src/main/java/writer2latex/xhtml/content/TextParser.java @@ -34,7 +34,6 @@ import org.w3c.dom.Element; import writer2latex.util.Misc; import writer2latex.xhtml.Converter; -import writer2latex.xhtml.Separator; import writer2latex.xhtml.PageSplitter; import writer2latex.xhtml.Parser; import writer2latex.xhtml.StyleInfo; @@ -80,7 +79,7 @@ public class TextParser extends Parser { private String sCurrentListLabel = null; private ListStyle currentListStyle = null; private int nCurrentListLevel = 0; - Separator docSep = null; + public Separator docSep = null; // Mode used to handle floats (depends on source doc type and config) @@ -125,6 +124,7 @@ public class TextParser extends Parser { private boolean inFooter = false; private String endnotesContext = null; private String footnotesContext = null; + PageContainer pageContainer = null; public TextParser(OfficeReader ofr, XhtmlConfig config, Converter converter) { super(ofr,config,converter); @@ -143,7 +143,7 @@ public class TextParser extends Parser { DrawParser.FLOATING : DrawParser.ABSOLUTE; outlineNumbering = new ListCounter(ofr.getOutlineStyle()); bDisplayHiddenText = config.displayHiddenText(); - + pageContainer = converter.pageContainer; docSep = new Separator(config, converter); } @@ -555,7 +555,7 @@ public class TextParser extends Parser { footnotesContext = lastFootnotesContext; if (removeStyleAtExit) { - docSep.rmPageContainerStyle(); + pageContainer.removeStyle(); } return hnode; @@ -573,7 +573,7 @@ public class TextParser extends Parser { int colCount = sectionStyle.getColCount(); if (colCount > 1 ) { String styleValue = "column-count: " + colCount + ";"; - docSep.addPageContainerStyle(styleValue); + pageContainer.addStyle(styleValue); result = true; } String collectEndnotes = sectionStyle.getSectionProperty("endnote", false); @@ -1815,7 +1815,7 @@ public class TextParser extends Parser { MasterPage mp = ofr.getFullMasterPage(currentMasterPage); PageLayout layout = ofr.getPageLayout(mp.getPageLayoutName()); String containerStyle = "column-count: " + layout.getColCount() + ";"; - docSep.setPageContainerStyle(containerStyle); + pageContainer.setRootStyle(containerStyle); } private void fitPageNumberToMasterPageStyle() {