last = start + next.inserted;
}
}
Difference.Insert diff;
if (nodesA[start0].nodeType == XMLStreamReader.END_ELEMENT) {
diff = new Difference.Append(new NodeProxy(docA, nodesA[start0].nodeId), docB);
changes.add(diff);
} else {
diff = (Difference.Insert) inserts.get(nodesA[start0].nodeId);
if (diff == null) {
diff = new Difference.Insert(new NodeProxy(docA, nodesA[start0].nodeId), docB);
inserts.put(nodesA[start0].nodeId, diff);
}
}
// now scan the chunk and collect the nodes
DiffNode[] nodes = new DiffNode[last - start];
int j = 0;
for (int i = start; i < last; i++, j++) {
if (LOG.isTraceEnabled())
LOG.trace(Integer.toString(i) + " " + nodesB[i]);
nodes[j] = nodesB[i];
}
diff.addNodes(nodes);
}
if (next.deleted > 0) {
// This is a simple test to correct an issue when two nodes of the same
// node-name are siblings and the first is deleted. What happens is the first
// element doesn't get it's start node deleted and the second does. So
// the second element basically ends up with the first one's start element.
// Which causes problems for the second element's attributes.
DiffNode beforeElement = nodesA[start0 - 1];
DiffNode lastElement = nodesA[lastDeleted - 1];
if(beforeElement.qname != null
&& lastElement.qname != null
&& beforeElement.qname.equals(lastElement.qname)
&& beforeElement.nodeType == XMLStreamReader.START_ELEMENT
&& lastElement.nodeType == XMLStreamReader.START_ELEMENT) {
start0--;
lastDeleted--;
}
if (LOG.isTraceEnabled())
LOG.trace("Deleted: " + start0 + " last: " + lastDeleted);
for (int i = start0; i < lastDeleted; i++) {
boolean elementDeleted = false;
if (nodesA[i].nodeType == XMLStreamReader.START_ELEMENT) {
for (int j = i; j < lastDeleted; j++) {
if (nodesA[j].nodeType == XMLStreamReader.END_ELEMENT &&
nodesA[j].nodeId.equals(nodesA[i].nodeId)) {
Difference.Delete diff = new Difference.Delete(new NodeProxy(docA, nodesA[i].nodeId));
changes.add(diff);
i = j;
elementDeleted = true;
break;
}
}
}
if (!elementDeleted) {
Difference.Delete diff = new Difference.Delete(nodesA[i].nodeType, new NodeProxy(docA, nodesA[i].nodeId));
changes.add(diff);
}
}
}
next = next.link;