Refactored table row split metho

This commit is contained in:
Georgy Litvinov 2020-07-24 19:21:52 +02:00
parent b1788f2472
commit 4ff33bcc3f

View file

@ -322,9 +322,9 @@ public class ODFPageSplitter {
table.removeChild(tableChildNode);
} else if (tableChildNodeName.equals(TABLE_TABLE_ROW_GROUP)) {
if (handleTableRowGroup(tableChildFirstPart, tableChildNode)){
if (handleTableRowGroup(tableChildNode)){
dataMoved = true;
tableFirstPart.appendChild(tableChildFirstPart);
tableFirstPart.appendChild(tableChildNode.getPreviousSibling());
}
} else if ( tableChildNodeName.equals(TABLE_TABLE_ROWS)) {
if (handleTableRows(tableChildFirstPart, tableChildNode)){
@ -332,9 +332,9 @@ public class ODFPageSplitter {
tableFirstPart.appendChild(tableChildFirstPart);
}
} else if ( tableChildNodeName.equals(TABLE_TABLE_ROW)) {
if (handleTableRow(tableChildFirstPart, tableChildNode)){
if (handleTableRow(tableChildNode)){
dataMoved = true;
tableFirstPart.appendChild(tableChildFirstPart);
tableFirstPart.appendChild(tableChildNode.getPreviousSibling());
}
} else if (tableChildNodeName.equals(TABLE_TABLE_COLUMN)
|| tableChildNodeName.equals(TABLE_TABLE_COLUMN_GROUP)
@ -370,8 +370,10 @@ public class ODFPageSplitter {
return dataMoved;
}
private static boolean handleTableRowGroup(Node tableRowGroupFistPart, Node tableRowGroup) {
private static boolean handleTableRowGroup(Node tableRowGroup) {
boolean dataMoved = false;
Node parent = tableRowGroup.getParentNode();
Node tableRowGroupFistPart = tableRowGroup.cloneNode(false);
// Node counter
int i = 0;
NodeList tableRowGroupChildNodes = tableRowGroup.getChildNodes();
@ -392,14 +394,14 @@ public class ODFPageSplitter {
//Not needed to set dataMoved = true, not needed to append First part
} else if (nodeName.equals(TABLE_TABLE_ROW)){
if (handleTableRow(tableRowGroupChildFirstPart, tableRowGroupChildNode)){
if (handleTableRow(tableRowGroupChildNode)){
dataMoved = true;
tableRowGroupFistPart.appendChild(tableRowGroupChildFirstPart);
tableRowGroupFistPart.appendChild(tableRowGroupChildNode.getPreviousSibling());
}
} else if (nodeName.equals(TABLE_TABLE_ROW_GROUP)){
if (handleTableRowGroup(tableRowGroupChildFirstPart, tableRowGroupChildNode)){
if (handleTableRowGroup(tableRowGroupChildNode)){
dataMoved = true;
tableRowGroupFistPart.appendChild(tableRowGroupChildFirstPart);
tableRowGroupFistPart.appendChild(tableRowGroupChildNode.getPreviousSibling());
}
} else if (nodeName.equals(TABLE_TABLE_ROWS)){
if (handleTableRows(tableRowGroupChildFirstPart, tableRowGroupChildNode)){
@ -426,6 +428,10 @@ public class ODFPageSplitter {
}
}
if (dataMoved) {
parent.insertBefore(tableRowGroupFistPart, tableRowGroup);
}
return dataMoved;
}
private static boolean handleTableRows(Node tableRowsFistPart, Node tableRows) {
@ -446,9 +452,9 @@ public class ODFPageSplitter {
tableRows.removeChild(tableRowsChildNode);
} else if (nodeName.equals(TABLE_TABLE_ROW)){
if (handleTableRow(tableRowGroupChildFirstPart, tableRowsChildNode)){
if (handleTableRow(tableRowsChildNode)){
dataMoved = true;
tableRowsFistPart.appendChild(tableRowGroupChildFirstPart);
tableRowsFistPart.appendChild(tableRowsChildNode.getPreviousSibling());
}
}
break;
@ -466,7 +472,9 @@ public class ODFPageSplitter {
}
return dataMoved;
}
private static boolean handleTableRow(Node tableRowFistPart, Node tableRow) {
private static boolean handleTableRow(Node tableRow) {
Node tableRowFirstPart = tableRow.cloneNode(false);
Node parent = tableRow.getParentNode();
boolean dataMoved = false;
// Node counter
int i = 0;
@ -482,20 +490,20 @@ public class ODFPageSplitter {
if (nodeName.equals(TABLE_TABLE_CELL)){
if (handleCell(tableRowGroupChildFirstPart, tableRowChildNode)){
dataMoved = true;
tableRowFistPart.appendChild(tableRowGroupChildFirstPart);
tableRowFirstPart.appendChild(tableRowGroupChildFirstPart);
}
} else if (nodeName.equals(TABLE_COVERED_TABLE_CELL)){
//Implement handleCoveredCell in future
if (handleCell(tableRowGroupChildFirstPart, tableRowChildNode)){
dataMoved = true;
tableRowFistPart.appendChild(tableRowGroupChildFirstPart);
tableRowFirstPart.appendChild(tableRowGroupChildFirstPart);
}
}
} else {
//System.out.println("HERE " + nodeName);
//Move node without SPB above
tableRowFistPart.appendChild(tableRowChildNode.cloneNode(true));
tableRowFirstPart.appendChild(tableRowChildNode.cloneNode(true));
Node emptyCell = tableRowChildNode.cloneNode(false);
Document document = tableRow.getOwnerDocument();
Element textP = document.createElement(TEXT_P);
@ -515,6 +523,9 @@ public class ODFPageSplitter {
}
}
if (dataMoved) {
parent.insertBefore(tableRowFirstPart, tableRow);
}
return dataMoved;
}
private static boolean handleCell(Node cellFirstPart, Node cellNode) {