From a93679a41bb39021db549544d87233d83b9c1cf8 Mon Sep 17 00:00:00 2001
From: Georgy Litvinov <git@litvinovg.pro>
Date: Tue, 14 Jan 2020 21:44:27 +0100
Subject: [PATCH] refactoring

---
 .../java/writer2latex/xhtml/PageSplitter.java | 70 +++++++++----------
 1 file changed, 34 insertions(+), 36 deletions(-)

diff --git a/src/main/java/writer2latex/xhtml/PageSplitter.java b/src/main/java/writer2latex/xhtml/PageSplitter.java
index c1205de..576455b 100644
--- a/src/main/java/writer2latex/xhtml/PageSplitter.java
+++ b/src/main/java/writer2latex/xhtml/PageSplitter.java
@@ -453,26 +453,24 @@ public class PageSplitter {
 		}
 		return dataMoved;
 	}
-	private static boolean handleSection(Node sectionFirstPart, Node sectionNode) {
+	private static boolean handleSection(Node sectionFirstPart, Node section) {
 		boolean dataMoved = false;
 		// Node counter
 		int i = 0;
-		NodeList sectionChildNodes = sectionNode.getChildNodes();
-		while (sectionChildNodes.getLength() > i) {
+		NodeList sectionChilds = section.getChildNodes();
+		while (sectionChilds.getLength() > i) {
 			
-			Node sectionChildNode = sectionChildNodes.item(0);
-			if ((sectionChildNode.getNodeType() == Node.ELEMENT_NODE)) {
-				String nodeName = sectionChildNode.getNodeName();
-			//	System.out.println("Nodename " + nodeName);
-				if (containsSPB(sectionChildNode)){
-				//	System.out.println("Contains spb");
-					Node sectionChildFirstPart = sectionChildNode.cloneNode(false); 
+			Node child = sectionChilds.item(0);
+			if ((child.getNodeType() == Node.ELEMENT_NODE)) {
+				String nodeName = child.getNodeName();
+				if (containsSPB(child)){
+					Node childFirstPart = child.cloneNode(false); 
 					if (nodeName.equals(TEXT_SOFT_PAGE_BREAK)){
 						// remove inner soft page break node
-						sectionNode.removeChild(sectionChildNode);
+						section.removeChild(child);
 					
 					} else if (nodeName.equals(TEXT_H) || nodeName.equals(TEXT_P)) {
-						Node paraFirstPart = handleParagraph(sectionChildNode);
+						Node paraFirstPart = handleParagraph(child);
 						if (paraFirstPart != null){
 							sectionFirstPart.appendChild(paraFirstPart);
 							dataMoved=true;
@@ -480,34 +478,34 @@ public class PageSplitter {
 					} else if (nodeName.equals(TEXT_TABLE_OF_CONTENT)) {
 						
 						//HACK
-						removeSPB(sectionNode);
+						removeSPB(section);
 						i++;
 						continue;
 					} else if (nodeName.equals(TABLE_TABLE)) {
-						if (handleTableTable(sectionChildFirstPart, sectionChildNode)){
-							sectionFirstPart.appendChild(sectionChildFirstPart);
+						if (handleTableTable(childFirstPart, child)){
+							sectionFirstPart.appendChild(childFirstPart);
 							dataMoved=true;
 						}
 					} else if (nodeName.equals(TEXT_SECTION)) {
-						if (handleSection(sectionChildFirstPart, sectionChildNode)){
-							sectionFirstPart.appendChild(sectionChildFirstPart);
+						if (handleSection(childFirstPart, child)){
+							sectionFirstPart.appendChild(childFirstPart);
 							dataMoved=true;
 						}
 					} else if (nodeName.equals(TEXT_LIST)) {
-						if (handleList(sectionChildFirstPart, sectionChildNode)){
-							sectionFirstPart.appendChild(sectionChildFirstPart);
+						if (handleList(childFirstPart, child)){
+							sectionFirstPart.appendChild(childFirstPart);
 							dataMoved=true;
 							}
 						}
 					//split node with spb and exit
 					break;
 				} else {
-						sectionFirstPart.appendChild(sectionChildNode);
+						sectionFirstPart.appendChild(child);
 						dataMoved = true;
 				}
 			} else {
 				//Append text nodes
-				sectionFirstPart.appendChild(sectionChildNode);
+				sectionFirstPart.appendChild(child);
 				dataMoved = true;	
 			}
 			
@@ -521,17 +519,17 @@ public class PageSplitter {
 		Node paraBefore = para.cloneNode(false);
 		boolean dataMoved = false;
 		int i = 0;
-		NodeList paraChildNodes = para.getChildNodes();
-		while (paraChildNodes.getLength() > i) {
-			Node paraChildNode = paraChildNodes.item(i);
+		NodeList сhilds = para.getChildNodes();
+		while (сhilds.getLength() > i) {
+			Node сhild = сhilds.item(i);
 			//NOT TEXT NODES
-			if ((paraChildNode.getNodeType() == Node.ELEMENT_NODE)) {
-				String nodeName = paraChildNode.getNodeName();
+			if ((сhild.getNodeType() == Node.ELEMENT_NODE)) {
+				String childName = сhild.getNodeName();
 				//SPB FOUND
-				if (containsSPB(paraChildNode)){
-					if (nodeName.equals(TEXT_SOFT_PAGE_BREAK)){
+				if (containsSPB(сhild)){
+					if (childName.equals(TEXT_SOFT_PAGE_BREAK)){
 						//Next node in paragraph. If it is text node go further
-						Node paraNextNode = paraChildNodes.item(i+1);
+						Node paraNextNode = сhilds.item(i+1);
 						Node paraPrevNode = paraBefore.getLastChild();
 						String nextText = null;
 						String prevText = null;
@@ -568,34 +566,34 @@ public class PageSplitter {
 						if (paraNextNode == null && paraPrevNode == null){
 							Document doc = para.getOwnerDocument();
 							Node space = doc.createTextNode(" ");
-							para.insertBefore(space, paraChildNode);
+							para.insertBefore(space, сhild);
 						}
 						
 						// remove inner soft page break node
-						para.removeChild(paraChildNode);
+						para.removeChild(сhild);
 						
 						/*	Check if next node in para is text and first char is a letter
 						 *  Check if last node in paraFirstPart is text and last char is a letter
 						 *  If both true - add 
 						*/
 					} else {
-						System.out.println("ERROR: SPB INSIDE Paragraph Element in inner element " + nodeName);
+						System.out.println("ERROR: SPB INSIDE Paragraph Element in inner element " + childName);
 						//checkSoftPageBreak(internalNode, true);
 						//paraFirstPart.appendChild(internalNode);
 						//dataMoved = true;
 					}
 					break;
 				//ELEMENT WITHOUT SPB
-				} else if (nodeName.equals(TEXT_BOOKMARK_START)){
-					paraBefore.appendChild(paraChildNode.cloneNode(true));
+				} else if (childName.equals(TEXT_BOOKMARK_START)){
+					paraBefore.appendChild(сhild.cloneNode(true));
 					i++;
 				} else	{
-					paraBefore.appendChild(paraChildNode);
+					paraBefore.appendChild(сhild);
 					dataMoved = true;
 				}
 				//TEXT NODES
 			} else {
-				paraBefore.appendChild(paraChildNode);
+				paraBefore.appendChild(сhild);
 				dataMoved = true;
 			}