Results of splitters changed from boolean to object to return complex info about splitting results

This commit is contained in:
Georgy Litvinov 2021-02-12 22:37:57 +01:00
parent 164d7871a1
commit 893e09c916
17 changed files with 134 additions and 114 deletions

View file

@ -15,11 +15,11 @@ public class ABIndexSplitter extends BasicSplitter implements ISplitter {
}
@Override
public boolean Split(Node abIndex) {
public SplitResults Split(Node abIndex) {
Node parent = abIndex.getParentNode();
Node abIndexFirstPart = abIndex.cloneNode(false);
NodeList childs = abIndex.getChildNodes();
boolean dataMoved = false;
SplitResults results = new SplitResults(false);
int i = 0;
while (childs.getLength() > i) {
Node child = childs.item(i);
@ -28,17 +28,17 @@ public class ABIndexSplitter extends BasicSplitter implements ISplitter {
abIndexFirstPart.appendChild(child.cloneNode(true));
} else
if (childName.equals(TEXT_INDEX_BODY)) {
if (factory.split(child)) {
if (factory.split(child).isDataMoved()) {
abIndexFirstPart.appendChild(child.getPreviousSibling());
dataMoved = true;
results.setDataMoved(true);
}
}
i++;
}
if (dataMoved) {
if (results.isDataMoved()) {
parent.insertBefore(abIndexFirstPart, abIndex);
}
return dataMoved;
return results;
}
}

View file

@ -4,6 +4,6 @@ import org.w3c.dom.Node;
public interface ISplitter {
public boolean Split(Node node);
public SplitResults Split(Node node);
}

View file

@ -15,11 +15,11 @@ public class IllustrationIndexSplitter extends BasicSplitter implements ISplitte
}
@Override
public boolean Split(Node illustrationIndex) {
public SplitResults Split(Node illustrationIndex) {
Node parent = illustrationIndex.getParentNode();
Node illustrationIndexFirstPart = illustrationIndex.cloneNode(false);
NodeList childs = illustrationIndex.getChildNodes();
boolean dataMoved = false;
SplitResults results = new SplitResults(false);
int i = 0;
while (childs.getLength() > i) {
Node child = childs.item(i);
@ -28,17 +28,17 @@ public class IllustrationIndexSplitter extends BasicSplitter implements ISplitte
illustrationIndexFirstPart.appendChild(child.cloneNode(true));
} else
if (childName.equals(TEXT_INDEX_BODY)) {
if(factory.split(child)) {
if(factory.split(child).isDataMoved()) {
illustrationIndexFirstPart.appendChild(child.getPreviousSibling());
dataMoved = true;
results.setDataMoved(true);;
}
}
i++;
}
if (dataMoved) {
if (results.isDataMoved()) {
parent.insertBefore(illustrationIndexFirstPart, illustrationIndex);
}
return dataMoved;
return results;
}
}

View file

@ -15,10 +15,10 @@ public class IndexBodySplitter extends BasicSplitter implements ISplitter {
}
@Override
public boolean Split(Node indexBody) {
public SplitResults Split(Node indexBody) {
Node indexBodyFirstPart = indexBody.cloneNode(false);
NodeList childs = indexBody.getChildNodes();
boolean dataMoved = false;
SplitResults results = new SplitResults(false);
int i = 0;
while (childs.getLength() > i) {
Node child = childs.item(i);
@ -27,11 +27,11 @@ public class IndexBodySplitter extends BasicSplitter implements ISplitter {
} else {
String childName = child.getNodeName();
if (childName.equals(TEXT_P)) {
if (factory.split(child)) {
if (factory.split(child).isDataMoved()) {
indexBodyFirstPart.appendChild(child.getPreviousSibling());
dataMoved = true;
results.setDataMoved(true);
}
return dataMoved;
return results;
} else
if (childName.equals(TEXT_SOFT_PAGE_BREAK)) {
//indexBody.removeChild(child);
@ -41,7 +41,7 @@ public class IndexBodySplitter extends BasicSplitter implements ISplitter {
}
}
}
return dataMoved;
return results;
}
}

View file

@ -18,13 +18,13 @@ public class ListItemSplitter extends BasicSplitter implements ISplitter {
}
@Override
public boolean Split(Node listItem) {
public SplitResults Split(Node listItem) {
Node listItemFirstPart = listItem.cloneNode(false);
Node parent = listItem.getParentNode();
//System.out.println("----Start Item------");
//Debug.prettyPrintXml(parent);
int i = 0;
boolean dataMoved = false;
SplitResults results = new SplitResults(false);
NodeList listItemNodes = listItem.getChildNodes();
while(listItemNodes.getLength() > i){
Node listItemChild = listItemNodes.item(i);
@ -41,9 +41,9 @@ public class ListItemSplitter extends BasicSplitter implements ISplitter {
factory.split(listItemChild);
} else if (nodeName.equals(TEXT_H) || nodeName.equals(TEXT_P)) {
if (factory.split(listItemChild)){
if (factory.split(listItemChild).isDataMoved()){
listItemFirstPart.appendChild(listItemChild.getPreviousSibling());
dataMoved=true;
results.setDataMoved(true);
}
} else {
System.out.println("Error. SPB in List item child node " + nodeName);
@ -54,20 +54,20 @@ public class ListItemSplitter extends BasicSplitter implements ISplitter {
} else {
listItemFirstPart.appendChild(listItemChild);
dataMoved = true;
results.setDataMoved(true);
}
} else {
listItemFirstPart.appendChild(listItemChild);
dataMoved = true;
results.setDataMoved(true);
}
//check internal nodes
}
if(dataMoved) {
if(results.isDataMoved()) {
parent.insertBefore(listItemFirstPart, listItem);
}
//System.out.println("-----FINISH Item-----");
//Debug.prettyPrintXml(parent);
return dataMoved;
return results;
}
}

View file

@ -22,7 +22,7 @@ public class ListSplitter extends BasicSplitter implements ISplitter {
}
@Override
public boolean Split(Node list) {
public SplitResults Split(Node list) {
Node parent = list.getParentNode();
// System.out.println("----Start ListSplitter------");
// Debug.prettyPrintXml(parent);
@ -32,7 +32,7 @@ public class ListSplitter extends BasicSplitter implements ISplitter {
Element softPageBreak = document.createElement(TEXT_SOFT_PAGE_BREAK);
Node nextPageItemPart = null;
int i = 0;
boolean dataMoved = false;
SplitResults results = new SplitResults(false);
while (listNodes.getLength() > i) {
Node child = listNodes.item(i);
if (child.getNodeType() == Node.ELEMENT_NODE) {
@ -51,8 +51,8 @@ public class ListSplitter extends BasicSplitter implements ISplitter {
if (containsSPB(child)) {
// remove SPB, move previous nodes to firstPart.
if (factory.split(child)) {
dataMoved = true;
if (factory.split(child).isDataMoved()) {
results.setDataMoved(true);
// Add first part of list item to previous list item
listFirstPart.appendChild(child.getPreviousSibling());
if (child.hasChildNodes()) {
@ -67,7 +67,7 @@ public class ListSplitter extends BasicSplitter implements ISplitter {
} else {
// Not with SPB yet, move node, set dataMoved=true
listFirstPart.appendChild(child);
dataMoved = true;
results.setDataMoved(true);
}
} else {
System.out.println("Error. SPB in List child node " + nodeName);
@ -75,7 +75,7 @@ public class ListSplitter extends BasicSplitter implements ISplitter {
}
}
}
if (dataMoved) {
if (results.isDataMoved()) {
((Element) list).setAttribute(TEXT_CONTINUE_NUMBERING, "true");
parent.insertBefore(listFirstPart, list);
parent.insertBefore(softPageBreak, list);
@ -109,7 +109,7 @@ public class ListSplitter extends BasicSplitter implements ISplitter {
// Debug.prettyPrintXml(parent);
return dataMoved;
return results;
}
}

View file

@ -21,13 +21,12 @@ public class ParagraphSplitter extends BasicSplitter implements ISplitter {
}
@Override
public boolean Split(Node para) {
public SplitResults Split(Node para) {
Node parent = para.getParentNode();
//System.out.println("PRINT PARA START");
//Debug.prettyPrintXml(parent);
SplitResults results = new SplitResults(false);
Node paraFirstPart = para.cloneNode(false);
boolean dataMoved = false;
int i = 0;
NodeList childs = para.getChildNodes();
while (childs.getLength() > i) {
@ -60,7 +59,7 @@ public class ParagraphSplitter extends BasicSplitter implements ISplitter {
paraFirstPart.appendChild(child.cloneNode(true));
i++;
} else {
dataMoved = true;
results.setDataMoved(true);
paraFirstPart.appendChild(child);
}
//TEXT NODES
@ -68,13 +67,13 @@ public class ParagraphSplitter extends BasicSplitter implements ISplitter {
}
addHyphen(para,paraFirstPart);
if (dataMoved) {
if (results.isDataMoved()) {
removeIndent(para);
parent.insertBefore(paraFirstPart, para);
}
//System.out.println("PRINT PARA END");
//Debug.prettyPrintXml(parent);
return dataMoved;
return results;
}
}

View file

@ -22,12 +22,12 @@ public class SectionSplitter extends BasicSplitter implements ISplitter {
}
@Override
public boolean Split(Node section) {
public SplitResults Split(Node section) {
Node parent = section.getParentNode();
setLastAttribute(section);
Node sectionFirstPart = section.cloneNode(false);
removeLastAttribute(sectionFirstPart);
boolean dataMoved = false;
SplitResults results = new SplitResults(false);
// Node counter
int i = 0;
NodeList childs = section.getChildNodes();
@ -41,9 +41,9 @@ public class SectionSplitter extends BasicSplitter implements ISplitter {
// remove inner soft page break node
section.removeChild(child);
} else if (nodeName.equals(TEXT_H) || nodeName.equals(TEXT_P)) {
if (factory.split(child)){
if (factory.split(child).isDataMoved()){
sectionFirstPart.appendChild(child.getPreviousSibling());
dataMoved=true;
results.setDataMoved(true);
}
} else if (nodeName.equals(TEXT_TABLE_OF_CONTENT)) {
@ -52,18 +52,18 @@ public class SectionSplitter extends BasicSplitter implements ISplitter {
i++;
continue;
} else if (nodeName.equals(TABLE_TABLE)) {
if (factory.split(child)){
if (factory.split(child).isDataMoved()){
sectionFirstPart.appendChild(child.getPreviousSibling());
dataMoved=true;
results.setDataMoved(true);
}
} else if (nodeName.equals(TEXT_SECTION)) {
if (factory.split(child)){
if (factory.split(child).isDataMoved()){
sectionFirstPart.appendChild(child.getPreviousSibling());
dataMoved=true;
results.setDataMoved(true);
}
} else if (nodeName.equals(TEXT_LIST)) {
if (factory.split(child)){
dataMoved=true;
if (factory.split(child).isDataMoved()){
results.setDataMoved(true);
}
} else {
System.out.println("Error. SPB in Section child node " + nodeName);
@ -73,20 +73,20 @@ public class SectionSplitter extends BasicSplitter implements ISplitter {
break;
} else {
sectionFirstPart.appendChild(child);
dataMoved = true;
results.setDataMoved(true);
}
} else {
//Append text nodes
sectionFirstPart.appendChild(child);
dataMoved = true;
results.setDataMoved(true);
}
}
if (dataMoved) {
if (results.isDataMoved()) {
parent.insertBefore(sectionFirstPart, section);
}
return dataMoved;
return results;
}

View file

@ -17,7 +17,8 @@ public class SpanSplitter extends BasicSplitter implements ISplitter{
}
@Override
public boolean Split(Node span) {
public SplitResults Split(Node span) {
SplitResults results = new SplitResults(false);
NodeList childs = span.getChildNodes();
int i = 0;
while (childs.getLength() > i) {
@ -37,7 +38,7 @@ public class SpanSplitter extends BasicSplitter implements ISplitter{
}
i++;
}
return false;
return results;
}
}

View file

@ -10,7 +10,7 @@ public class SplitFactory {
public SplitFactory(OfficeReader ofr){
this.officeReader = ofr;
}
public boolean split(Node node) {
public SplitResults split(Node node) {
if(node == null) {
System.out.println("Error. Node is null.");
Debug.printStackTrace();

View file

@ -0,0 +1,19 @@
package w2phtml.pageSplitters;
public class SplitResults {
private boolean dataMoved;
public SplitResults(boolean dataMoved) {
this.setDataMoved(dataMoved);
}
public boolean isDataMoved() {
return dataMoved;
}
public void setDataMoved(boolean dataMoved) {
this.dataMoved = dataMoved;
}
}

View file

@ -19,10 +19,10 @@ public class TableCellSplitter extends BasicSplitter implements ISplitter {
}
@Override
public boolean Split(Node cellNode) {
public SplitResults Split(Node cellNode) {
Node cellFirstPart = cellNode.cloneNode(false);
Node parent = cellNode.getParentNode();
boolean dataMoved = false;
SplitResults results = new SplitResults(false);
// Node counter
int i = 0;
NodeList cellChildNodes = cellNode.getChildNodes();
@ -35,19 +35,19 @@ public class TableCellSplitter extends BasicSplitter implements ISplitter {
// remove inner soft page break node
cellNode.removeChild(cellChildNode);
} else if (nodeName.equals(TEXT_H) || nodeName.equals(TEXT_P)) {
if (factory.split(cellChildNode)){
if (factory.split(cellChildNode).isDataMoved()){
cellFirstPart.appendChild(cellChildNode.getPreviousSibling());
dataMoved=true;
results.setDataMoved(true);
}
} else if (nodeName.equals(TEXT_LIST)) {
if (factory.split(cellChildNode)){
if (factory.split(cellChildNode).isDataMoved()){
cellFirstPart.appendChild(cellChildNode.getPreviousSibling());
dataMoved=true;
results.setDataMoved(true);
}
} else if (nodeName.equals(TABLE_TABLE)) {
if (factory.split(cellChildNode)){
if (factory.split(cellChildNode).isDataMoved()){
cellFirstPart.appendChild(cellChildNode.getPreviousSibling());
dataMoved=true;
results.setDataMoved(true);
}
} else {
System.out.println("Error. SPB in Cell child node " + nodeName);
@ -57,20 +57,20 @@ public class TableCellSplitter extends BasicSplitter implements ISplitter {
break;
} else {
cellFirstPart.appendChild(cellChildNode);
dataMoved = true;
results.setDataMoved(true);
}
} else {
//Append text nodes
cellFirstPart.appendChild(cellChildNode);
dataMoved = true;
results.setDataMoved(true);
}
}
if (dataMoved) {
if (results.isDataMoved()) {
parent.insertBefore(cellFirstPart, cellNode);
}
return dataMoved;
return results;
}
}

View file

@ -19,8 +19,8 @@ public class TableRowGroupSplitter extends BasicSplitter implements ISplitter {
}
@Override
public boolean Split(Node tableRowGroup) {
boolean dataMoved = false;
public SplitResults Split(Node tableRowGroup) {
SplitResults results = new SplitResults(false);
Node parent = tableRowGroup.getParentNode();
Node tableRowGroupFistPart = tableRowGroup.cloneNode(false);
// Node counter
@ -42,18 +42,18 @@ public class TableRowGroupSplitter extends BasicSplitter implements ISplitter {
//Not needed to set dataMoved = true, not needed to append First part
} else if (nodeName.equals(TABLE_TABLE_ROW)){
if (factory.split(tableRowGroupChildNode)){
dataMoved = true;
if (factory.split(tableRowGroupChildNode).isDataMoved()){
results.setDataMoved(true);
tableRowGroupFistPart.appendChild(tableRowGroupChildNode.getPreviousSibling());
}
} else if (nodeName.equals(TABLE_TABLE_ROW_GROUP)){
if (factory.split(tableRowGroupChildNode)){
dataMoved = true;
if (factory.split(tableRowGroupChildNode).isDataMoved()){
results.setDataMoved(true);
tableRowGroupFistPart.appendChild(tableRowGroupChildNode.getPreviousSibling());
}
} else if (nodeName.equals(TABLE_TABLE_ROWS)){
if (factory.split(tableRowGroupChildNode)){
dataMoved = true;
if (factory.split(tableRowGroupChildNode).isDataMoved()){
results.setDataMoved(true);
tableRowGroupFistPart.appendChild(tableRowGroupChildNode.getPreviousSibling());
}
}
@ -66,21 +66,21 @@ public class TableRowGroupSplitter extends BasicSplitter implements ISplitter {
} else {
tableRowGroupFistPart.appendChild(tableRowGroupChildNode);
dataMoved = true;
results.setDataMoved(true);
}
}
} else {
//Append text nodes
tableRowGroupFistPart.appendChild(tableRowGroupChildNode);
dataMoved = true;
results.setDataMoved(true);
}
}
if (dataMoved) {
if (results.isDataMoved()) {
parent.insertBefore(tableRowGroupFistPart, tableRowGroup);
}
return dataMoved;
return results;
}
}

View file

@ -18,10 +18,10 @@ public class TableRowSplitter extends BasicSplitter implements ISplitter {
}
@Override
public boolean Split(Node tableRow) {
public SplitResults Split(Node tableRow) {
Node tableRowFirstPart = tableRow.cloneNode(false);
Node parent = tableRow.getParentNode();
boolean dataMoved = false;
SplitResults results = new SplitResults(false);
// Node counter
int i = 0;
NodeList tableRowChildNodes = tableRow.getChildNodes();
@ -33,15 +33,15 @@ public class TableRowSplitter extends BasicSplitter implements ISplitter {
if (containsSPB(tableRowChildNode)){
if (nodeName.equals(TABLE_TABLE_CELL)){
if (factory.split(tableRowChildNode)){
dataMoved = true;
if (factory.split(tableRowChildNode).isDataMoved()){
results.setDataMoved(true);
tableRowFirstPart.appendChild(tableRowChildNode.getPreviousSibling());
}
} else if (nodeName.equals(TABLE_COVERED_TABLE_CELL)){
//Implement handleCoveredCell in future
if (factory.split(tableRowChildNode)){
dataMoved = true;
if (factory.split(tableRowChildNode).isDataMoved()){
results.setDataMoved(true);
tableRowFirstPart.appendChild(tableRowChildNode.getPreviousSibling());
}
}
@ -57,7 +57,7 @@ public class TableRowSplitter extends BasicSplitter implements ISplitter {
tableRow.removeChild(tableRowChildNode);
dataMoved = true;
results.setDataMoved(true);
}
i++;
} else {
@ -68,10 +68,10 @@ public class TableRowSplitter extends BasicSplitter implements ISplitter {
}
}
if (dataMoved) {
if (results.isDataMoved()) {
parent.insertBefore(tableRowFirstPart, tableRow);
}
return dataMoved;
return results;
}
}

View file

@ -15,10 +15,10 @@ public class TableRowsSplitter extends BasicSplitter implements ISplitter {
}
@Override
public boolean Split(Node tableRows) {
public SplitResults Split(Node tableRows) {
Node tableRowsFirstPart = tableRows.cloneNode(false);
Node parent = tableRows.getParentNode();
boolean dataMoved = false;
SplitResults results = new SplitResults(false);
// Node counter
int i = 0;
NodeList tableRowsChildNodes = tableRows.getChildNodes();
@ -34,15 +34,15 @@ public class TableRowsSplitter extends BasicSplitter implements ISplitter {
tableRows.removeChild(tableRowsChildNode);
} else if (nodeName.equals(TABLE_TABLE_ROW)){
if (factory.split(tableRowsChildNode)){
dataMoved = true;
if (factory.split(tableRowsChildNode).isDataMoved()){
results.setDataMoved(true);
tableRowsFirstPart.appendChild(tableRowsChildNode.getPreviousSibling());
}
}
break;
} else {
tableRowsFirstPart.appendChild(tableRowsChildNode);
dataMoved = true;
results.setDataMoved(true);
}
} else {
System.out.println("ERROR: TEXT NODE FOUND INSIDE tabl:table-rows");
@ -52,10 +52,10 @@ public class TableRowsSplitter extends BasicSplitter implements ISplitter {
}
}
if (dataMoved) {
if (results.isDataMoved()) {
parent.insertBefore(tableRowsFirstPart, tableRows);
}
return dataMoved;
return results;
}
}

View file

@ -21,7 +21,7 @@ public class TableSplitter extends BasicSplitter implements ISplitter {
}
@Override
public boolean Split(Node table) {
public SplitResults Split(Node table) {
/*
* // TODO: 0.Test if soft-page-break not at start of table // - in that
@ -41,7 +41,7 @@ public class TableSplitter extends BasicSplitter implements ISplitter {
NodeList tableChildNodes = table.getChildNodes();
// Node counter
int i = 0;
boolean dataMoved = false;
SplitResults results = new SplitResults(false);
// Loop through the TABLE:TABLE child nodes
while (tableChildNodes.getLength() > i) {
Node tableChildNode = tableChildNodes.item(i);
@ -56,18 +56,18 @@ public class TableSplitter extends BasicSplitter implements ISplitter {
table.removeChild(tableChildNode);
} else if (tableChildNodeName.equals(TABLE_TABLE_ROW_GROUP)) {
if (factory.split(tableChildNode)){
dataMoved = true;
if (factory.split(tableChildNode).isDataMoved()){
results.setDataMoved(true);
tableFirstPart.appendChild(tableChildNode.getPreviousSibling());
}
} else if ( tableChildNodeName.equals(TABLE_TABLE_ROWS)) {
if (factory.split(tableChildNode)){
dataMoved = true;
if (factory.split(tableChildNode).isDataMoved()){
results.setDataMoved(true);
tableFirstPart.appendChild(tableChildNode.getPreviousSibling());
}
} else if ( tableChildNodeName.equals(TABLE_TABLE_ROW)) {
if (factory.split(tableChildNode)){
dataMoved = true;
if (factory.split(tableChildNode).isDataMoved()){
results.setDataMoved(true);
tableFirstPart.appendChild(tableChildNode.getPreviousSibling());
}
} else if (tableChildNodeName.equals(TABLE_TABLE_COLUMN)
@ -93,15 +93,15 @@ public class TableSplitter extends BasicSplitter implements ISplitter {
} else {
//Append to clone table
tableFirstPart.appendChild(tableChildNode);
dataMoved = true;
results.setDataMoved(true);
}
}
}
}
if (dataMoved) {
if (results.isDataMoved()) {
parent.insertBefore(tableFirstPart, table);
}
return dataMoved;
return results;
}
}

View file

@ -30,11 +30,12 @@ public class TextSplitter extends BasicSplitter implements ISplitter {
}
@Override
public boolean Split(Node onode) {
public SplitResults Split(Node onode) {
//Find par node with soft page break inside and split it
Document document = onode.getOwnerDocument();
Element softPageBreak = document.createElement(TEXT_SOFT_PAGE_BREAK);
NodeList nodes = onode.getChildNodes();
SplitResults results = new SplitResults(false);
int i = 0;
//Loop through the content nodes and split nodes with soft page break
@ -51,11 +52,11 @@ public class TextSplitter extends BasicSplitter implements ISplitter {
if ((nodeName.equals(TEXT_P) || nodeName.equals(TEXT_H))) {
//If SPB not the first node
if (factory.split(child)){
if (factory.split(child).isDataMoved()){
style = officeReader.getParStyle(Misc.getAttribute(child, TEXT_STYLE_NAME));
}
} else if (nodeName.equals(TABLE_TABLE)) {
if (factory.split(child)){
if (factory.split(child).isDataMoved()){
style = officeReader.getTableStyle(Misc.getAttribute(child, TABLE_STYLE_NAME));
}
} else if (nodeName.equals(TEXT_LIST)) {
@ -65,7 +66,7 @@ public class TextSplitter extends BasicSplitter implements ISplitter {
} else if (nodeName.equals(TEXT_ALPHABETICAL_INDEX)) {
factory.split(child);
} else if (nodeName.equals(TEXT_SECTION)) {
if (factory.split(child)) {
if (factory.split(child).isDataMoved()) {
style = officeReader.getSectionStyle(Misc.getAttribute(child, TEXT_SECTION));
}
} else if (nodeName.equals(TEXT_TABLE_OF_CONTENT)){
@ -95,7 +96,7 @@ public class TextSplitter extends BasicSplitter implements ISplitter {
i++;
}
//Debug.printNode(onode);
return false;
return results;
}
}