One more step
This commit is contained in:
parent
20f7e21595
commit
450b76470c
2 changed files with 126 additions and 80 deletions
|
@ -24,7 +24,7 @@ public class Separator {
|
||||||
public Node currentComment = null;
|
public Node currentComment = null;
|
||||||
private static final String NONE = "none";
|
private static final String NONE = "none";
|
||||||
private static final String DIV = "div";
|
private static final String DIV = "div";
|
||||||
private int splitLevel = 0;
|
private int splitFilesOutlineLevel = 0;
|
||||||
private boolean alignSplitToPages;
|
private boolean alignSplitToPages;
|
||||||
private int lastSplitPageNum = 1;
|
private int lastSplitPageNum = 1;
|
||||||
private Integer pageNumber = null;
|
private Integer pageNumber = null;
|
||||||
|
@ -32,9 +32,9 @@ public class Separator {
|
||||||
|
|
||||||
private static LinkedList<Integer> greenstoneStack = new LinkedList<Integer>();
|
private static LinkedList<Integer> greenstoneStack = new LinkedList<Integer>();
|
||||||
private int[] headingPath;
|
private int[] headingPath;
|
||||||
private static boolean pageOpened = false;
|
static boolean pageOpened = false;
|
||||||
// headings none
|
// headings none
|
||||||
private static boolean greenstoneSeparation;
|
private static boolean isGreenstoneCommentsNeeded;
|
||||||
private static boolean rdfSeparation = false;
|
private static boolean rdfSeparation = false;
|
||||||
// sections div none
|
// sections div none
|
||||||
private static boolean pagination;
|
private static boolean pagination;
|
||||||
|
@ -45,9 +45,9 @@ public class Separator {
|
||||||
|
|
||||||
public Separator(XhtmlConfig config, Converter converter) {
|
public Separator(XhtmlConfig config, Converter converter) {
|
||||||
this.converter = converter;
|
this.converter = converter;
|
||||||
greenstoneSeparation = config.getGreenstoneSeparation();
|
isGreenstoneCommentsNeeded = config.getGreenstoneSeparation();
|
||||||
pagination = config.pagination();
|
pagination = config.pagination();
|
||||||
splitLevel = config.getXhtmlSplitLevel();
|
splitFilesOutlineLevel = config.getXhtmlSplitLevel();
|
||||||
alignSplitToPages = config.getAlignSplitsToPages();
|
alignSplitToPages = config.getAlignSplitsToPages();
|
||||||
breakStyle = config.getPageBreakStyle();
|
breakStyle = config.getPageBreakStyle();
|
||||||
pageContainer = converter.pageContainer;
|
pageContainer = converter.pageContainer;
|
||||||
|
@ -55,44 +55,39 @@ public class Separator {
|
||||||
headingPath = new int[10];
|
headingPath = new int[10];
|
||||||
}
|
}
|
||||||
|
|
||||||
public Node breakOutline(Node currentNode, Node hnode, int pageNum) {
|
//page break found. break outline
|
||||||
// Get outline level
|
public Node breakPageWithOutline(Node currentNode, Node hnode, int pageNum) {
|
||||||
if (isBadOutlineNode(currentNode)) {
|
|
||||||
return hnode;
|
|
||||||
}
|
|
||||||
Node outlineNode = getRealOntlineNode(currentNode);
|
|
||||||
Integer curLevel = getOutlineLevel(outlineNode);
|
|
||||||
String title = getOutlineTitle(outlineNode);
|
|
||||||
|
|
||||||
if (!greenstoneSeparation &&
|
if (!isGreenstoneCommentsNeeded &&
|
||||||
!needPagination() &&
|
!needPagination() &&
|
||||||
!needCurrentLevelSplitOnThisPage(curLevel,pageNum)) {
|
!needOutlineSplitOnThisPage(currentNode,pageNum)) {
|
||||||
return hnode;
|
return hnode;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (needCurrentLevelSplitOnThisPage(curLevel, pageNum)) {
|
if (needOutlineSplitOnThisPage(currentNode, pageNum)) {
|
||||||
prevPageContainer = hnode;
|
prevPageContainer = hnode;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pageOpened) {
|
if (pageOpened) {
|
||||||
hnode = closePage(hnode);
|
hnode = closePage(hnode);
|
||||||
}
|
}
|
||||||
|
Integer curLevel = getOutlineLevel(currentNode);
|
||||||
if (greenstoneSeparation) {
|
if (isGreenstoneCommentsNeeded) {
|
||||||
closeCommentHeadings(hnode, curLevel);
|
closeCommentHeadings(hnode, curLevel);
|
||||||
}
|
}
|
||||||
|
|
||||||
updateHeadingPath(curLevel);
|
updateHeadingPath(curLevel);
|
||||||
|
if (needOutlineSplitOnThisPage(currentNode, pageNum)) {
|
||||||
if (needCurrentLevelSplitOnThisPage(curLevel, pageNum)) {
|
|
||||||
hnode = splitFiles(hnode);
|
hnode = splitFiles(hnode);
|
||||||
if (rdfSeparation) {
|
if (rdfSeparation) {
|
||||||
setContentPath(hnode,curLevel);
|
setContentPath(hnode,curLevel);
|
||||||
|
String title = getOutlineTitle(currentNode);
|
||||||
setContentName(hnode,title);
|
setContentName(hnode,title);
|
||||||
}
|
}
|
||||||
lastSplitPageNum = pageNum;
|
lastSplitPageNum = pageNum;
|
||||||
}
|
}
|
||||||
if (greenstoneSeparation) {
|
if (isGreenstoneCommentsNeeded) {
|
||||||
|
String title = getOutlineTitle(currentNode);
|
||||||
openCommentHeading(hnode, title);
|
openCommentHeading(hnode, title);
|
||||||
addToCommentStack(curLevel.toString());
|
addToCommentStack(curLevel.toString());
|
||||||
}
|
}
|
||||||
|
@ -103,21 +98,58 @@ public class Separator {
|
||||||
|
|
||||||
return hnode;
|
return hnode;
|
||||||
}
|
}
|
||||||
|
//page break not found. break outline
|
||||||
|
public Node breakOutlineOnly(Node currentNode, Node hnode, int pageNum) {
|
||||||
|
|
||||||
private boolean isBadOutlineNode(Node currentNode) {
|
if (!isGreenstoneCommentsNeeded &&
|
||||||
Node outlineNode = getRealOntlineNode(currentNode);
|
!needPagination() &&
|
||||||
Integer curLevel = getOutlineLevel(outlineNode);
|
!needOutlineSplitOnThisPage(currentNode,pageNum)) {
|
||||||
|
return hnode;
|
||||||
|
}
|
||||||
|
if (needOutlineSplitOnThisPage(currentNode, pageNum)) {
|
||||||
|
prevPageContainer = hnode;
|
||||||
|
}
|
||||||
|
if (pageOpened) {
|
||||||
|
hnode = closePage(hnode);
|
||||||
|
}
|
||||||
|
Integer curLevel = getOutlineLevel(currentNode);
|
||||||
|
if (isGreenstoneCommentsNeeded) {
|
||||||
|
closeCommentHeadings(hnode, curLevel);
|
||||||
|
}
|
||||||
|
updateHeadingPath(curLevel);
|
||||||
|
if (needOutlineSplitOnThisPage(currentNode, pageNum)) {
|
||||||
|
hnode = splitFiles(hnode);
|
||||||
|
if (rdfSeparation) {
|
||||||
|
setContentPath(hnode,curLevel);
|
||||||
|
String title = getOutlineTitle(currentNode);
|
||||||
|
setContentName(hnode,title);
|
||||||
|
}
|
||||||
|
lastSplitPageNum = pageNum;
|
||||||
|
}
|
||||||
|
if (isGreenstoneCommentsNeeded) {
|
||||||
|
String title = getOutlineTitle(currentNode);
|
||||||
|
openCommentHeading(hnode, title);
|
||||||
|
addToCommentStack(curLevel.toString());
|
||||||
|
}
|
||||||
|
if (needPagination()) {
|
||||||
|
hnode = openPage(hnode, pageNum);
|
||||||
|
}
|
||||||
|
return hnode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isNotOutlineNode(Node currentNode) {
|
||||||
|
Integer curLevel = getOutlineLevel(currentNode);
|
||||||
if (curLevel < 1) {
|
if (curLevel < 1) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
String title = getOutlineTitle(outlineNode);
|
String title = getOutlineTitle(currentNode);
|
||||||
if (title == null || title.isEmpty()) {
|
if (title == null || title.isEmpty()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Node getRealOntlineNode(Node currentNode) {
|
private static Node getRealOntlineNode(Node currentNode) {
|
||||||
Node outlineNode = null;
|
Node outlineNode = null;
|
||||||
if (currentNode.getNodeName().contentEquals(TABLE_TABLE)) {
|
if (currentNode.getNodeName().contentEquals(TABLE_TABLE)) {
|
||||||
outlineNode = getOulineNodeFromTable(currentNode);
|
outlineNode = getOulineNodeFromTable(currentNode);
|
||||||
|
@ -127,8 +159,9 @@ public class Separator {
|
||||||
return outlineNode;
|
return outlineNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getOutlineLevel(Node currentNode) {
|
private static int getOutlineLevel(Node currentNode) {
|
||||||
String levelAttr = getAttribute(currentNode, XMLString.TEXT_OUTLINE_LEVEL);
|
Node outlineNode = getRealOntlineNode(currentNode);
|
||||||
|
String levelAttr = getAttribute(outlineNode, XMLString.TEXT_OUTLINE_LEVEL);
|
||||||
if (levelAttr == null || levelAttr.isEmpty()) {
|
if (levelAttr == null || levelAttr.isEmpty()) {
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
|
@ -136,7 +169,7 @@ public class Separator {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Node getOulineNodeFromTable(Node currentNode) {
|
private static Node getOulineNodeFromTable(Node currentNode) {
|
||||||
NodeList tableNodes = currentNode.getChildNodes();
|
NodeList tableNodes = currentNode.getChildNodes();
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (i < tableNodes.getLength()) {
|
while (i < tableNodes.getLength()) {
|
||||||
|
@ -172,11 +205,11 @@ public class Separator {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean needChapterSplits() {
|
public boolean configuredOutlineSplits() {
|
||||||
if (splitLevel > 0 ) {
|
if (isFilesSplitLevelSet() ) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (greenstoneSeparation) {
|
if (isGreenstoneCommentsNeeded) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (rdfSeparation) {
|
if (rdfSeparation) {
|
||||||
|
@ -184,8 +217,12 @@ public class Separator {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isFilesSplitLevelSet() {
|
||||||
|
return splitFilesOutlineLevel > 0;
|
||||||
|
}
|
||||||
|
|
||||||
private boolean needPagination() {
|
boolean needPagination() {
|
||||||
if (pagination) {
|
if (pagination) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -224,11 +261,15 @@ public class Separator {
|
||||||
((Element) hnode).setAttribute("path", path.toString());
|
((Element) hnode).setAttribute("path", path.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean needCurrentLevelSplitOnThisPage(int curLevel, int curPage) {
|
boolean needOutlineSplitOnThisPage(Node currentNode, int curPage) {
|
||||||
if (!needChapterSplits()) {
|
if (!configuredOutlineSplits()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if ( splitLevel >= curLevel ) {
|
if (isNotOutlineNode(currentNode)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Integer curLevel = getOutlineLevel(currentNode);
|
||||||
|
if ( splitFilesOutlineLevel >= curLevel ) {
|
||||||
if (alignSplitToPages) {
|
if (alignSplitToPages) {
|
||||||
if (lastSplitPageNum != curPage) {
|
if (lastSplitPageNum != curPage) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -239,19 +280,27 @@ public class Separator {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isPageOpened() {
|
public boolean isPageOpened() {
|
||||||
return pageOpened;
|
return pageOpened;
|
||||||
}
|
}
|
||||||
|
public Node turnPage(Node hnode, int pageNum){
|
||||||
|
if (needPagination()) {
|
||||||
|
if (pageOpened) {
|
||||||
|
hnode = closePage(hnode);
|
||||||
|
}
|
||||||
|
hnode = openPage(hnode, pageNum);
|
||||||
|
}
|
||||||
|
return hnode;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Opens main document section heading tag
|
* Opens main document section heading tag
|
||||||
*/
|
*/
|
||||||
public Node startDocumentSeparation(Node hnode, String title, int pageNum) {
|
public Node startDocumentSeparation(Node hnode, String title, int pageNum) {
|
||||||
if (!greenstoneSeparation && !needPagination()) {
|
if (!isGreenstoneCommentsNeeded && !needPagination()) {
|
||||||
return hnode;
|
return hnode;
|
||||||
}
|
}
|
||||||
if (greenstoneSeparation) {
|
if (isGreenstoneCommentsNeeded) {
|
||||||
// Create global section
|
// Create global section
|
||||||
openCommentHeading(hnode, title);
|
openCommentHeading(hnode, title);
|
||||||
}
|
}
|
||||||
|
@ -262,13 +311,13 @@ public class Separator {
|
||||||
|
|
||||||
// Method to close open tags at the end of the document
|
// Method to close open tags at the end of the document
|
||||||
public Node endDocument(Node hnode) {
|
public Node endDocument(Node hnode) {
|
||||||
if (!greenstoneSeparation && !needPagination()) {
|
if (!isGreenstoneCommentsNeeded && !needPagination()) {
|
||||||
return hnode;
|
return hnode;
|
||||||
}
|
}
|
||||||
if (pageOpened) {
|
if (pageOpened) {
|
||||||
hnode = closePage(hnode);
|
hnode = closePage(hnode);
|
||||||
}
|
}
|
||||||
if (greenstoneSeparation) {
|
if (isGreenstoneCommentsNeeded) {
|
||||||
closeCommentHeadings(hnode, 0);
|
closeCommentHeadings(hnode, 0);
|
||||||
// Close global section
|
// Close global section
|
||||||
addCloseComment(hnode);
|
addCloseComment(hnode);
|
||||||
|
@ -359,7 +408,8 @@ public class Separator {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getOutlineTitle(Node currentNode) {
|
public static String getOutlineTitle(Node currentNode) {
|
||||||
Node content = currentNode.cloneNode(true);
|
Node outlineNode = getRealOntlineNode(currentNode);
|
||||||
|
Node content = outlineNode.cloneNode(true);
|
||||||
NodeList lineBreaks = ((Element) content).getElementsByTagName(XMLString.TEXT_LINE_BREAK);
|
NodeList lineBreaks = ((Element) content).getElementsByTagName(XMLString.TEXT_LINE_BREAK);
|
||||||
NodeList textTabs = ((Element) content).getElementsByTagName(XMLString.TEXT_TAB);
|
NodeList textTabs = ((Element) content).getElementsByTagName(XMLString.TEXT_TAB);
|
||||||
|
|
||||||
|
@ -487,7 +537,7 @@ public class Separator {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void appendMetadata(String name, String value) {
|
public void appendMetadata(String name, String value) {
|
||||||
if (!greenstoneSeparation) {
|
if (!isGreenstoneCommentsNeeded) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (currentComment == null) {
|
if (currentComment == null) {
|
||||||
|
@ -506,22 +556,4 @@ public class Separator {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Node breaksOrOutline(Node currentNode, Node hnode, int pageNum) {
|
|
||||||
|
|
||||||
if (isBadOutlineNode(currentNode)) {
|
|
||||||
if (!needPagination()) {
|
|
||||||
return hnode;
|
|
||||||
}
|
|
||||||
if (pageOpened) {
|
|
||||||
hnode = closePage(hnode);
|
|
||||||
}
|
|
||||||
hnode = openPage(hnode, pageNum);
|
|
||||||
|
|
||||||
return hnode;
|
|
||||||
} else {
|
|
||||||
hnode = breakOutline(currentNode, hnode, pageNum);
|
|
||||||
}
|
|
||||||
return hnode;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1222,15 +1222,15 @@ public class TextParser extends Parser {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean firstSeparation = (currentMasterPage == null) ;
|
boolean isMasterPageNull = (currentMasterPage == null) ;
|
||||||
if (firstSeparation && style != null) {
|
if (isMasterPageNull && style != null) {
|
||||||
hnode = startDocument(hnode, style);
|
hnode = startDocument(hnode, style);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isPageBreakFound(style) && !firstSeparation) {
|
if (isPageBreakFound(style) && !isMasterPageNull) {
|
||||||
hnode = breakPage(currentNode, hnode, style);
|
hnode = breakPage(currentNode, hnode, style);
|
||||||
} else {
|
} else if (!Separator.isNotOutlineNode(currentNode)) {
|
||||||
hnode = docSep.breakOutline(currentNode, hnode, pageNum);
|
hnode = docSep.breakOutlineOnly(currentNode, hnode, pageNum);
|
||||||
}
|
}
|
||||||
setBreakPageBeforeNextFromStyle(style);
|
setBreakPageBeforeNextFromStyle(style);
|
||||||
return hnode;
|
return hnode;
|
||||||
|
@ -1243,6 +1243,13 @@ public class TextParser extends Parser {
|
||||||
breakPageBeforeNextNode = false;
|
breakPageBeforeNextNode = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isOutlineBreakFound(Node currentNode) {
|
||||||
|
if (docSep.needOutlineSplitOnThisPage(currentNode, pageNum)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
private boolean isPageBreakFound(StyleWithProperties style) {
|
private boolean isPageBreakFound(StyleWithProperties style) {
|
||||||
return hasMasterPage(style) || hasBreakBefore(style) || breakPageBeforeNextNode;
|
return hasMasterPage(style) || hasBreakBefore(style) || breakPageBeforeNextNode;
|
||||||
|
@ -1266,15 +1273,27 @@ public class TextParser extends Parser {
|
||||||
|
|
||||||
private Node breakPage(Node currentNode, Node hnode, StyleWithProperties style) {
|
private Node breakPage(Node currentNode, Node hnode, StyleWithProperties style) {
|
||||||
// Insert footnotes
|
// Insert footnotes
|
||||||
insertFootnotes(hnode,false);
|
if (docSep.needPagination()) {
|
||||||
|
insertFootnotes(hnode,false);
|
||||||
// Add previous MP footer
|
addFooter(hnode);
|
||||||
//hnode = exitPageContainer((Element) hnode);
|
}
|
||||||
addFooter(hnode);
|
|
||||||
// Update MP
|
|
||||||
updateMasterPageWith(style);
|
updateMasterPageWith(style);
|
||||||
setPageContainerStyle();
|
setPageContainerStyle();
|
||||||
// Set new page number if defined or increment if not
|
setNewPageNumber(style);
|
||||||
|
|
||||||
|
if (Separator.isNotOutlineNode(currentNode)) {
|
||||||
|
hnode = docSep.turnPage(hnode, pageNum);
|
||||||
|
} else {
|
||||||
|
hnode = docSep.breakPageWithOutline(currentNode, hnode, pageNum);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (docSep.needPagination()) {
|
||||||
|
addHeader(hnode);
|
||||||
|
}
|
||||||
|
return hnode;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setNewPageNumber(StyleWithProperties style) {
|
||||||
Integer newPageNumber = getPageNumberFromStyle(style);
|
Integer newPageNumber = getPageNumberFromStyle(style);
|
||||||
if (newPageNumber != null) {
|
if (newPageNumber != null) {
|
||||||
pageNum = newPageNumber;
|
pageNum = newPageNumber;
|
||||||
|
@ -1282,11 +1301,6 @@ public class TextParser extends Parser {
|
||||||
pageNum++;
|
pageNum++;
|
||||||
fitPageNumberToMasterPageStyle();
|
fitPageNumberToMasterPageStyle();
|
||||||
}
|
}
|
||||||
hnode = docSep.breaksOrOutline(currentNode, hnode, pageNum);
|
|
||||||
|
|
||||||
// Print new header
|
|
||||||
addHeader(hnode);
|
|
||||||
return hnode;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean inUnreakableElement() {
|
private boolean inUnreakableElement() {
|
||||||
|
|
Loading…
Add table
Reference in a new issue