Refactored Paragraph splitter

This commit is contained in:
Georgy Litvinov 2020-11-27 19:21:42 +01:00
parent 850f92615a
commit b170acdece
2 changed files with 12 additions and 18 deletions

View file

@ -20,12 +20,6 @@ public class BasicSplitter {
this.officeReader = officeReader;
this.factory = factory;
}
protected static boolean appendChild(Node parent, Node child) {
boolean dataMoved;
parent.appendChild(child);
dataMoved = true;
return dataMoved;
}
protected static void addHyphen(Node para, Node paraBefore) {
//Debug.printNode(paraBefore);

View file

@ -10,6 +10,7 @@ import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import pro.litvinovg.xml.Debug;
import w2phtml.office.OfficeReader;
public class ParagraphSplitter extends BasicSplitter implements ISplitter {
@ -22,7 +23,9 @@ public class ParagraphSplitter extends BasicSplitter implements ISplitter {
@Override
public boolean Split(Node para) {
Node parent = para.getParentNode();
//System.out.println("handlePara");
//System.out.println("PRINT PARA START");
//Debug.prettyPrintXml(parent);
Node paraFirstPart = para.cloneNode(false);
boolean dataMoved = false;
int i = 0;
@ -31,10 +34,8 @@ public class ParagraphSplitter extends BasicSplitter implements ISplitter {
//System.out.println("In WHILE HANDLE PARA");
Node child = childs.item(i);
//NOT TEXT NODES
if ((child.getNodeType() == Node.ELEMENT_NODE)) {
String childName = child.getNodeName();
//SPB FOUND
if (containsSPB(child)){
String childName = child.getNodeName();
//System.out.println(childName);
if (childName.equals(TEXT_SOFT_PAGE_BREAK)){
//removeSPB
@ -55,16 +56,14 @@ public class ParagraphSplitter extends BasicSplitter implements ISplitter {
}
break;
//Other elements
} else if (childName.equals(TEXT_BOOKMARK_START)){
} else if (child.getNodeName() != null && child.getNodeName().equals(TEXT_BOOKMARK_START)){
paraFirstPart.appendChild(child.cloneNode(true));
i++;
} else {
dataMoved = appendChild(paraFirstPart, child);
dataMoved = true;
paraFirstPart.appendChild(child);
}
//TEXT NODES
} else {
dataMoved = appendChild(paraFirstPart, child);
}
}
addHyphen(para,paraFirstPart);
@ -73,7 +72,8 @@ public class ParagraphSplitter extends BasicSplitter implements ISplitter {
removeIndent(para);
parent.insertBefore(paraFirstPart, para);
}
//System.out.println("PRINT PARA END");
//Debug.prettyPrintXml(parent);
return dataMoved;
}