Refactored separations
This commit is contained in:
parent
450b76470c
commit
be88aec977
3 changed files with 63 additions and 90 deletions
|
@ -44,7 +44,7 @@ public class Separator {
|
||||||
private static final Logger logger = LoggerFactory.getLogger(Separator.class);
|
private static final Logger logger = LoggerFactory.getLogger(Separator.class);
|
||||||
|
|
||||||
public Separator(XhtmlConfig config, Converter converter) {
|
public Separator(XhtmlConfig config, Converter converter) {
|
||||||
this.converter = converter;
|
Separator.converter = converter;
|
||||||
isGreenstoneCommentsNeeded = config.getGreenstoneSeparation();
|
isGreenstoneCommentsNeeded = config.getGreenstoneSeparation();
|
||||||
pagination = config.pagination();
|
pagination = config.pagination();
|
||||||
splitFilesOutlineLevel = config.getXhtmlSplitLevel();
|
splitFilesOutlineLevel = config.getXhtmlSplitLevel();
|
||||||
|
@ -55,85 +55,52 @@ public class Separator {
|
||||||
headingPath = new int[10];
|
headingPath = new int[10];
|
||||||
}
|
}
|
||||||
|
|
||||||
//page break found. break outline
|
public Node breakOutline(Node currentNode, Node hnode, int pageNum) {
|
||||||
public Node breakPageWithOutline(Node currentNode, Node hnode, int pageNum) {
|
if (isGreenstoneCommentsNeeded) {
|
||||||
|
hnode = addGreenstoneOutlineBreaks(currentNode, hnode, pageNum);
|
||||||
|
} else if (rdfSeparation) {
|
||||||
if (!isGreenstoneCommentsNeeded &&
|
hnode = addRDFOutlineBreaks(currentNode, hnode, pageNum);
|
||||||
!needPagination() &&
|
} else if(isFileSplitNeed(currentNode, pageNum)) {
|
||||||
!needOutlineSplitOnThisPage(currentNode,pageNum)) {
|
hnode = addFileOutlineBreaks(currentNode, hnode, pageNum);
|
||||||
|
} else {
|
||||||
|
logger.error("Shouldn't be here. No separation method found.");
|
||||||
|
}
|
||||||
return hnode;
|
return hnode;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (needOutlineSplitOnThisPage(currentNode, pageNum)) {
|
private Node addFileOutlineBreaks(Node currentNode, Node hnode, int pageNum) {
|
||||||
|
|
||||||
prevPageContainer = hnode;
|
prevPageContainer = hnode;
|
||||||
|
hnode = closePage(hnode);
|
||||||
|
hnode = splitFiles(hnode);
|
||||||
|
lastSplitPageNum = pageNum;
|
||||||
|
hnode = openPage(hnode, pageNum);
|
||||||
|
return hnode;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pageOpened) {
|
private Node addGreenstoneOutlineBreaks(Node currentNode, Node hnode, int pageNum) {
|
||||||
|
|
||||||
hnode = closePage(hnode);
|
hnode = closePage(hnode);
|
||||||
}
|
|
||||||
Integer curLevel = getOutlineLevel(currentNode);
|
Integer curLevel = getOutlineLevel(currentNode);
|
||||||
if (isGreenstoneCommentsNeeded) {
|
|
||||||
closeCommentHeadings(hnode, curLevel);
|
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);
|
String title = getOutlineTitle(currentNode);
|
||||||
openCommentHeading(hnode, title);
|
openCommentHeading(hnode, title);
|
||||||
addToCommentStack(curLevel.toString());
|
addToCommentStack(curLevel.toString());
|
||||||
}
|
|
||||||
|
|
||||||
if (needPagination()) {
|
|
||||||
hnode = openPage(hnode, pageNum);
|
hnode = openPage(hnode, pageNum);
|
||||||
}
|
|
||||||
|
|
||||||
return hnode;
|
return hnode;
|
||||||
}
|
}
|
||||||
//page break not found. break outline
|
|
||||||
public Node breakOutlineOnly(Node currentNode, Node hnode, int pageNum) {
|
|
||||||
|
|
||||||
if (!isGreenstoneCommentsNeeded &&
|
public Node addRDFOutlineBreaks(Node currentNode, Node hnode, int pageNum) {
|
||||||
!needPagination() &&
|
|
||||||
!needOutlineSplitOnThisPage(currentNode,pageNum)) {
|
|
||||||
return hnode;
|
|
||||||
}
|
|
||||||
if (needOutlineSplitOnThisPage(currentNode, pageNum)) {
|
|
||||||
prevPageContainer = hnode;
|
prevPageContainer = hnode;
|
||||||
}
|
|
||||||
if (pageOpened) {
|
|
||||||
hnode = closePage(hnode);
|
hnode = closePage(hnode);
|
||||||
}
|
|
||||||
Integer curLevel = getOutlineLevel(currentNode);
|
Integer curLevel = getOutlineLevel(currentNode);
|
||||||
if (isGreenstoneCommentsNeeded) {
|
|
||||||
closeCommentHeadings(hnode, curLevel);
|
|
||||||
}
|
|
||||||
updateHeadingPath(curLevel);
|
updateHeadingPath(curLevel);
|
||||||
if (needOutlineSplitOnThisPage(currentNode, pageNum)) {
|
|
||||||
hnode = splitFiles(hnode);
|
hnode = splitFiles(hnode);
|
||||||
if (rdfSeparation) {
|
|
||||||
setContentPath(hnode,curLevel);
|
setContentPath(hnode,curLevel);
|
||||||
String title = getOutlineTitle(currentNode);
|
String title = getOutlineTitle(currentNode);
|
||||||
setContentName(hnode,title);
|
setContentName(hnode,title);
|
||||||
}
|
|
||||||
lastSplitPageNum = pageNum;
|
|
||||||
}
|
|
||||||
if (isGreenstoneCommentsNeeded) {
|
|
||||||
String title = getOutlineTitle(currentNode);
|
|
||||||
openCommentHeading(hnode, title);
|
|
||||||
addToCommentStack(curLevel.toString());
|
|
||||||
}
|
|
||||||
if (needPagination()) {
|
|
||||||
hnode = openPage(hnode, pageNum);
|
hnode = openPage(hnode, pageNum);
|
||||||
}
|
|
||||||
return hnode;
|
return hnode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -268,17 +235,29 @@ public class Separator {
|
||||||
if (isNotOutlineNode(currentNode)) {
|
if (isNotOutlineNode(currentNode)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (isFilesSplitEnabled() && !isFileSplitNeed( currentNode, curPage)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isFilesSplitEnabled() {
|
||||||
|
return splitFilesOutlineLevel != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isFileSplitNeed(Node currentNode, int pageNum) {
|
||||||
|
boolean result = false;
|
||||||
Integer curLevel = getOutlineLevel(currentNode);
|
Integer curLevel = getOutlineLevel(currentNode);
|
||||||
if ( splitFilesOutlineLevel >= curLevel ) {
|
if ( splitFilesOutlineLevel >= curLevel ) {
|
||||||
if (alignSplitToPages) {
|
if (alignSplitToPages) {
|
||||||
if (lastSplitPageNum != curPage) {
|
if (lastSplitPageNum != pageNum) {
|
||||||
return true;
|
result = true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return true;
|
result = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isPageOpened() {
|
public boolean isPageOpened() {
|
||||||
|
@ -412,7 +391,6 @@ public class Separator {
|
||||||
Node content = outlineNode.cloneNode(true);
|
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);
|
||||||
|
|
||||||
replaceWithSpaces(lineBreaks);
|
replaceWithSpaces(lineBreaks);
|
||||||
replaceWithSpaces(textTabs);
|
replaceWithSpaces(textTabs);
|
||||||
deleteNotesIn(content);
|
deleteNotesIn(content);
|
||||||
|
@ -483,7 +461,7 @@ public class Separator {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Node closePage(Node hnode) {
|
public Node closePage(Node hnode) {
|
||||||
if (pageOpened == false) {
|
if (pageOpened == false || !needPagination()) {
|
||||||
return hnode;
|
return hnode;
|
||||||
}
|
}
|
||||||
hnode = exitPageContainer(hnode);
|
hnode = exitPageContainer(hnode);
|
||||||
|
|
|
@ -1229,8 +1229,8 @@ public class TextParser extends Parser {
|
||||||
|
|
||||||
if (isPageBreakFound(style) && !isMasterPageNull) {
|
if (isPageBreakFound(style) && !isMasterPageNull) {
|
||||||
hnode = breakPage(currentNode, hnode, style);
|
hnode = breakPage(currentNode, hnode, style);
|
||||||
} else if (!Separator.isNotOutlineNode(currentNode)) {
|
} else if (isOutlineBreakFound(currentNode)) {
|
||||||
hnode = docSep.breakOutlineOnly(currentNode, hnode, pageNum);
|
hnode = docSep.breakOutline(currentNode, hnode, pageNum);
|
||||||
}
|
}
|
||||||
setBreakPageBeforeNextFromStyle(style);
|
setBreakPageBeforeNextFromStyle(style);
|
||||||
return hnode;
|
return hnode;
|
||||||
|
@ -1281,12 +1281,11 @@ public class TextParser extends Parser {
|
||||||
setPageContainerStyle();
|
setPageContainerStyle();
|
||||||
setNewPageNumber(style);
|
setNewPageNumber(style);
|
||||||
|
|
||||||
if (Separator.isNotOutlineNode(currentNode)) {
|
if (!isOutlineBreakFound(currentNode)) {
|
||||||
hnode = docSep.turnPage(hnode, pageNum);
|
hnode = docSep.turnPage(hnode, pageNum);
|
||||||
} else {
|
} else {
|
||||||
hnode = docSep.breakPageWithOutline(currentNode, hnode, pageNum);
|
hnode = docSep.breakOutline(currentNode, hnode, pageNum);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (docSep.needPagination()) {
|
if (docSep.needPagination()) {
|
||||||
addHeader(hnode);
|
addHeader(hnode);
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,10 +24,6 @@
|
||||||
<div class="pageContainer" style="column-count: 1;">
|
<div class="pageContainer" style="column-count: 1;">
|
||||||
<h1 id="toc0" style="margin-left:0;border:none;padding:0;font-weight:bold;clear:left;font-size:1.5166668rem;margin-top:0.9992126rem;font-family:'IPH Astra Serif',serif;page-break-before:always;margin-bottom:0.5007874rem;margin-right:0;text-align:center;">Heading 1</h1>
|
<h1 id="toc0" style="margin-left:0;border:none;padding:0;font-weight:bold;clear:left;font-size:1.5166668rem;margin-top:0.9992126rem;font-family:'IPH Astra Serif',serif;page-break-before:always;margin-bottom:0.5007874rem;margin-right:0;text-align:center;">Heading 1</h1>
|
||||||
<p class="Textbody" style="margin-left:0;border:none;padding:0;text-indent:2.1259842rem;font-size:8.0rem;margin-top:0;font-family:'IPH Astra Serif',serif;margin-bottom:0.58346456rem;margin-right:0;">Tex</p>
|
<p class="Textbody" style="margin-left:0;border:none;padding:0;text-indent:2.1259842rem;font-size:8.0rem;margin-top:0;font-family:'IPH Astra Serif',serif;margin-bottom:0.58346456rem;margin-right:0;">Tex</p>
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="pageNum" page="2">
|
|
||||||
<div class="pageContainer" style="column-count: 1;">
|
|
||||||
<h1 id="toc1" style="margin-left:0;border:none;padding:0;font-weight:bold;clear:left;font-size:1.5166668rem;margin-top:0.9992126rem;font-family:'IPH Astra Serif',serif;margin-bottom:0.5007874rem;margin-right:0;text-align:center;">Heading 1</h1>
|
<h1 id="toc1" style="margin-left:0;border:none;padding:0;font-weight:bold;clear:left;font-size:1.5166668rem;margin-top:0.9992126rem;font-family:'IPH Astra Serif',serif;margin-bottom:0.5007874rem;margin-right:0;text-align:center;">Heading 1</h1>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Add table
Reference in a new issue