Refactored Paragraph splitter
This commit is contained in:
parent
850f92615a
commit
b170acdece
2 changed files with 12 additions and 18 deletions
|
@ -20,13 +20,7 @@ public class BasicSplitter {
|
||||||
this.officeReader = officeReader;
|
this.officeReader = officeReader;
|
||||||
this.factory = factory;
|
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) {
|
protected static void addHyphen(Node para, Node paraBefore) {
|
||||||
//Debug.printNode(paraBefore);
|
//Debug.printNode(paraBefore);
|
||||||
//Debug.printNode(para);
|
//Debug.printNode(para);
|
||||||
|
|
|
@ -10,6 +10,7 @@ import org.w3c.dom.Element;
|
||||||
import org.w3c.dom.Node;
|
import org.w3c.dom.Node;
|
||||||
import org.w3c.dom.NodeList;
|
import org.w3c.dom.NodeList;
|
||||||
|
|
||||||
|
import pro.litvinovg.xml.Debug;
|
||||||
import w2phtml.office.OfficeReader;
|
import w2phtml.office.OfficeReader;
|
||||||
|
|
||||||
public class ParagraphSplitter extends BasicSplitter implements ISplitter {
|
public class ParagraphSplitter extends BasicSplitter implements ISplitter {
|
||||||
|
@ -22,7 +23,9 @@ public class ParagraphSplitter extends BasicSplitter implements ISplitter {
|
||||||
@Override
|
@Override
|
||||||
public boolean Split(Node para) {
|
public boolean Split(Node para) {
|
||||||
Node parent = para.getParentNode();
|
Node parent = para.getParentNode();
|
||||||
//System.out.println("handlePara");
|
//System.out.println("PRINT PARA START");
|
||||||
|
//Debug.prettyPrintXml(parent);
|
||||||
|
|
||||||
Node paraFirstPart = para.cloneNode(false);
|
Node paraFirstPart = para.cloneNode(false);
|
||||||
boolean dataMoved = false;
|
boolean dataMoved = false;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
@ -31,10 +34,8 @@ public class ParagraphSplitter extends BasicSplitter implements ISplitter {
|
||||||
//System.out.println("In WHILE HANDLE PARA");
|
//System.out.println("In WHILE HANDLE PARA");
|
||||||
Node child = childs.item(i);
|
Node child = childs.item(i);
|
||||||
//NOT TEXT NODES
|
//NOT TEXT NODES
|
||||||
if ((child.getNodeType() == Node.ELEMENT_NODE)) {
|
|
||||||
String childName = child.getNodeName();
|
|
||||||
//SPB FOUND
|
|
||||||
if (containsSPB(child)){
|
if (containsSPB(child)){
|
||||||
|
String childName = child.getNodeName();
|
||||||
//System.out.println(childName);
|
//System.out.println(childName);
|
||||||
if (childName.equals(TEXT_SOFT_PAGE_BREAK)){
|
if (childName.equals(TEXT_SOFT_PAGE_BREAK)){
|
||||||
//removeSPB
|
//removeSPB
|
||||||
|
@ -55,17 +56,15 @@ public class ParagraphSplitter extends BasicSplitter implements ISplitter {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
//Other elements
|
//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));
|
paraFirstPart.appendChild(child.cloneNode(true));
|
||||||
i++;
|
i++;
|
||||||
} else {
|
} else {
|
||||||
dataMoved = appendChild(paraFirstPart, child);
|
dataMoved = true;
|
||||||
|
paraFirstPart.appendChild(child);
|
||||||
}
|
}
|
||||||
//TEXT NODES
|
//TEXT NODES
|
||||||
} else {
|
|
||||||
dataMoved = appendChild(paraFirstPart, child);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
addHyphen(para,paraFirstPart);
|
addHyphen(para,paraFirstPart);
|
||||||
|
|
||||||
|
@ -73,7 +72,8 @@ public class ParagraphSplitter extends BasicSplitter implements ISplitter {
|
||||||
removeIndent(para);
|
removeIndent(para);
|
||||||
parent.insertBefore(paraFirstPart, para);
|
parent.insertBefore(paraFirstPart, para);
|
||||||
}
|
}
|
||||||
|
//System.out.println("PRINT PARA END");
|
||||||
|
//Debug.prettyPrintXml(parent);
|
||||||
return dataMoved;
|
return dataMoved;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue