public static void joinupRuns(P p) {
List<Object> existingContents = p.getContent();
List<Object> newContents = new ArrayList<Object>();
R currentR = null;
String currentRPrString = null;
// First join up runs with same run properties
for (Object o : existingContents) {
if (o instanceof R) {
if (currentR==null) { // first object, or after something not a run
currentR=(R)o;
if (currentR.getRPr()!=null) {
currentRPrString = XmlUtils.marshaltoString(currentR.getRPr(), true);
}
newContents.add(currentR);
} else {
RPr other = ((R)o).getRPr();
boolean makeNewRun = true; // unless proven otherwise
if (currentRPrString==null && other==null) makeNewRun=false;
if (currentRPrString!=null && other!=null) {
// Simple minded notion of equality
if ( XmlUtils.marshaltoString(other, true).equals(currentRPrString) ) makeNewRun=false;
}
if (makeNewRun) {
currentR=(R)o;
if (currentR.getRPr()==null) {
currentRPrString = null;
} else {
currentRPrString = XmlUtils.marshaltoString(currentR.getRPr(), true);
}
newContents.add(currentR);
} else {
currentR.getContent().addAll( ((R)o).getContent() );
}
}
} else {
// not a run (eg w:ins) .. just add it and move on