Refactored. Extracted class PageContainer
This commit is contained in:
parent
3e53edd42a
commit
2ed1b4ba7f
7 changed files with 66 additions and 43 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
|
||||
/** <p> Class representing a master page in OOo Writer </p> */
|
||||
public class MasterPage extends OfficeStyle {
|
||||
|
|
|
@ -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;
|
||||
|
||||
/** <p> Class representing a style in OOo which contains a style:properties
|
||||
* element </p>
|
||||
|
|
|
@ -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
|
||||
|
|
34
src/main/java/writer2latex/xhtml/content/PageContainer.java
Normal file
34
src/main/java/writer2latex/xhtml/content/PageContainer.java
Normal file
|
@ -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<String> pageContanerStyles = null;
|
||||
public PageContainer() {
|
||||
pageContanerStyles = new ArrayList<String>(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);
|
||||
}
|
||||
}
|
|
@ -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<String> pageContanerStyles = new ArrayList<String>(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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -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() {
|
||||
|
|
Loading…
Add table
Reference in a new issue