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

View file

@ -4,6 +4,6 @@ import org.w3c.dom.Node;
public interface ISplitter { 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 @Override
public boolean Split(Node illustrationIndex) { public SplitResults Split(Node illustrationIndex) {
Node parent = illustrationIndex.getParentNode(); Node parent = illustrationIndex.getParentNode();
Node illustrationIndexFirstPart = illustrationIndex.cloneNode(false); Node illustrationIndexFirstPart = illustrationIndex.cloneNode(false);
NodeList childs = illustrationIndex.getChildNodes(); NodeList childs = illustrationIndex.getChildNodes();
boolean dataMoved = false; SplitResults results = new SplitResults(false);
int i = 0; int i = 0;
while (childs.getLength() > i) { while (childs.getLength() > i) {
Node child = childs.item(i); Node child = childs.item(i);
@ -28,17 +28,17 @@ public class IllustrationIndexSplitter extends BasicSplitter implements ISplitte
illustrationIndexFirstPart.appendChild(child.cloneNode(true)); illustrationIndexFirstPart.appendChild(child.cloneNode(true));
} else } else
if (childName.equals(TEXT_INDEX_BODY)) { if (childName.equals(TEXT_INDEX_BODY)) {
if(factory.split(child)) { if(factory.split(child).isDataMoved()) {
illustrationIndexFirstPart.appendChild(child.getPreviousSibling()); illustrationIndexFirstPart.appendChild(child.getPreviousSibling());
dataMoved = true; results.setDataMoved(true);;
} }
} }
i++; i++;
} }
if (dataMoved) { if (results.isDataMoved()) {
parent.insertBefore(illustrationIndexFirstPart, illustrationIndex); parent.insertBefore(illustrationIndexFirstPart, illustrationIndex);
} }
return dataMoved; return results;
} }
} }

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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